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