root / plugins / router / snmp__mikrotik @ 7cf2dda9
Historique | Voir | Annoter | Télécharger (4,63 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
snmp__mikrotik - monitor Mikrotik routers via SNMP |
| 6 |
|
| 7 |
=head1 APPLICABLE SYSTEMS |
| 8 |
|
| 9 |
Mikrotik Routers |
| 10 |
|
| 11 |
=head1 CONFIGURATION |
| 12 |
|
| 13 |
As a rule SNMP plugins need site specific configuration. The default |
| 14 |
configuration (shown here) will only work on insecure sites/devices. |
| 15 |
[snmp_*] |
| 16 |
env.version 2 |
| 17 |
env.community public |
| 18 |
|
| 19 |
=head1 MAGIC MARKERS |
| 20 |
|
| 21 |
#%# family=snmpauto |
| 22 |
#%# capabilities=snmpconf |
| 23 |
|
| 24 |
=head1 BUGS |
| 25 |
|
| 26 |
None known. |
| 27 |
|
| 28 |
=head1 AUTHOR |
| 29 |
|
| 30 |
Copyright (C) 2020 Alejandro Suarez (teconecta.es) |
| 31 |
Based on snmp__if_ plugin. |
| 32 |
|
| 33 |
=head1 LICENSE |
| 34 |
|
| 35 |
GPLv2. |
| 36 |
|
| 37 |
=cut |
| 38 |
|
| 39 |
use strict; |
| 40 |
use Net::SNMP; |
| 41 |
|
| 42 |
my $DEBUG = 0; |
| 43 |
|
| 44 |
my $host = $ENV{host} || undef;
|
| 45 |
my $port = $ENV{port} || 161;
|
| 46 |
my $community = $ENV{community} || "public";
|
| 47 |
|
| 48 |
my $sysFlashUsageOID = "1.3.6.1.2.1.25.2.3.1.6.131072"; |
| 49 |
my $sysFlashTotalOID = "1.3.6.1.2.1.25.2.3.1.5.131072"; |
| 50 |
my $sysRAMUsageOID = "1.3.6.1.2.1.25.2.3.1.6.65536"; |
| 51 |
my $sysRAMTotalOID = "1.3.6.1.2.1.25.2.3.1.5.65536"; |
| 52 |
my $sysTempOID = "1.3.6.1.4.1.14988.1.1.3.10.0"; |
| 53 |
|
| 54 |
my $response; |
| 55 |
|
| 56 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
|
| 57 |
print "require $sysFlashUsageOID ^\\d\n"; |
| 58 |
print "require $sysFlashTotalOID ^\\d\n"; |
| 59 |
print "require $sysRAMUsageOID ^\\d\n"; |
| 60 |
print "require $sysRAMTotalOID ^\\d\n"; |
| 61 |
exit 0; |
| 62 |
} |
| 63 |
|
| 64 |
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_mikrotik$/) {
|
| 65 |
$host = $1; |
| 66 |
if ($host =~ /^([^:]+):(\d+)$/) {
|
| 67 |
$host = $1; |
| 68 |
$port = $2; |
| 69 |
} |
| 70 |
} elsif (!defined($host)) {
|
| 71 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
| 72 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
| 73 |
} |
| 74 |
|
| 75 |
my ($session, $error) = Net::SNMP->session( |
| 76 |
-hostname => $host, |
| 77 |
-community => $community, |
| 78 |
-port => $port |
| 79 |
); |
| 80 |
|
| 81 |
|
| 82 |
die "Croaking: $error" unless (defined ($session)); |
| 83 |
|
| 84 |
|
| 85 |
if ($ARGV[0] and $ARGV[0] eq "config") {
|
| 86 |
print "host_name $host\n"; |
| 87 |
$response = $session->get_request($sysFlashTotalOID); |
| 88 |
if (defined $response) {
|
| 89 |
print "multigraph flash\n"; |
| 90 |
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysFlashTotalOID} * 1024) . "\n";
|
| 91 |
print "graph_title Flash disk usage\n"; |
| 92 |
print "graph_category system\n"; |
| 93 |
print "graph_info This graph shows the router's flash disk usage.\n"; |
| 94 |
print "graph_order Total Used\n"; |
| 95 |
print "graph_vlabel bytes\n"; |
| 96 |
print "sysFlashTotal.label Total Memory\n"; |
| 97 |
print "sysFlashTotal.draw AREA\n"; |
| 98 |
print "sysFlashUsage.label Used Memory\n"; |
| 99 |
print "sysFlashUsage.draw AREA\n"; |
| 100 |
} |
| 101 |
|
| 102 |
$response = $session->get_request($sysRAMTotalOID); |
| 103 |
if (defined $response) {
|
| 104 |
print "multigraph ram\n"; |
| 105 |
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotalOID} * 1024) . "\n";
|
| 106 |
print "graph_title RAM usage\n"; |
| 107 |
print "graph_category system\n"; |
| 108 |
print "graph_info This graph shows the router's memory usage.\n"; |
| 109 |
print "graph_order Total Used\n"; |
| 110 |
print "graph_vlabel bytes\n"; |
| 111 |
print "sysRAMTotal.label Total Memory\n"; |
| 112 |
print "sysRAMTotal.draw AREA\n"; |
| 113 |
print "sysRAMUsage.label Used Memory\n"; |
| 114 |
print "sysRAMUsage.draw AREA\n"; |
| 115 |
} |
| 116 |
|
| 117 |
$response = $session->get_request($sysTempOID); |
| 118 |
if (defined $response) {
|
| 119 |
print "multigraph temp\n"; |
| 120 |
print "graph_vlabel degC \n"; |
| 121 |
print "graph_title Temperature\n"; |
| 122 |
print "graph_category sensors\n"; |
| 123 |
print "graph_info This graph shows the router's temperature.\n"; |
| 124 |
print "sysTemp.label Temperature\n"; |
| 125 |
print "sysTemp.type GAUGE\n"; |
| 126 |
} |
| 127 |
exit 0 unless (($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1);
|
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
print "multigraph flash\n"; |
| 132 |
$response = $session->get_request(-varbindlist => [$sysFlashUsageOID, $sysFlashTotalOID]); |
| 133 |
if (defined $response) {
|
| 134 |
print "sysFlashUsage.value ", $response->{$sysFlashUsageOID}*1024, "\n";
|
| 135 |
print "sysFlashTotal.value ", $response->{$sysFlashTotalOID}*1024, "\n";
|
| 136 |
} else {
|
| 137 |
print "sysFlashUsage.value U\n"; |
| 138 |
print "sysFlashTotal.value U\n"; |
| 139 |
} |
| 140 |
|
| 141 |
print "multigraph ram\n"; |
| 142 |
$response = $session->get_request(-varbindlist => [$sysRAMUsageOID, $sysRAMTotalOID]); |
| 143 |
if (defined $response) {
|
| 144 |
print "sysRAMUsage.value ", $response->{$sysRAMUsageOID}*1024, "\n";
|
| 145 |
print "sysRAMTotal.value ", $response->{$sysRAMTotalOID}*1024, "\n";
|
| 146 |
} else {
|
| 147 |
print "sysRAMUsage.value U\n"; |
| 148 |
print "sysRAMTotal.value U\n"; |
| 149 |
} |
| 150 |
|
| 151 |
print "multigraph temp\n"; |
| 152 |
$response = $session->get_request(-varbindlist => [$sysTempOID]); |
| 153 |
if (defined $response) {
|
| 154 |
print "sysTemp.value ", $response->{$sysTempOID}/10, "\n";
|
| 155 |
} else {
|
| 156 |
print "sysTemp.value U\n"; |
| 157 |
} |
| 158 |
|
| 159 |
# vim:syntax=perl |
