Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / router / snmp__mikrotik @ 10534d0d

Historique | Voir | Annoter | Télécharger (3,94 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

    
53
my $response;
54

    
55
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") {
56
    print "require $sysFlashUsageOID\n";
57
    print "require $sysFlashTotalOID\n";
58
    print "require $sysRAMUsageOID\n";
59
    print "require $sysRAMTotalOID\n";
60
    exit 0;
61
}
62

    
63
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_mikrotik$/) {
64
    $host  = $1;
65
    if ($host =~ /^([^:]+):(\d+)$/) {
66
        $host = $1;
67
        $port = $2;
68
    }
69
} elsif (!defined($host)) {
70
    print "# Debug: $0 -- $1\n" if $DEBUG;
71
    die "# Error: couldn't understand what I'm supposed to monitor.";
72
}
73

    
74
my ($session, $error) = Net::SNMP->session(
75
                -hostname  => $host,
76
                -community => $community,
77
                -port      => $port
78
        );
79

    
80

    
81
die "Croaking: $error" unless (defined ($session));
82

    
83

    
84
if ($ARGV[0] and $ARGV[0] eq "config") {
85
    print "host_name $host\n";
86
    $response = $session->get_request($sysFlashTotalOID);
87
    if (defined $response) {
88
        print "multigraph flash\n";
89
        print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysFlashTotalOID} * 1024) . "\n";
90
        print "graph_title Flash disk usage\n";
91
        print "graph_category system\n";
92
        print "graph_info This graph shows the router's flash disk usage.\n";
93
        print "graph_order Total Used\n";
94
        print "graph_vlabel bytes\n";
95
        print "sysFlashTotal.label Total Memory\n";
96
        print "sysFlashTotal.draw AREA\n";
97
        print "sysFlashUsage.label Used Memory\n";
98
        print "sysFlashUsage.draw AREA\n";
99
    }
100

    
101
    $response = $session->get_request($sysRAMTotalOID);
102
    if (defined $response) {
103
        print "multigraph ram\n";
104
        print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotalOID} * 1024) . "\n";
105
        print "graph_title RAM usage\n";
106
        print "graph_category system\n";
107
        print "graph_info This graph shows the router's memory usage.\n";
108
        print "graph_order Total Used\n";
109
        print "graph_vlabel bytes\n";
110
        print "sysRAMTotal.label Total Memory\n";
111
        print "sysRAMTotal.draw AREA\n";
112
        print "sysRAMUsage.label Used Memory\n";
113
        print "sysRAMUsage.draw AREA\n";
114
    }
115
    exit 0 unless (($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1);
116
}
117

    
118

    
119
print "multigraph flash\n";
120
$response = $session->get_request(-varbindlist => [$sysFlashUsageOID, $sysFlashTotalOID]);
121
if (defined $response) {
122
        print "sysFlashUsage.value ", $response->{$sysFlashUsageOID}*1024, "\n";
123
        print "sysFlashTotal.value ", $response->{$sysFlashTotalOID}*1024, "\n";
124
} else {
125
        print "sysFlashUsage.value U\n";
126
        print "sysFlashTotal.value U\n";
127
}
128

    
129
print "multigraph ram\n";
130
$response = $session->get_request(-varbindlist => [$sysRAMUsageOID, $sysRAMTotalOID]);
131
if (defined $response) {
132
        print "sysRAMUsage.value ", $response->{$sysRAMUsageOID}*1024, "\n";
133
        print "sysRAMTotal.value ", $response->{$sysRAMTotalOID}*1024, "\n";
134
} else {
135
        print "sysRAMUsage.value U\n";
136
        print "sysRAMTotal.value U\n";
137
}
138

    
139
# vim:syntax=perl