Title: [opsview] [11327] Updated check_snmp_fortigate_cpu to use SNMPv3 library
Revision
11327
Author
hstevenson
Date
2013-02-04 10:51:49 +0000 (Mon, 04 Feb 2013)

Log Message

Updated check_snmp_fortigate_cpu to use SNMPv3 library

Modified Paths


Modified: trunk/opsview-core/nagios-plugins/check_snmp_fortigate_cpu
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_fortigate_cpu	2013-02-01 17:45:24 UTC (rev 11326)
+++ trunk/opsview-core/nagios-plugins/check_snmp_fortigate_cpu	2013-02-04 10:51:49 UTC (rev 11327)
@@ -20,82 +20,48 @@
 #    along with Opsview; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #
+use strict;
+use warnings;
 
-use lib qw ( /usr/local/nagios/perl/lib );
+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_snmp_fortigate_cpu";
-$script_version = "2.1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+    usage     => "Usage: %s",
+    shortname => "check_snmp_fortigate_cpu",
+    version   => "2.1.1",
+    blurb     => "Returns the current CPU load as %",
+    snmp      => { "snmp-version" => 1, },
+);
 
-$metric       = 1;
-$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
-$oid_cpu      = "1.3.6.1.4.1.12356.1.8.0";
+$np->add_arg(
+    spec => "warning|w=s",
+    help => qq{-w, --warning=INTEGER
+    Warning threshold (as %)},
+    default => 80,
+);
 
-$ipaddress    = "192.168.1.1"; # Default IP address
-$version      = "1";           # SNMP version
-$community    = "public";
-$timeout      = 2;             # Response timeout (seconds)
-$warning      = 80;
-$critical     = 90;
-$status       = 0;
-$returnstring = "";
-my $port = 161;
+$np->add_arg(
+    spec => "critical|c=s",
+    help => qq{-c, --critical=INTEGER
+    Critical threshold (as %)},
+    default => 90,
+);
 
-$configfilepath = "/usr/local/nagios/etc";
+$np->getopts;
 
-# Do we have enough information?
-if ( @ARGV < 1 ) {
-    print "Too few arguments\n";
-    usage();
-}
+my $warning  = $np->opts->warning;
+my $critical = $np->opts->critical;
 
-getopts( "hH:C:w:c:p:" );
-if ($opt_h) {
-    usage();
-    exit(0);
-}
-if ($opt_H) {
-    $hostname = $opt_H;
+my $s = $np->snmp;
 
-    # print "Hostname $opt_H\n";
-}
-else {
-    print "No hostname specified\n";
-    usage();
-}
-if ($opt_C) {
-    $community = $opt_C;
+my $oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+my $oid_cpu      = "1.3.6.1.4.1.12356.1.8.0";
+my $status       = 0;
+my $returnstring = "";
 
-    # print "Using community $opt_C\n";
-}
-else {
-
-    # print "Using community $community\n";
-}
-if ($opt_w) {
-    $warning = $opt_w;
-
-    # 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 => $community,
-    -hostname  => $hostname,
-    -version   => $version,
-    -timeout   => $timeout,
-    -port      => $port,
-);
-
 main();
 
 # Close the session
@@ -127,7 +93,7 @@
 ####################################################################
 
 sub main {
-
+    my $cpu5min;
     if ( !defined( $s->get_request($oid_cpu) ) ) {
         if ( !defined( $s->get_request($oid_sysDescr) ) ) {
             $returnstring = "SNMP agent not responding";
@@ -152,45 +118,16 @@
         $status = 2;
     }
 
-    $temp = "CPU: $cpu5min %|load=$cpu5min";
+    my $temp = "CPU: $cpu5min %|load=$cpu5min";
 
     append($temp);
 }
 
 ####################################################################
-# help and usage information                                       #
-####################################################################
-
-sub usage {
-    print << "USAGE";
---------------------------------------------------------------------	 
-$script v$script_version
-
-Returns the current CPU load as %
-
-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 %)
-	 
---------------------------------------------------------------------	 
-Copyright (C) 2003-2012 Opsview Limited. All rights reserved	 
-	 
-This program is free software; you can redistribute it or modify
-it under the terms of the GNU General Public License
---------------------------------------------------------------------
-
-USAGE
-    exit 1;
-}
-
-####################################################################
 # Appends string to existing $returnstring                         #
 ####################################################################
 
 sub append {
-    my $appendstring = @_[0];
+    my $appendstring = $_[0];
     $returnstring = "$returnstring$appendstring";
 }

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

Reply via email to