Title: [opsview] [11375] Updated check_snmp_netscaler_memutil to use SNMPv3 library
- Revision
- 11375
- Author
- hstevenson
- Date
- 2013-02-07 14:41:43 +0000 (Thu, 07 Feb 2013)
Log Message
Updated check_snmp_netscaler_memutil to use SNMPv3 library
Modified Paths
Modified: trunk/opsview-core/nagios-plugins/check_snmp_netscaler_memutil
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_netscaler_memutil 2013-02-07 13:53:34 UTC (rev 11374)
+++ trunk/opsview-core/nagios-plugins/check_snmp_netscaler_memutil 2013-02-07 14:41:43 UTC (rev 11375)
@@ -19,84 +19,49 @@
# 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_netscaler_memutil";
-$script_version = "2.1.0";
+my $np = Opsview::NagiosPlugin::SNMP->new(
+ usage => "Usage: %s",
+ shortname => "check_snmp_netscaler_memutil",
+ version => "2.1.1",
+ blurb => "Returns memory utilisation as %",
+ snmp => { "snmp-version" => 1, },
+);
-# Netscaler root OID= 1.3.6.1.4.1.5951
+$np->add_arg(
+ spec => "warning|w=s",
+ help => qq{-w, --warning=INTEGER
+ Warning threshold (as %)},
+ default => 80,
+);
-$oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
-$oid_mem = ".1.3.6.1.4.1.5951.4.1.1.41.2.0";
+$np->add_arg(
+ spec => "critical|c=s",
+ help => qq{-c, --critical=INTEGER
+ Critical threshold (as %)},
+ default => 90,
+);
-$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 = "";
+$np->getopts;
-$defaultcommunity = "public"; # Default community string
-$configfilepath = "/usr/local/nagios/etc";
-my $port = 161;
+my $warning = $np->opts->warning;
+my $critical = $np->opts->critical;
-# Do we have enough information?
-if ( @ARGV < 1 ) {
- print "Too few arguments\n";
- usage();
-}
+my $s = $np->snmp;
-getopts( "hH:C:w:c:p:" );
-if ($opt_h) {
- usage();
- exit(0);
-}
-if ($opt_H) {
- $hostname = $opt_H;
+my $oid_sysDescr = ".1.3.6.1.2.1.1.1.0";
+my $oid_mem = ".1.3.6.1.4.1.5951.4.1.1.41.2.0";
- # print "Hostname $opt_H\n";
-}
-else {
- print "No hostname specified\n";
- usage();
-}
-if ($opt_C) {
- $defaultcommunity = $opt_C;
+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 => return_snmpcommunity($hostname),
- -hostname => $hostname,
- -version => $version,
- -timeout => $timeout,
- -port => $port,
-);
-
main();
# Close the session
@@ -129,6 +94,9 @@
sub main {
+ my $mem;
+ my $temp;
+
if ( !defined( $s->get_request($oid_mem) ) ) {
if ( !defined( $s->get_request($oid_sysDescr) ) ) {
$returnstring = "SNMP agent not responding";
@@ -158,79 +126,11 @@
}
####################################################################
-# help and usage information #
-####################################################################
-
-sub usage {
- print << "USAGE";
---------------------------------------------------------------------
-$script v$script_version
-
-Returns memory utilisation 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";
}
-####################################################################
-# Returns the SNMP community string for a given hostname / IP #
-####################################################################
-
-sub return_snmpcommunity {
- my $requiredhostname = @_[0];
- my $returncommunity = $defaultcommunity;
- my $tempcommunity = "";
- my $temphostname = "";
-
- my $row = 0;
- my $nullval = 0;
-
- if ( -e "$configfilepath/livehosttable.db" ) {
- open INFILE, "<$configfilepath/livehosttable.db"
- or die "Can't open file $configfilepath/livehosttable.db $1";
- foreach $line (<INFILE>) {
- (
- $temphostname, $nullval, $nullval, $nullval, $nullval, $nullval,
- $nullval, $tempcommunity
- ) = split( /:/, $line );
- if ( $temphostname eq $requiredhostname ) {
- if ( $tempcommunity eq "" ) {
- $returncommunity = $defaultcommunity;
- }
- else {
- $returncommunity = $tempcommunity;
-
- # print "lookup for $temphostname successful: $tempcommunity\n";
- }
- last;
- }
- }
- }
- else {
- }
- close INFILE;
- return ($returncommunity);
-}
_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins