root / plugins / router / snmp__mikrotik @ 3032db48
Historique | Voir | Annoter | Télécharger (4,64 ko)
| 1 | 10534d0d | Lars Kruse | #!/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 | 3032db48 | Alejandro Suarez | my $sysTempOID = "1.3.6.1.4.1.14988.1.1.3.10.0"; |
| 53 | 10534d0d | Lars Kruse | |
| 54 | my $response; |
||
| 55 | |||
| 56 | if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
|
||
| 57 | print "require $sysFlashUsageOID\n"; |
||
| 58 | print "require $sysFlashTotalOID\n"; |
||
| 59 | print "require $sysRAMUsageOID\n"; |
||
| 60 | print "require $sysRAMTotalOID\n"; |
||
| 61 | 3032db48 | Alejandro Suarez | print "require $sysTempOID\n"; |
| 62 | 10534d0d | Lars Kruse | exit 0; |
| 63 | } |
||
| 64 | |||
| 65 | if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_mikrotik$/) {
|
||
| 66 | $host = $1; |
||
| 67 | if ($host =~ /^([^:]+):(\d+)$/) {
|
||
| 68 | $host = $1; |
||
| 69 | $port = $2; |
||
| 70 | } |
||
| 71 | } elsif (!defined($host)) {
|
||
| 72 | print "# Debug: $0 -- $1\n" if $DEBUG; |
||
| 73 | die "# Error: couldn't understand what I'm supposed to monitor."; |
||
| 74 | } |
||
| 75 | |||
| 76 | my ($session, $error) = Net::SNMP->session( |
||
| 77 | -hostname => $host, |
||
| 78 | -community => $community, |
||
| 79 | -port => $port |
||
| 80 | ); |
||
| 81 | |||
| 82 | |||
| 83 | die "Croaking: $error" unless (defined ($session)); |
||
| 84 | |||
| 85 | |||
| 86 | if ($ARGV[0] and $ARGV[0] eq "config") {
|
||
| 87 | print "host_name $host\n"; |
||
| 88 | $response = $session->get_request($sysFlashTotalOID); |
||
| 89 | if (defined $response) {
|
||
| 90 | print "multigraph flash\n"; |
||
| 91 | print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysFlashTotalOID} * 1024) . "\n";
|
||
| 92 | print "graph_title Flash disk usage\n"; |
||
| 93 | print "graph_category system\n"; |
||
| 94 | print "graph_info This graph shows the router's flash disk usage.\n"; |
||
| 95 | print "graph_order Total Used\n"; |
||
| 96 | print "graph_vlabel bytes\n"; |
||
| 97 | print "sysFlashTotal.label Total Memory\n"; |
||
| 98 | print "sysFlashTotal.draw AREA\n"; |
||
| 99 | print "sysFlashUsage.label Used Memory\n"; |
||
| 100 | print "sysFlashUsage.draw AREA\n"; |
||
| 101 | } |
||
| 102 | |||
| 103 | $response = $session->get_request($sysRAMTotalOID); |
||
| 104 | if (defined $response) {
|
||
| 105 | print "multigraph ram\n"; |
||
| 106 | print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotalOID} * 1024) . "\n";
|
||
| 107 | print "graph_title RAM usage\n"; |
||
| 108 | print "graph_category system\n"; |
||
| 109 | print "graph_info This graph shows the router's memory usage.\n"; |
||
| 110 | print "graph_order Total Used\n"; |
||
| 111 | print "graph_vlabel bytes\n"; |
||
| 112 | print "sysRAMTotal.label Total Memory\n"; |
||
| 113 | print "sysRAMTotal.draw AREA\n"; |
||
| 114 | print "sysRAMUsage.label Used Memory\n"; |
||
| 115 | print "sysRAMUsage.draw AREA\n"; |
||
| 116 | } |
||
| 117 | 3032db48 | Alejandro Suarez | |
| 118 | $response = $session->get_request($sysTempOID); |
||
| 119 | if (defined $response) {
|
||
| 120 | print "multigraph temp\n"; |
||
| 121 | print "graph_vlabel degC \n"; |
||
| 122 | print "graph_title Temperature\n"; |
||
| 123 | print "graph_category sensors\n"; |
||
| 124 | print "graph_info This graph shows the router's temperature.\n"; |
||
| 125 | print "sysTemp.label Temperature\n"; |
||
| 126 | print "sysTemp.type GAUGE\n"; |
||
| 127 | } |
||
| 128 | 10534d0d | Lars Kruse | exit 0 unless (($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1);
|
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | print "multigraph flash\n"; |
||
| 133 | $response = $session->get_request(-varbindlist => [$sysFlashUsageOID, $sysFlashTotalOID]); |
||
| 134 | if (defined $response) {
|
||
| 135 | print "sysFlashUsage.value ", $response->{$sysFlashUsageOID}*1024, "\n";
|
||
| 136 | print "sysFlashTotal.value ", $response->{$sysFlashTotalOID}*1024, "\n";
|
||
| 137 | } else {
|
||
| 138 | print "sysFlashUsage.value U\n"; |
||
| 139 | print "sysFlashTotal.value U\n"; |
||
| 140 | } |
||
| 141 | |||
| 142 | print "multigraph ram\n"; |
||
| 143 | $response = $session->get_request(-varbindlist => [$sysRAMUsageOID, $sysRAMTotalOID]); |
||
| 144 | if (defined $response) {
|
||
| 145 | print "sysRAMUsage.value ", $response->{$sysRAMUsageOID}*1024, "\n";
|
||
| 146 | print "sysRAMTotal.value ", $response->{$sysRAMTotalOID}*1024, "\n";
|
||
| 147 | } else {
|
||
| 148 | print "sysRAMUsage.value U\n"; |
||
| 149 | print "sysRAMTotal.value U\n"; |
||
| 150 | } |
||
| 151 | |||
| 152 | 3032db48 | Alejandro Suarez | print "multigraph temp\n"; |
| 153 | $response = $session->get_request(-varbindlist => [$sysTempOID]); |
||
| 154 | if (defined $response) {
|
||
| 155 | print "sysTemp.value ", $response->{$sysTempOID}/10, "\n";
|
||
| 156 | } else {
|
||
| 157 | print "sysTemp.value U\n"; |
||
| 158 | } |
||
| 159 | |||
| 160 | 10534d0d | Lars Kruse | # vim:syntax=perl |
