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(); }
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(); }