$ Version= 1.1 raquo ;;
$ o_host=undef; # Hostname $ o_community=undef; # Community $ o_port=161; # Port $ o_help=undef; # Wan't some help? $ O_verb=undef; # Verbose mode $ o_version=undef; # Print version $ o_netsnmp=1; # Check with netsnmp (default) $ o_cisco=undef; # Check cisco router mem $ o_hp=undef; # Check hp procurve mem $ o_warn=undef; # Warning level option $ o_warnR=undef; # Warning level for Real memory $ o_warnS=undef; # Warning levels for swap $ o_crit=undef; # Critical level option $ o_critR=undef; # Critical level for Real memory $ o_critS=undef; # Critical level for swap $ o_perf=undef; # Performance data option $ o_cache=undef; # Include cached memory as used memory $ o_timeout=undef; # Timeout (Default 5) $ o_version2=undef; # Use snmp v2c
# SNMPv3 specific $ o_login=undef; # Login for snmpv3 $ o_passwd=undef; # Pass for snmpv3 $ v3protocols=undef; # V3 protocol list. $ O_authproto= md5 raquo ;; # Auth protocol $ o_privproto= des raquo ;; # Priv protocol $ o_privpass=undef; # Priv password
# functions
p_version {print check_snmp_mem version: $ Version n raquo ;; }
print_usage { Usage: $ 0 [-v] -H lt; host gt;-C Lt; snmp_community gt; [- 2] | (-l login -x passwd [-X pass -L lt; authp gt;, lt; privp gt;]) [-p lt; port gt;] -w lt; warn level gt;-c lt; crit level gt; [-I | -N | -E] [-f] [-m] [-t Lt; timeout gt;] [-V] n raquo ;;
}
isnnum {# Return true if arg is not a number $ num=shift; ($ num=~ /^(d+.?d*)|(^.d+)$/) {return 0;} 1;
}
round ($$) {%. $ _ [1] f raquo ;, $ _ [0];
}
help { nSNMP Memory Monitor for Nagios version , $ Version, n raquo ;; (c) 2004-2006 to my cat Ratoune - Author: Patrick Proy n n raquo ;; _ usage (); lt; lt; EOT;
v, --verboseextra debugging information (including interface list on the system)
h, --helpthis help message
H, --hostname=HOSTor IP address of host to check
C, --community=COMMUNITY NAMEname for the host's SNMP agent (implies SNMP v1 or v2c with option)
, --v2csnmp v2c
l, --login=LOGIN;-x, --passwd=PASSWDand auth password for snmpv3 authenticationno priv password exists, implies AuthNoPriv
X, --privpass=PASSWDpassword for snmpv3 (AuthPriv protocol)
L, --protocols= lt; authproto gt;, lt; privproto gt;
lt; authproto gt;:Authentication protocol (md5 | sha: default md5)
lt; privproto gt;:Priv protocole (des | aes: default des)
P, --port=PORTport (Default 161)
w, --warn=INTEGER | INT, INTlevel for memory in percent (0 for no checks) (- N switch): comma separated level for Real Memory and Swap
I switch: warning level
c, --crit=INTEGER | INT, INTlevel for memory in percent (0 for no checks) (- N switch): comma separated level for Real Memory and Swap
I switch: critical level
N, --netsnmp (default) linux memory amp; swap provided by Net SNMP
m, --memcachecached memory in used memory (only with Net-SNMP)
I, --ciscocisco memory (sum of all memory pools)
E, --hpHP proccurve memory
f, --perfdatadata output
t, --timeout=INTEGERfor SNMP in seconds (Default: 5)
V, --versionversion number
}
# For verbose outputverb {my $ t=shift; print $ t, n if defined ($ o_verb); }
# Get the alarm signal (just in case snmp timout screws up)
$ SIG { ALRM }=sub {( ERROR: Alarm signal (Nagios time-out) n ); $ ERRORS { UNKNOWN };
};
check_options {:: Long :: Configure ( bundling ); (
v = gt; $ o_verb, verbose = gt; $ o_verb,
h = gt; $ o_help, help = gt; $ o_help,
H: s = gt; $ o_host, hostname: s = gt; $ o_host,
p: i = gt; $ o_port, port: i = gt; $ o_port,
C: s = gt; $ o_community, community: s = gt; $ o_community,
l: s = gt; $ o_login, login: s = gt; $ o_login,
x: s = gt; $ o_passwd, passwd: s = gt; $ o_passwd,
X: s...