예제 #1
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();
        }
예제 #2
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();
        }