forked from yoshikaw/munin-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snmp__qnap_df
executable file
·186 lines (145 loc) · 5 KB
/
snmp__qnap_df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/perl
# -*- perl -*-
=head1 NAME
snmp__qnap_df - Munin plugin to monitor QNAP disk usage through SNMP
=head1 APPLICABLE SYSTEMS
File systems usage stats should be reported by any QNAP storage
with SNMP Settings enabled.
=head1 CONFIGURATION
The plugin excludes per default the following file systems:
/sys/kernel/config
To change this set the environment variable "exclude" with a list of
space separated mount point. The environment variables "warning" and
"critical" sets the percentage from which Munin starts to warn about
the disk usage.
This configuration snipplet is an example with the defaults:
[snmp_*_qnap_df]
env.community public
env.warning 92
env.critical 98
env.exclude /sys/kernel/config
Put it in a file in /etc/munin/plugin-conf.d/ and restart the munin-node.
You may specify filesystem specific warning and critical levels:
env._share_MD0_DATA_warning 98
env._share_MD0_DATA_critical 99
Please see 'perldoc Munin::Plugin::SNMP' for further configuration.
=head1 MAGIC MARKERS
#%# family=snmpauto
#%# capabilities=snmpconf
=head1 VERSION
git-master + a few munin modifications
This plugin was downloaded from L<http://github.com/yoshikaw/munin-plugins/>
=head1 AUTHOR
Copyright (C) 2012 Kazuhiro Yoshikawa <[email protected]>
QNAP is a trademark of QNAP Systems, Inc.
=head1 BUGS
Does not support SNMPv3.
=head1 LICENSE
GPLv2 or (at your option) any later version.
=cut
use strict;
use warnings;
use Munin::Plugin;
use Munin::Plugin::SNMP;
use vars qw($DEBUG);
my $DEBUG = $ENV{'MUNIN_DEBUG'} || 0;
my %env = (
warning => $ENV{'warning'} || 92,
critical => $ENV{'critical'} || 98,
exclude => $ENV{'exclude'} || '/sys/kernel/config',
);
my $hrStorageEntry = '1.3.6.1.2.1.25.2.3.1';
my $hrStorageFixedDisk = '1.3.6.1.2.1.25.2.1.4';
if (defined $ARGV[0] and $ARGV[0] eq 'snmpconf') {
print "require $hrStorageEntry\n";
exit 0;
}
# SNMP needed for both config and fetch.
my $session = Munin::Plugin::SNMP->session();
my $result = $session->get_hash(
-baseoid => $hrStorageEntry,
-cols => {
1 => 'index',
2 => 'type',
3 => 'descr',
4 => 'units',
5 => 'size',
6 => 'used',
},
);
if ($DEBUG) {
for my $index (sort { $result->{$a}->{index} <=> $result->{$b}->{index} } keys %$result) {
for my $key (qw/type descr size used/) {
printf "%d: %-5s %s\n", $index, $key, $result->{$index}->{$key};
}
printf "%d: is hrStorageFixedDisk? %d\n", $index
, $result->{$index}->{type} eq $hrStorageFixedDisk;
printf "%d: match exclude? %d\n", $index
, index($env{'exclude'}, $result->{$index}->{descr}) > -1;
}
}
sub print_result
{
my $callback = shift;
for my $index (sort { $result->{$a}->{index} <=> $result->{$b}->{index} } keys %$result) {
my $type = $result->{$index}->{type};
my $desc = $result->{$index}->{descr};
next if $type ne $hrStorageFixedDisk;
next if index($env{'exclude'}, $desc) > -1;
my $name = clean_fieldname($desc);
$callback->($name, $result->{$index});
}
}
if (defined $ARGV[0] and $ARGV[0] eq "config") {
my ($host, undef, undef, $tail) = Munin::Plugin::SNMP->config_session();
# The headers
print "host_name $host\n" unless $host eq 'localhost';
print "graph_title Filesystem usage (in %)\n";
print "graph_args --lower-limit 0 --upper-limit 100\n";
print "graph_vlabel %\n";
print "graph_scale no\n";
print "graph_category disk\n";
print_result(sub{
my $name = shift;
my $result = shift;
printf "%s.label %s\n", $name, $result->{descr};
for my $v (qw/warning critical/) {
printf "%s.%s %s\n", $name, $v, $ENV{"${name}_${v}"} || $env{$v};
}
my $size_bytes = correct_overflow($result->{size}) * $result->{units};
my $divide_times = 0;
while (($size_bytes / 1024) > 1024) {
$divide_times++;
$size_bytes /= 1024;
}
my %d = (
size => $size_bytes,
warn => $size_bytes * ($ENV{"${name}_warning"} || $env{warning}) / 100,
crit => $size_bytes * ($ENV{"${name}_critical"} || $env{critical}) / 100,
);
my @units = qw/B KB MB GB TB/;
for my $d (keys %d) {
$d{$d} = int $d{$d};
1 while $d{$d} =~ s/^(\d+)(\d\d\d)/$1,$2/;
$d{$d} .= " $units[$divide_times]";
}
printf "%s.info Size: %s / Warn: %s / Crit: %s\n"
, $name, $d{size}, $d{warn}, $d{crit};
});
exit 0;
}
print_result(sub {
my $name = shift;
my $result = shift;
my $used = correct_overflow($result->{used});
my $size = correct_overflow($result->{size});
printf "%s.value %d\n", $name, ($size == 0 ? 0 : ($used / $size) * 100);
});
sub correct_overflow{
if($_[0]<0){
return $_[0]+2**32;
}else{
return $_[0];
}
}
exit 0;