#!/usr/bin/perl ############################################################################### use diagnostics; use Net::SNMP; use strict; use warnings; ############################################################################### my $DiskTotalOID = ".1.3.6.1.2.1.25.2.3.1.5.1"; my $DiskUsedOID = ".1.3.6.1.2.1.25.2.3.1.6.1"; my $SNMPCommunity = "public"; my $SNMPPort = "161"; ############################################################################### ## Determine Hostname my $Host = undef; $0 =~ /mikrotikdiskspace_(.+)*$/; unless ($Host = $1) { exit 2; } ############################################################################### ## Initiate SNMP Session my ($Session, $Error) = Net::SNMP->session (-hostname => $Host, -community => $SNMPCommunity, -port => $SNMPPort, -timeout => 60, -retries => 5, -version => 1); if (!defined($Session)) { die "Croaking: $Error"; } ############################################################################### ## Configuration if ($ARGV[0] && $ARGV[0] eq "config") { my $Result = $Session->get_request(-varbindlist => [$DiskTotalOID]); print "host_name " . $Host . "\n"; print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($Result->{$DiskTotalOID} * 1024) . "\n"; print "graph_title Disk Space usage\n"; print "graph_category system\n"; print "graph_info This graph shows the router's Disk Space usage.\n"; print "graph_order Total Used\n"; print "graph_vlabel bytes\n"; print "Total.label Total Disk Space\n"; print "Total.draw AREA\n"; print "Used.label Used Disk Space\n"; print "Used.draw AREA\n"; $Session->close; exit; } ############################################################################### ## Execution if (my $Result = $Session->get_request(-varbindlist => [$DiskTotalOID, $DiskUsedOID])) { print "Total.value " . ($Result->{$DiskTotalOID} * 1024) . "\n"; print "Used.value " . ($Result->{$DiskUsedOID} * 1024) . "\n"; $Session->close; exit; }