static void Main(string[] args)
        {
            CheckDiskFreeWmiPluginOptions Options = new CheckDiskFreeWmiPluginOptions();
            Options.label = "Disk Free";            
            Options.units = "GB";
            Options.multiplier = .000000001M;
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            if (Options.disk != null)
            {
                plugin.Query(String.Format("Select DeviceID, FreeSpace From Win32_LogicalDisk where DeviceID='{0}' and FreeSpace is not null", Options.disk));
            }
            else
            {
                plugin.Query("Select DeviceID, FreeSpace From Win32_LogicalDisk where DriveType=3 and FreeSpace is not null");
            }
            if (plugin.ResultCollection.Count > 0)
            {
                foreach (ManagementObject mgtObject in plugin.ResultCollection)
                {
                    if (mgtObject["FreeSpace"] != null)
                    {
                        plugin.AppendValue(mgtObject["DeviceID"].ToString(), Convert.ToDecimal(mgtObject["FreeSpace"].ToString()));
                    }
                }
            }
            else
            {
                plugin.FatalError(Plugin<WmiPluginOptions>.StatusCode.Critical, "", "WMI query returned 0 results");
            }
            plugin.Finish();
        }
示例#2
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label      = "Uptime";
            Options.units      = "s";
            Options.multiplier = 1.0M / TimeSpan.TicksPerSecond;
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            plugin.Query("Select LastBootUpTime From Win32_OperatingSystem where LastBootUpTime is not null");
            string lastBootUpTime = null;

            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                lastBootUpTime = mgtObject["LastBootUpTime"].ToString();
                lastBootUpTime = lastBootUpTime.Substring(4, 2)
                                 + "/" + lastBootUpTime.Substring(6, 2)
                                 + "/" + lastBootUpTime.Substring(0, 4)
                                 + " " + lastBootUpTime.Substring(8, 2)
                                 + ":" + lastBootUpTime.Substring(10, 2)
                                 + ":" + lastBootUpTime.Substring(12, 2);
            }
            if (lastBootUpTime == null)
            {
                plugin.FatalError(NagiosPluginsNT.Plugin <WmiPluginOptions> .StatusCode.Critical, "", "Win32_OperatingSystem.LastBootUpTime was null (maybe unsupported by OS)");
            }
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // force US format for dates
            plugin.AppendValue(Convert.ToDecimal((DateTime.Now.Ticks - Convert.ToDateTime(lastBootUpTime).Ticks)));
            plugin.Finish();
        }
示例#3
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label = "Memory Free";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            decimal total = 0;

            plugin.Query("Select TotalPhysicalMemory From Win32_LogicalMemoryConfiguration");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                total = Convert.ToDecimal(mgtObject["TotalPhysicalMemory"].ToString());
            }

            plugin.Query("Select FreePhysicalMemory From Win32_OperatingSystem");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(Math.Round(Convert.ToDecimal(mgtObject["FreePhysicalMemory"]) / total * 100));
            }

            plugin.Finish();
        }
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Disk Time";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            plugin.Query("Select PercentDiskTime, PercentDiskTime_Base From Win32_PerfRawData_PerfDisk_PhysicalDisk where Name='_Total'");
            decimal time1 = 0;
            decimal base1 = 0;
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {                
                time1 = Convert.ToDecimal(mgtObject["PercentDiskTime"].ToString());     
                base1 = Convert.ToDecimal(mgtObject["PercentDiskTime_Base"].ToString());
            }

            Thread.Sleep(1000);

            plugin.Query("Select PercentDiskTime, PercentDiskTime_Base From Win32_PerfRawData_PerfDisk_PhysicalDisk where Name='_Total'");
            decimal time2 = 0;
            decimal base2 = 0;
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {                
                time2 = Convert.ToDecimal(mgtObject["PercentDiskTime"].ToString());   
                base2 = Convert.ToDecimal(mgtObject["PercentDiskTime_Base"].ToString());
            }

            plugin.AppendValue(Math.Round(((time2 - time1) / (base2 - base1)) * 100));        
            plugin.Finish();
        }
示例#5
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Memory Free";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            decimal total = 0;
            plugin.Query("Select TotalPhysicalMemory From Win32_LogicalMemoryConfiguration");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                total = Convert.ToDecimal(mgtObject["TotalPhysicalMemory"].ToString());
            }

            plugin.Query("Select FreePhysicalMemory From Win32_OperatingSystem");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(Math.Round(Convert.ToDecimal(mgtObject["FreePhysicalMemory"]) / total * 100));
            }
           
            plugin.Finish();
        }
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Uptime";
            Options.units = "s";
            Options.multiplier = 1.0M / TimeSpan.TicksPerSecond;
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            plugin.Query("Select LastBootUpTime From Win32_OperatingSystem where LastBootUpTime is not null");
            string lastBootUpTime = null;
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                lastBootUpTime = mgtObject["LastBootUpTime"].ToString();
                lastBootUpTime = lastBootUpTime.Substring(4, 2)
                 + "/" + lastBootUpTime.Substring(6, 2)
                 + "/" + lastBootUpTime.Substring(0, 4)
                 + " " + lastBootUpTime.Substring(8, 2)
                 + ":" + lastBootUpTime.Substring(10, 2)
                 + ":" + lastBootUpTime.Substring(12, 2);
            }
            if (lastBootUpTime == null)
            {
                plugin.FatalError(NagiosPluginsNT.Plugin<WmiPluginOptions>.StatusCode.Critical, "", "Win32_OperatingSystem.LastBootUpTime was null (maybe unsupported by OS)");
            }
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // force US format for dates
            plugin.AppendValue(Convert.ToDecimal((DateTime.Now.Ticks - Convert.ToDateTime(lastBootUpTime).Ticks)));            
            plugin.Finish();
        }
示例#7
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Operating System";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            plugin.Query("Select Caption, CSDVersion From Win32_OperatingSystem");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Caption"].ToString() + " " + mgtObject["CSDVersion"].ToString());
            }            
            plugin.Finish();
        }
示例#8
0
 static void Main(string[] args)
 {
     WmiPluginOptions Options = new WmiPluginOptions();            
     Options.label = "CPU";
     Options.units = "%";
     Options.ProcessArgs(args);      
     
     WmiPlugin plugin = new WmiPlugin(Options);            
     plugin.Connect();
     plugin.Query("Select DeviceID, LoadPercentage From Win32_Processor");                                 
     foreach (ManagementObject mgtObject in plugin.ResultCollection)
     {
         plugin.AppendValue(mgtObject["DeviceID"].ToString(), Convert.ToDecimal(mgtObject["LoadPercentage"].ToString()));
     }            
     plugin.Finish();
 }
        static void Main(string[] args)
        {            
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Stopped Services";
            Options.warning = ".+";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            plugin.Query("select Name from Win32_Service where State='Stopped' and StartMode='Auto' and Name<>'SysmonLog' and Name<>'spupdsvc'");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Name"].ToString());
            }
            plugin.Finish();
        }
示例#10
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label = "Operating System";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            plugin.Query("Select Caption, CSDVersion From Win32_OperatingSystem");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Caption"].ToString() + " " + mgtObject["CSDVersion"].ToString());
            }
            plugin.Finish();
        }
示例#11
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label = "CPU";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();
            plugin.Query("Select DeviceID, LoadPercentage From Win32_Processor");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["DeviceID"].ToString(), Convert.ToDecimal(mgtObject["LoadPercentage"].ToString()));
            }
            plugin.Finish();
        }
示例#12
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();
            Options.label = "Page File Utilization";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);
            plugin.Connect();

            plugin.Query("Select Name, CurrentUsage, AllocatedBaseSize From Win32_PageFileUsage");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Name"].ToString(), Math.Round(Convert.ToDecimal(mgtObject["CurrentUsage"]) / Convert.ToDecimal(mgtObject["AllocatedBaseSize"]) * 100));
            }

            plugin.Finish();
        }
示例#13
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label   = "Stopped Services";
            Options.warning = ".+";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            plugin.Query("select Name from Win32_Service where State='Stopped' and StartMode='Auto' and Name<>'SysmonLog' and Name<>'spupdsvc'");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Name"].ToString());
            }
            plugin.Finish();
        }
示例#14
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label = "Page File Utilization";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            plugin.Query("Select Name, CurrentUsage, AllocatedBaseSize From Win32_PageFileUsage");
            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                plugin.AppendValue(mgtObject["Name"].ToString(), Math.Round(Convert.ToDecimal(mgtObject["CurrentUsage"]) / Convert.ToDecimal(mgtObject["AllocatedBaseSize"]) * 100));
            }

            plugin.Finish();
        }
示例#15
0
        static void Main(string[] args)
        {
            CheckDiskFreeWmiPluginOptions Options = new CheckDiskFreeWmiPluginOptions();

            Options.label      = "Disk Use";
            Options.units      = "GB";
            Options.multiplier = .000000001M;
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            if (Options.disk != null)
            {
                plugin.Query(String.Format("Select DeviceID, FreeSpace, Size From Win32_LogicalDisk where DeviceID='{0}' and FreeSpace is not null", Options.disk));
            }
            else
            {
                plugin.Query("Select DeviceID, FreeSpace, Size From Win32_LogicalDisk where DriveType=3 and FreeSpace is not null");
            }
            if (plugin.ResultCollection.Count > 0)
            {
                Decimal use;
                foreach (ManagementObject mgtObject in plugin.ResultCollection)
                {
                    if (mgtObject["FreeSpace"] != null)
                    {
                        use = Convert.ToDecimal(mgtObject["Size"]) - Convert.ToDecimal(mgtObject["FreeSpace"]);
                        plugin.AppendValue(mgtObject["DeviceID"].ToString(), use);
                    }
                }
            }
            else
            {
                plugin.FatalError(Plugin <WmiPluginOptions> .StatusCode.Critical, "", "WMI query returned 0 results");
            }
            plugin.Finish();
        }
示例#16
0
        static void Main(string[] args)
        {
            WmiPluginOptions Options = new WmiPluginOptions();

            Options.label = "Disk Time";
            Options.units = "%";
            Options.ProcessArgs(args);

            WmiPlugin plugin = new WmiPlugin(Options);

            plugin.Connect();

            plugin.Query("Select PercentDiskTime, PercentDiskTime_Base From Win32_PerfRawData_PerfDisk_PhysicalDisk where Name='_Total'");
            decimal time1 = 0;
            decimal base1 = 0;

            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                time1 = Convert.ToDecimal(mgtObject["PercentDiskTime"].ToString());
                base1 = Convert.ToDecimal(mgtObject["PercentDiskTime_Base"].ToString());
            }

            Thread.Sleep(1000);

            plugin.Query("Select PercentDiskTime, PercentDiskTime_Base From Win32_PerfRawData_PerfDisk_PhysicalDisk where Name='_Total'");
            decimal time2 = 0;
            decimal base2 = 0;

            foreach (ManagementObject mgtObject in plugin.ResultCollection)
            {
                time2 = Convert.ToDecimal(mgtObject["PercentDiskTime"].ToString());
                base2 = Convert.ToDecimal(mgtObject["PercentDiskTime_Base"].ToString());
            }

            plugin.AppendValue(Math.Round(((time2 - time1) / (base2 - base1)) * 100));
            plugin.Finish();
        }