use lib "/usr/local/nagios/libexec"; use strict; use Net::Telnet; use Nagios::Plugin; use strict; use Getopt::Long; my $host ="nagios"; my $password ="nagios"; my @slot; my @slot1; my @slot2; my @slot3; my @slot4; my @slot5; my @slot6; my @slot7; my @slot8; my $Sresult; my $output; my $result; my @result; my @type; my @output; my @pref; #nagios my $np = Nagios::Plugin->new( usage => "Usage: %s [-H ] [-h ] [-p ]", shortname => "check_slot", license => 'This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. It may be used, redistributed and/or modified under the terms of the GNU General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).', blurb =>'(contact Michi1s@web.de)', ); $np->add_arg( spec => 'host|H=s', help => '-H, --host=STRING\n', required => '0', ); $np->add_arg( spec => 'help|h=s', help => '-h, --help=STRING\n', required => '0', ); $np->add_arg( spec => 'password|p=s', help => '-p, --password=STRING\n', required => '0', ); $np->getopts; $host = ( defined( $np->opts->host ) ? $np->opts->host : $host ); $password = ( defined( $np->opts->password ) ? $np->opts->password : $password ); my $t = new Net::Telnet (Timeout => 10, Prompt => '/Provaris GmbH/'); my $fh = $t->dump_log('skylla.log'); $t->open("10.0.10.61"); $t->login($host, $password); @slot1 = $t->cmd("show slot 1"); @slot2 = $t->cmd("show slot 2"); @slot3 = $t->cmd("show slot 3"); @slot4 = $t->cmd("show slot 4"); @slot5 = $t->cmd("show slot 5"); @slot6 = $t->cmd("show slot 6"); @slot7 = $t->cmd("show slot 7"); @slot8 = $t->cmd("show slot 8"); @slot[1] = "@slot1"; @slot[2] = "@slot2"; @slot[3] = "@slot3"; @slot[4] = "@slot4"; @slot[5] = "@slot5"; @slot[6] = "@slot6"; @slot[7] = "@slot7"; @slot[8] = "@slot8"; @result = slotState(@slot); @type = slotType(@slot); $Sresult = "@result"; if (defined @output){ $output = "@output"; } for(my $i=1;$i<= 8; $i++){ @pref[$i] = "@type[$i]$output slot $i"; } $output = "@pref"; #übergabe an nagios if ($Sresult =~ m/0/){ $result = 0; } if ($Sresult =~ m/3/){ $result = 1; } if ($Sresult =~ m/2/){ $result = 2; } $np->nagios_exit( CRITICAL, $output ) if ( $result eq "2" ); $np->nagios_exit( WARNING, $output ) if ( $result eq "1" ); $np->nagios_exit( OK, $output ) if ( $result eq "0" ); $np->nagios_die('state of connection is UNKNOWN'); sub slotState(@) { my @slot = @_; for(my $i=1;$i<= 8; $i++){ if ( @slot[$i] =~ /State:/ ) { @slot[$i] = split( "\n", $' ); } if (@slot[$i] =~ /Operational/){ @result[$i] = 0; } elsif (@slot[$i] =~ /Empty/){ @result[$i] = 3; }else{ @slot[$i] = @output[$i]; @result[$i] = 2; } } return @result; } sub slotType(@) { my @slot = @_; for(my $i=1;$i<= 8; $i++){ if ( @slot[$i] =~ /HW Module Type:/ ) { @slot[$i] = split( "\n", $' ); } } return @slot; }