« lib/App/MadEye/Plugin/Agent/TheSchwartz/Job.pm
↑ Summary
lib/App/MadEye/Plugin/Worker/Gearman.pm »
| 1 | package App::MadEye::Plugin::Agent::SNMP::Disk; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use App::MadEye::Plugin::Agent::Base; | ||
| 5 | use App::MadEye::Util; | ||
| 6 | |||
| 7 | my $oid_map = { | ||
| 8 | hrStorageType => '.1.3.6.1.2.1.25.2.3.1.2', | ||
| 9 | hrStorageSize => '.1.3.6.1.2.1.25.2.3.1.5', | ||
| 10 | hrStorageUsed => '.1.3.6.1.2.1.25.2.3.1.6', | ||
| 11 | hrStorageDescr => '.1.3.6.1.2.1.25.2.3.1.3', | ||
| 12 | hrStorageFixedDisk => '.1.3.6.1.2.1.25.2.1.4', | ||
| 13 | }; | ||
| 14 | |||
| 15 | sub is_dead { | ||
| 16 | my ($self, $host) = @_; | ||
| 17 | |||
| 18 | my $threshold = $self->config->{config}->{threshold} or die "missing threshold"; | ||
| 19 | |||
| 20 | my $response = snmp_session( | ||
| 21 | $self, | ||
| 22 | $host => sub { | ||
| 23 | my $session = shift; | ||
| 24 | |||
| 25 | return +{ | ||
| 26 | map { | ||
| 27 | $_ => ( | ||
| 28 | $session->get_table( | ||
| 29 | -baseoid => $oid_map->{$_}, | ||
| 30 | ) or die "cannot get a $_ : " . $session->error | ||
| 31 | ) | ||
| 32 | } | ||
| 33 | qw/hrStorageDescr hrStorageUsed hrStorageType hrStorageSize/ | ||
| 34 | }; | ||
| 35 | }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | my $result = ''; | ||
| 39 | each_storage($response => sub { | ||
| 40 | my $get = shift; | ||
| 41 | |||
| 42 | return if $get->('hrStorageSize') == 0; # /proc/bus/usb0 とかはサイズがゼロなのだ | ||
| 43 | |||
| 44 | my $used_per = $get->('hrStorageUsed') / $get->('hrStorageSize') * 100; | ||
| 45 | if ($used_per > $threshold) { | ||
| 46 | $result .= join ' ', $get->('hrStorageDescr'), $get->('hrStorageUsed'), $get->('hrStorageSize'), sprintf('%3.2f%%', $used_per), "\n"; | ||
| 47 | } | ||
| 48 | }); | ||
| 49 | return $result; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub each_storage { | ||
| 53 | my ($response, $code) = @_; | ||
| 54 | |||
| 55 | while (my ($node, $storage_type) = each %{ $response->{hrStorageType} }) { | ||
| 56 | if ($storage_type eq $oid_map->{hrStorageFixedDisk}) { | ||
| 57 | (my $storage_number = $node) =~ s/.+\.//; | ||
| 58 | |||
| 59 | $code->( | ||
| 60 | sub { | ||
| 61 | my $key = shift; | ||
| 62 | $response->{$key}->{$oid_map->{$key} . '.' . $storage_number} | ||
| 63 | } | ||
| 64 | ); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; | ||
| 70 | __END__ |