예제 #1
0
        static void Main(string[] args)
        {
            SnmpIfPluginOptions Options = new SnmpIfPluginOptions();
            Options.label = "Interface";            
            Options.units = "%";
            Options.ProcessArgs(args);            
            SnmpPlugin plugin = new SnmpPlugin(Options);

            String checkInterface = Options.checkInterface.ToString();

            // *** get interface description ***            
            Options.oid = Options.oidIfName + "." + checkInterface;
            Options.label += " '" + plugin.Get() + "'";
            
            // *** get interface speeds (0 = in, 1 = out) ***
            Int32[] ifSpeed = new Int32[2];
            Int32 tryParse;
            for (Int32 i = 0; i < 2; ++i)
            {
                String optionIfSpeed = plugin.GetNthOption(Options.ifSpeed, i);
                if (optionIfSpeed == "auto" || !Int32.TryParse(optionIfSpeed, out tryParse))
                {
                    Options.oid = Options.oidIfSpeed + "." + checkInterface;
                    ifSpeed[i] = Convert.ToInt32(plugin.Get());
                    if (ifSpeed[i] < 1)
                    {
                        plugin.FatalError(Plugin<NagiosPluginsNT.SnmpPluginOptions>.StatusCode.Critical, "", "Unable to determine interface speed");
                    }
                }
                else
                {
                    ifSpeed[i] = Convert.ToInt32(optionIfSpeed);
                }
            }
            
            // *** poll counters ***            
            Options.oid = Options.oidIfInOctets + "." + checkInterface;
            Int64 startTimeIn = DateTime.Now.Ticks;
            Decimal ifInOctets1 = Convert.ToDecimal(plugin.Get());            
            Options.oid = Options.oidIfOutOctets + "." + checkInterface;
            Int64 startTimeOut = DateTime.Now.Ticks;
            Decimal ifOutOctets1 = Convert.ToDecimal(plugin.Get());

            Thread.Sleep(Options.interval * 1000);

            // *** poll counters ***                        
            Options.oid = Options.oidIfInOctets + "." + checkInterface;
            Decimal ifInOctets2 = Convert.ToDecimal(plugin.Get());
            Decimal realIntervalIn = (((Decimal)DateTime.Now.Ticks - (Decimal)startTimeIn) / (Decimal)TimeSpan.TicksPerSecond);
            Options.oid = Options.oidIfOutOctets + "." + checkInterface;
            Decimal ifOutOctets2 = Convert.ToDecimal(plugin.Get());
            Decimal realIntervalOut = (((Decimal)DateTime.Now.Ticks - (Decimal)startTimeOut) / (Decimal)TimeSpan.TicksPerSecond);                        

            // *** get traffic statistics ***
            plugin.AppendValue("Traffic In", Math.Round((Math.Abs(ifInOctets2 - ifInOctets1) * 8 * 100) / (realIntervalIn * ifSpeed[0])));
            plugin.AppendValue("Traffic Out", Math.Round((Math.Abs(ifOutOctets2 - ifOutOctets1) * 8 * 100) / (realIntervalOut * ifSpeed[1])));

            plugin.Finish();
        }
예제 #2
0
        static void Main(string[] args)
        {
            SnmpPluginOptions Options = new SnmpPluginOptions();
            Options.oid = "1.3.6.1.2.1.1.5.0";
            Options.ProcessArgs(args);

            SnmpPlugin plugin = new SnmpPlugin(Options);            
            String value = plugin.Get();            
            Decimal tryParse;
            if (decimal.TryParse(value, out tryParse))
            {
                plugin.AppendValue(tryParse);
            }
            else
            {
                plugin.AppendValue(value);
            }

            plugin.Finish();
        }
예제 #3
0
        static void Main(string[] args)
        {
            SnmpPluginOptions Options = new SnmpPluginOptions();

            Options.oid = "1.3.6.1.2.1.1.5.0";
            Options.ProcessArgs(args);

            SnmpPlugin plugin = new SnmpPlugin(Options);
            String     value  = plugin.Get();
            Decimal    tryParse;

            if (decimal.TryParse(value, out tryParse))
            {
                plugin.AppendValue(tryParse);
            }
            else
            {
                plugin.AppendValue(value);
            }

            plugin.Finish();
        }
예제 #4
0
        static void Main(string[] args)
        {
            SnmpIfPluginOptions Options = new SnmpIfPluginOptions();

            Options.label = "Interface";
            Options.units = "%";
            Options.ProcessArgs(args);
            SnmpPlugin plugin = new SnmpPlugin(Options);

            String checkInterface = Options.checkInterface.ToString();

            // *** get interface description ***
            Options.oid    = Options.oidIfName + "." + checkInterface;
            Options.label += " '" + plugin.Get() + "'";

            // *** get interface speeds (0 = in, 1 = out) ***
            Int32[] ifSpeed = new Int32[2];
            Int32   tryParse;

            for (Int32 i = 0; i < 2; ++i)
            {
                String optionIfSpeed = plugin.GetNthOption(Options.ifSpeed, i);
                if (optionIfSpeed == "auto" || !Int32.TryParse(optionIfSpeed, out tryParse))
                {
                    Options.oid = Options.oidIfSpeed + "." + checkInterface;
                    ifSpeed[i]  = Convert.ToInt32(plugin.Get());
                    if (ifSpeed[i] < 1)
                    {
                        plugin.FatalError(Plugin <NagiosPluginsNT.SnmpPluginOptions> .StatusCode.Critical, "", "Unable to determine interface speed");
                    }
                }
                else
                {
                    ifSpeed[i] = Convert.ToInt32(optionIfSpeed);
                }
            }

            // *** poll counters ***
            Options.oid = Options.oidIfInOctets + "." + checkInterface;
            Int64   startTimeIn = DateTime.Now.Ticks;
            Decimal ifInOctets1 = Convert.ToDecimal(plugin.Get());

            Options.oid = Options.oidIfOutOctets + "." + checkInterface;
            Int64   startTimeOut = DateTime.Now.Ticks;
            Decimal ifOutOctets1 = Convert.ToDecimal(plugin.Get());

            Thread.Sleep(Options.interval * 1000);

            // *** poll counters ***
            Options.oid = Options.oidIfInOctets + "." + checkInterface;
            Decimal ifInOctets2    = Convert.ToDecimal(plugin.Get());
            Decimal realIntervalIn = (((Decimal)DateTime.Now.Ticks - (Decimal)startTimeIn) / (Decimal)TimeSpan.TicksPerSecond);

            Options.oid = Options.oidIfOutOctets + "." + checkInterface;
            Decimal ifOutOctets2    = Convert.ToDecimal(plugin.Get());
            Decimal realIntervalOut = (((Decimal)DateTime.Now.Ticks - (Decimal)startTimeOut) / (Decimal)TimeSpan.TicksPerSecond);

            // *** get traffic statistics ***
            plugin.AppendValue("Traffic In", Math.Round((Math.Abs(ifInOctets2 - ifInOctets1) * 8 * 100) / (realIntervalIn * ifSpeed[0])));
            plugin.AppendValue("Traffic Out", Math.Round((Math.Abs(ifOutOctets2 - ifOutOctets1) * 8 * 100) / (realIntervalOut * ifSpeed[1])));

            plugin.Finish();
        }