/[nagios-plugins-perl]/trunk/plugins/check_adic.pl
ViewVC logotype

Contents of /trunk/plugins/check_adic.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (show annotations) (download)
Tue Jan 7 10:21:09 2014 UTC (6 years, 10 months ago) by racvision
File MIME type: text/plain
File size: 3874 byte(s)
mise à jour fr_FR
1 #!/usr/bin/perl -w
2 #
3 # check_adic.pl - nagios plugin for Scalar tape libraries
4 #
5 # Martin Niedworok (martin.niedworok@gmx.de)
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #
21
22 use strict;
23 use Getopt::Long;
24 use File::Basename;
25 use Net::SNMP;
26
27 my $PROGNAME = basename($0);
28 my $opt_H = "";
29 my $opt_C = "public";
30 my $opt_help;
31 my @status;
32
33 # Getting options
34 Getopt::Long::Configure('bundling');
35 GetOptions(
36 "host|H=s" => \$opt_H,
37 "community|C=s" => \$opt_C,
38 "help" => \$opt_help,
39 "h" => \$opt_help
40 );
41
42 if ( !$opt_H || $opt_help ) {
43 print_usage();
44 }
45
46 # Getting SNMP output
47 my($session, $error) = Net::SNMP->session(
48 -hostname => $opt_H,
49 -community => $opt_C
50 );
51
52 my %oids = (
53 Power => '.1.3.6.1.4.1.3764.1.10.10.12.1.0',
54 Cooling => '.1.3.6.1.4.1.3764.1.10.10.12.2.0',
55 Control => '.1.3.6.1.4.1.3764.1.10.10.12.3.0',
56 Connectivity => '.1.3.6.1.4.1.3764.1.10.10.12.4.0',
57 Robotics => '.1.3.6.1.4.1.3764.1.10.10.12.5.0',
58 Media => '.1.3.6.1.4.1.3764.1.10.10.12.6.0',
59 Drive => '.1.3.6.1.4.1.3764.1.10.10.12.7.0',
60 );
61
62 my %subsystems = (
63 1 => 'Power',
64 2 => 'Cooling',
65 3 => 'Control',
66 4 => 'Connectivity',
67 5 => 'Robotics',
68 6 => 'Media',
69 7 => 'Drive',
70 );
71
72 my %prio = (
73 2 => '1',
74 7 => '2',
75 3 => '3',
76 4 => '4',
77 6 => '5',
78 5 => '6',
79 1 => '7',
80 );
81
82 my $result = $session->get_request(
83 -varbindlist => [$oids{Power},
84 $oids{Cooling},
85 $oids{Control},
86 $oids{Connectivity},
87 $oids{Robotics},
88 $oids{Media},
89 $oids{Drive}]
90 );
91
92 $session->close;
93
94 my %resulthash = %$result;
95
96 my $key;
97 my @keys = sort keys %resulthash;
98
99 for (my $j = 0; $j < 8; $j++) {$status[$j] = ""};
100
101 # Putting the checked systems in a status array
102 my $i = 1;
103 foreach $key (@keys) {
104 $_ = $resulthash{$key};
105 $status[$prio{$_}] .= $i;
106 $i++;
107 }
108
109 # Iterating over the status array and searching the highest prio
110 if($status[1] ne "") {
111 myexit('CRITICAL', "failed subsystems: " . build_output($status[1]));
112 } elsif($status[2] ne "") {
113 myexit('CRITICAL', "invalid subsystems: " . build_output($status[2]));
114 } elsif($status[3] ne "") {
115 myexit('WARNING', "degraded subsystems: " . build_output($status[3]));
116 } elsif($status[4] ne "") {
117 myexit('WARNING', "warning subsystems: " . build_output($status[4]));
118 } elsif($status[5] ne "") {
119 myexit('UNKNOWN', "unknown subsystems: " . build_output($status[5]));
120 } elsif($status[6] ne "") {
121 myexit('OK', "informational subsystems: " . build_output($status[6]));
122 } elsif($status[7] ne "") {
123 myexit('OK', "all subsystems ok.");
124 }
125
126 # Getting the subsystems names into an output string
127 sub build_output {
128 my @input = split(//, $_[0]);
129 my $output;
130 while (@input) {
131 $output .= $subsystems{shift(@input)};
132 $output .= " ";
133 }
134 return $output;
135 }
136
137 sub print_usage {
138 print <<EOU;
139 Usage: $PROGNAME [ -H host ] [ -C SNMP-community ]
140
141 Options:
142
143 -H --host
144 Hostname
145 -C --community
146 SNMP-community
147 EOU
148
149 myexit( 'UNKNOWN', $PROGNAME );
150 }
151
152 sub myexit {
153 my $time;
154 my $date;
155
156 my ( $state, $text ) = @_;
157
158 my %STATUS_CODE =
159 ( 'UNKNOWN' => '-1', 'OK' => '0', 'WARNING' => '1', 'CRITICAL' => '2' );
160
161 my $out = $state;
162 $out .= " - ";
163 $out .= $text;
164 $out .= chr(10);
165
166 print $out;
167
168 exit $STATUS_CODE{$state};
169 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8