Projet

Général

Profil

Révision 10534d0d

ID10534d0dd00113ddd4f031e460730eaddca2a6b4
Parent 389ac956
Enfant 898224ba

Ajouté par Lars Kruse il y a plus de 5 ans

Merge SNMP plugins for Mikrotik routers into a single multigraph plugin

Voir les différences:

plugins/router/snmp__mikrotik
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
plugins/router/snmp__mikrotik_flash
1
#!/usr/bin/perl -w
2

  
3
=head1 NAME
4

  
5
snmp__mikrotik_flash - Munin plugin to monitor Mikrotik routers Falsh disk utilization.
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 $response;
49

  
50
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
51
{
52
    print "require 1.3.6.1.2.1.25.2.3.1.5.65536 \n";
53
    exit 0;
54
}
55

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

  
71
my $sysFlashUsage     = "1.3.6.1.2.1.25.2.3.1.6.131072";
72
my $sysFlashTotal     = "1.3.6.1.2.1.25.2.3.1.5.131072";
73

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

  
80

  
81
if (!defined ($session))
82
{
83
        die "Croaking: $error";
84
}
85

  
86

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

  
107

  
108
if (defined ($response = $session->get_request(-varbindlist => [$sysFlashUsage, $sysFlashTotal])))
109
{
110
        print "sysFlashUsage.value ", $response->{$sysFlashUsage}*1024, "\n";
111
        print "sysFlashTotal.value ", $response->{$sysFlashTotal}*1024, "\n";
112
}
113
else
114
{
115
        print "sysFlashUsage.value U\n";
116
        print "sysFlashTotal.value U\n";
117
}
118

  
119
# vim:syntax=perl
120

  
plugins/router/snmp__mikrotik_ram
1
#!/usr/bin/perl -w
2

  
3
=head1 NAME
4

  
5
snmp__mikrotik_flash - Munin plugin to monitor Mikrotik routers RAM utilization.
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 $response;
49

  
50
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
51
{
52
    print "require 1.3.6.1.2.1.25.2.3.1.5.65536 \n";
53
    exit 0;
54
}
55

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

  
71
my $sysRAMUsage     = "1.3.6.1.2.1.25.2.3.1.6.65536";
72
my $sysRAMTotal     = "1.3.6.1.2.1.25.2.3.1.5.65536";
73

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

  
80

  
81
if (!defined ($session))
82
{
83
        die "Croaking: $error";
84
}
85

  
86

  
87
if ($ARGV[0] and $ARGV[0] eq "config")
88
{
89
    print "host_name $host\n";
90
    if (!defined ($response = $session->get_request($sysRAMTotal)))
91
    {
92
        die "Croaking: " . $session->error();
93
    }
94
    print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotal} * 1024) . "\n";
95
    print "graph_title RAM usage\n";
96
    print "graph_category system\n";
97
    print "graph_info This graph shows the router's memory usage.\n";
98
    print "graph_order Total Used\n";
99
    print "graph_vlabel bytes\n";
100
    print "sysRAMTotal.label Total Memory\n";
101
    print "sysRAMTotal.draw AREA\n";
102
    print "sysRAMUsage.label Used Memory\n";
103
    print "sysRAMUsage.draw AREA\n";
104
    exit 0;
105
}
106

  
107

  
108
if (defined ($response = $session->get_request(-varbindlist => [$sysRAMUsage, $sysRAMTotal])))
109
{
110
        print "sysRAMUsage.value ", $response->{$sysRAMUsage}*1024, "\n";
111
        print "sysRAMTotal.value ", $response->{$sysRAMTotal}*1024, "\n";
112
}
113
else
114
{
115
        print "sysRAMUsage.value U\n";
116
        print "sysRAMTotal.value U\n";
117
}
118

  
119
# vim:syntax=perl

Formats disponibles : Unified diff