#!/usr/bin/perl -w # # check diskio op servers # # syntax: # ./check_diskio --host= [--community=] # # jorgbosman@optiver.com - 17 juli 2004 use strict; use Getopt::Long; use Net::SNMP; use Data::Dumper; # # settings # my $hostname = ""; my $community = "public"; my $tmpdir = '/tmp/nagios'; GetOptions("hostname:s" => \$hostname, "community:s" => \$community); my $errorcode = 0; my ($session, $error) = Net::SNMP->session(-hostname => $hostname, -community => $community, -timeout => 60, -retries => 1); if (! defined $session) { printf("ERROR: %s.\n", $error); exit 3; # unknown } # # get data # my $oid = ".1.3.6.1.4.1.2021.13.15.1.1.2"; my $disk = $session->get_table(-baseoid => $oid); if (! defined $disk) { # geen enkele disk terug gekregen? printf("%s.\n", $session->error); exit 3; # ok } my %disk = %{$disk}; $oid = ".1.3.6.1.4.1.2021.13.15.1.1.3"; my $read = $session->get_table(-baseoid => $oid); if (! defined $read) { # geen enkele disk terug gekregen? printf("ERROR: %s.\n", $session->error); exit 3; } my %read = %{$read}; $oid = ".1.3.6.1.4.1.2021.13.15.1.1.4"; my $written = $session->get_table(-baseoid => $oid); if (! defined $written) { # geen enkele disk terug gekregen? printf("ERROR: %s.\n", $session->error); exit 3; } my %written = %{$written}; # # rewrite data and put it in one hash # my %diskio; while (my ($key, $value) = each(%disk)) { $key =~ s/.*\.(\d+)$/$1/; if ($value !~ /^md../) { # geen mirror-metadevices $diskio{$key}{'name'} = $value; } } while (my ($key, $value) = each(%read)) { $key =~ s/.*\.(\d+)$/$1/; if (defined $diskio{$key}) { # geen mirror-metadevices $diskio{$key}{'read'} = $value; } } while (my ($key, $value) = each(%written)) { $key =~ s/.*\.(\d+)$/$1/; if (defined $diskio{$key}) { # geen mirror-metadevices $diskio{$key}{'written'} = $value; } } # # get data from previous reading # my %previous; if ( -f "$tmpdir/$hostname.diskio.counters" ) { open(FILE, "$tmpdir/$hostname.diskio.counters"); while (my $line = ) { my @tmp = split(/ /, $line); $previous{$tmp[0]}{'name'} = $tmp[1]; $previous{$tmp[0]}{'read'} = $tmp[2]; $previous{$tmp[0]}{'written'} = $tmp[3]; } close(FILE); } # # parse, save and print data # if ( ! -d "$tmpdir" ) { mkdir("$tmpdir", 0755); } open (FILE, ">$tmpdir/$hostname.diskio.counters"); my $rrdtext = ''; my $text = ''; foreach my $key (keys %diskio) { print FILE $key . " " . $diskio{$key}{'name'} . " " . $diskio{$key}{'read'} . " " . $diskio{$key}{'written'} . "\n"; $rrdtext .= $diskio{$key}{'name'} . "," . $diskio{$key}{'read'} . ":" . $diskio{$key}{'written'} . " "; if ((defined $previous{$key}{'read'}) && (defined $previous{$key}{'written'})) { my $diffread = $diskio{$key}{'read'} - $previous{$key}{'read'}; my $diffwritten = $diskio{$key}{'written'} - $previous{$key}{'written'}; if (($diffread > 0) || ($diffwritten > 0)) { if ($diffread > 1000000) { $diffread = sprintf("%.1fM", $diffread / 1000000); } elsif ($diffread > 1000) { $diffread = sprintf("%.1fK", $diffread / 1000); } if ($diffwritten > 1000000) { $diffwritten = sprintf("%.1fM", $diffwritten / 1000000); } elsif ($diffwritten > 1000) { $diffwritten = sprintf("%.1fK", $diffwritten / 1000); } $text .= $diskio{$key}{'name'} . ": $diffread/$diffwritten, "; } } } close(FILE); if ($rrdtext ne '') { chop($rrdtext); } if ($text ne '') { chop($text); chop($text); # remove last komma and space } else { $text = "OK"; } print "$text|$rrdtext\n"; # # exit # (0=ok 1=warning 2=critical 3=unknown 4=dependent) # exit $errorcode;