#!/usr/bin/perl use strict; use Net::SNMP; use Getopt::Long; my %opt; GetOptions( "host=s" => \$opt{'host'}, "community=s" => \$opt{'community'}, "warn=i" => \$opt{'warn'}, "crit=i" => \$opt{'crit'}); unless ($opt{'host'} && $opt{'community'} && $opt{'warn'} && $opt{'crit'}) { print "Usage: $0 --host --community --warn --crit \n\n"; exit 1; } my $oid_mem_used_5min = "1.3.6.1.4.1.9.9.48.1.1.1.5.1"; my $oid_mem_free_5min = "1.3.6.1.4.1.9.9.48.1.1.1.6.1"; my($session, $error) = Net::SNMP->session(-hostname => $opt{'host'}, -community => $opt{'community'} ); unless(defined($session)) { print "Critical - Could not establish SNMP session\n"; exit 3; } my $result = $session->get_request(-varbindlist => [$oid_mem_used_5min,$oid_mem_free_5min] ); my $mem_free = $result->{$oid_mem_free_5min}; my $mem_used = $result->{$oid_mem_used_5min}; my $mem_total = $mem_free + $mem_used; my $mem_used_percent = int(100 * ($mem_used / $mem_total)); my $mem_free_percent = int(100 * ($mem_free / $mem_total)); $session->close; print "Used: ".$mem_used."/".$mem_used_percent."% Free: ".$mem_free."/".$mem_free_percent."% Total: ".$mem_total."\n"; exit 2 if $mem_used_percent > $opt{'crit'}; exit 1 if $mem_used_percent > $opt{'warn'}; exit 0;