| 1 | It is possible to alert on disk space thresholds with the existing |
|---|
| 2 | check_snmp plugin, but it is rather fiddly to set up (because, for example, |
|---|
| 3 | you have to manually map the filesystem mountpoint to the OID index). So |
|---|
| 4 | the approach given here is to install a new plugin, which handles this for |
|---|
| 5 | you. |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | 1. Create a plugin script |
|---|
| 9 | |
|---|
| 10 | Create a file /usr/local/bin/check_hrstorage.pl with the following contents |
|---|
| 11 | (the #! line must be the very first line in the file) |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #!/usr/bin/perl -w |
|---|
| 16 | |
|---|
| 17 | unless ($ARGV[2]) { |
|---|
| 18 | print STDERR "Usage: $0 <host> <community> <mountpoint> [<warn%> [<crit%>]]\n"; |
|---|
| 19 | exit 3; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | my $res = `snmpwalk -On -Oq -r 2 -t 1 -c '$ARGV[1]' -v2c '$ARGV[0]' .1.3.6.1.2.1.25.2.3`; |
|---|
| 23 | unless ($res =~ /^\.1.3.6/) { |
|---|
| 24 | print "Unable to contact via SNMP\n"; |
|---|
| 25 | exit 3; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | my $table = {}; |
|---|
| 29 | my $index; |
|---|
| 30 | foreach my $line (split(/\n/,$res)) { |
|---|
| 31 | my ($k,$v) = split(/ /,$line,2); |
|---|
| 32 | $table->{$k} = $v; |
|---|
| 33 | if ($v eq $ARGV[2] && $k =~ /^.1.3.6.1.2.1.25.2.3.1.3\.(\d+)$/) { |
|---|
| 34 | $index = $1; |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | unless ($index) { |
|---|
| 39 | print "Unable to find mountpoint $ARGV[2]\n"; |
|---|
| 40 | exit 3; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | my $size = $table->{".1.3.6.1.2.1.25.2.3.1.5.$index"}; |
|---|
| 44 | $size += 4294967296 if $size < 0; |
|---|
| 45 | my $used = $table->{".1.3.6.1.2.1.25.2.3.1.6.$index"}; |
|---|
| 46 | $used += 4294967296 if $used < 0; |
|---|
| 47 | my $percent = $used * 100.0 / $size; |
|---|
| 48 | |
|---|
| 49 | my $block = $table->{".1.3.6.1.2.1.25.2.3.1.4.$index"}; |
|---|
| 50 | if ($block =~ /^(\d+)/) { |
|---|
| 51 | $block = $1; |
|---|
| 52 | $size = $size * 1.0 * $block / 1024 / 1024; |
|---|
| 53 | $used = $used * 1.0 * $block / 1024 / 1024; |
|---|
| 54 | } |
|---|
| 55 | printf "%.2f%% used (%d out of %d MB)\n", $percent, $used, $size; |
|---|
| 56 | if ($ARGV[4] && $percent >= $ARGV[4]) { |
|---|
| 57 | exit 2; # Critical |
|---|
| 58 | } |
|---|
| 59 | if ($ARGV[3] && $percent >= $ARGV[3]) { |
|---|
| 60 | exit 1; # Warning |
|---|
| 61 | } |
|---|
| 62 | exit 0; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | Make it executable using the following command: |
|---|
| 66 | |
|---|
| 67 | # chmod +x /usr/local/bin/check_hrstorage.pl |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | 2. Configure the plugin |
|---|
| 71 | |
|---|
| 72 | Create a new configuration file: |
|---|
| 73 | |
|---|
| 74 | # editor /etc/nagios-plugins/config/hrstorage.cfg |
|---|
| 75 | |
|---|
| 76 | define command { |
|---|
| 77 | command_name check_hrstorage |
|---|
| 78 | command_line /usr/local/bin/check_hrstorage.pl '$HOSTADDRESS$' '$ARG1$' '$ARG2$' '$ARG3$' '$ARG4$' |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | 3. Add a service check |
|---|
| 83 | |
|---|
| 84 | A service check can now be added to an individual host, or to a hostgroup. |
|---|
| 85 | For example: |
|---|
| 86 | |
|---|
| 87 | define service { |
|---|
| 88 | host_name noc |
|---|
| 89 | service_description Disk space / |
|---|
| 90 | check_command check_hrstorage!NetManage!/!80!90 |
|---|
| 91 | use generic-service |
|---|
| 92 | notification_interval 0 |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | The parameters to this check_hrstorage are: |
|---|
| 96 | |
|---|
| 97 | * SNMP community |
|---|
| 98 | * Filesystem mount point |
|---|
| 99 | * Warning threshold (%) |
|---|
| 100 | * Critical threshold (%) |
|---|