Thread Net::Telnet - Slots von Extreme Black Diamond Switch abfragen
(23 answers)
Opened by affe at 2010-08-24 15:02 Code (perl): (dl
)
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 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 <host>] [-h <help>] [-p <password>]", 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; } bin eig ferig man kann klar noch verbessern .....konnte leider nicht prüfen was passiert wenn was anderes auser operational oder empty kommt da ich keine defekte slot karte habe... Last edited: 2010-08-26 11:21:29 +0200 (CEST) |