Title: [opsview] [11322] Updated check_snmp_noprocesses to use SNMPv3 library
Revision
11322
Author
hstevenson
Date
2013-02-01 16:17:48 +0000 (Fri, 01 Feb 2013)

Log Message

Updated check_snmp_noprocesses to use SNMPv3 library

Modified Paths


Modified: trunk/opsview-core/nagios-plugins/check_snmp_noprocesses
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_noprocesses	2013-02-01 16:07:07 UTC (rev 11321)
+++ trunk/opsview-core/nagios-plugins/check_snmp_noprocesses	2013-02-01 16:17:48 UTC (rev 11322)
@@ -21,81 +21,49 @@
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #
 
-use lib qw ( /usr/local/nagios/perl/lib );
+use warnings;
+use strict;
+
+use FindBin qw($Bin);
+use lib "/opt/opsview/perl/lib/perl5", "$Bin/../lib";
 use Net::SNMP;
-use Getopt::Std;
+use Opsview::NagiosPlugin::SNMP;
 
-$script         = "check_noprocesses";
-$script_version = "2.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+    usage     => "Usage: %s",
+    shortname => "check_snmp_noprocesses",
+    version   => "2.1",
+    blurb     => "Returns the total number of running processes",
+    snmp      => { "snmp-version" => 1, },
+);
 
-$metric            = 1;
-$oid_sysDescr      = ".1.3.6.1.2.1.1.1.0";
-$hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
-$ipaddress         = "192.168.10.30";
-$version           = "1";
-$community         = "public";
-$timeout           = 2;
-$warning           = 100;
-$critical          = 150;
-$status            = 0;
-$returnstring      = "";
-my $port = 161;
+$np->add_arg(
+    spec => "warning|w=s",
+    help => qq{-w, --warning=INTEGER
+    Warning threshold (as %)},
+    default => 100,
+);
 
-$defaultcommunity = "public";               # Default community string
-$configfilepath   = "/usr/local/nagios/etc";
+$np->add_arg(
+    spec => "critical|c=s",
+    help => qq{-c, --critical=INTEGER
+    Critical threshold (as %)},
+    default => 150,
+);
 
-# Do we have enough information?
-if ( @ARGV < 1 ) {
-    print "Too few arguments\n";
-    usage();
-}
+$np->getopts;
 
-getopts( "hH:C:w:c:p:" );
-if ($opt_h) {
-    usage();
-    exit(0);
-}
-if ($opt_H) {
-    $hostname = $opt_H;
+my $warning  = $np->opts->warning;
+my $critical = $np->opts->critical;
 
-    # print "Hostname $opt_H\n";
-}
-else {
-    print "No hostname specified\n";
-    usage();
-}
-if ($opt_C) {
-    $defaultcommunity = $opt_C;
+my $s = $np->snmp;
 
-    # print "Using community $opt_C\n";
-}
-else {
+my $status       = 0;
+my $returnstring = "";
 
-    # print "Using community $community\n";
-}
-if ($opt_w) {
-    $warning = $opt_w;
+my $oid_sysDescr      = ".1.3.6.1.2.1.1.1.0";
+my $hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
 
-    # print "Warning threshold: $opt_w%\n";
-}
-if ($opt_c) {
-    $critical = $opt_c;
-
-    # print "Critical threshold: $opt_c%\n";
-}
-if ($opt_p) {
-    $port = $opt_p;
-}
-
-# Create the SNMP session
-my ( $s, $e ) = Net::SNMP->session(
-    -community => $defaultcommunity,
-    -hostname  => $hostname,
-    -version   => $version,
-    -timeout   => $timeout,
-    -port      => $port,
-);
-
 main();
 
 # Close the session
@@ -123,6 +91,8 @@
 exit $status;
 
 sub main {
+    my $processes;
+    my $temp;
 
     if ( !defined( $s->get_request($hrSystemProcesses) ) ) {
         if ( !defined( $s->get_request($oid_sysDescr) ) ) {
@@ -151,30 +121,8 @@
     }
 }
 
-sub usage {
-    print << "USAGE";
-
-$script v$script_version
-
-Returns the total number of running processes
-
-Usage: $script -H <hostname> -c <community> [...]
-Options: -H 		Hostname or IP address
-         -p 		Port (default: 161)
-         -C 		Community (default is public)
-         -w 		Warning threshold (as %)
-         -c 		Critical threshold (as %)
-
-USAGE
-    exit 1;
-}
-
 sub append {
-    my $appendstring = @_[0];
+    my $appendstring = $_[0];
     $returnstring = "$returnstring$appendstring";
 }
 
-sub errorhandler {
-    my $returnstring = @_[0];
-    print "$returnstring\n";
-}

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to