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

Contents of /trunk/plugins/check_quantum.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 159 - (show annotations) (download)
Tue Apr 7 12:12:32 2015 UTC (5 years, 7 months ago) by racvision
File MIME type: text/plain
File size: 4127 byte(s)
add check_netapp2.pl and check_quantum.pl
1 #!/usr/bin/perl -w
2 #
3 # check_quantum.pl - nagios plugin for Quantum tape libraries
4 #
5 # (c) 2015 St├ęphane Urbanovski (s.urbanovski@ac-nancy-metz.fr)
6 # inspired by check_adic.pl by
7 # (c) Martin Niedworok (martin.niedworok@gmx.de)
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #
23
24 use warnings;
25 use strict;
26
27 use Locale::gettext;
28 use Nagios::Plugin qw(:DEFAULT %STATUS_TEXT);
29
30 use Net::SNMP;
31
32 use Data::Dumper;
33
34
35 my $VERSION = '1.1';
36 my $TIMEOUT = 10;
37 my $DEBUG = 0;
38
39 my $np = Nagios::Plugin->new(
40 version => $VERSION,
41 blurb => _gt('Check Quantum tape libraries'),
42 usage => "Usage: %s -H <host> -C <community> [ -d|--dedbug ] [ -v|--verbose ] [-t <timeout>]",
43 timeout => $TIMEOUT+1
44 );
45 $np->add_arg (
46 spec => 'debug|d',
47 help => _gt('Debug level'),
48 default => 0,
49 );
50
51 $np->add_arg (
52 spec => 'hostname|H=s',
53 help => _gt('Hostname'),
54 required => 1,
55 );
56
57 $np->add_arg (
58 spec => 'community|C=s',
59 help => 'SNMP community',
60 default => 'public',
61 );
62
63 $np->getopts;
64
65 $DEBUG = $np->opts->get('debug');
66 my $host = $np->opts->get('hostname');
67 my $community = $np->opts->get('community');
68
69
70 my %statusOid = (
71 '.1.3.6.1.4.1.3764.1.10.10.12.4.0' => 'Connectivity',
72 '.1.3.6.1.4.1.3764.1.10.10.12.3.0' => 'Control',
73 '.1.3.6.1.4.1.3764.1.10.10.12.7.0' => 'Drive',
74 '.1.3.6.1.4.1.3764.1.10.10.12.6.0' => 'Media',
75 '.1.3.6.1.4.1.3764.1.10.10.12.1.0' => 'Power',
76 '.1.3.6.1.4.1.3764.1.10.10.12.2.0' => 'Cooling',
77 '.1.3.6.1.4.1.3764.1.10.10.12.5.0' => 'Robotics'
78 );
79 my %infoOid = (
80 '.1.3.6.1.4.1.3764.1.10.10.1.4.0' => 'Vendor',
81 '.1.3.6.1.4.1.3764.1.10.10.1.7.0' => 'Model',
82 '.1.3.6.1.4.1.3764.1.10.10.1.5.0' => 'Serial',
83 );
84
85 my %prioName = (
86 1 => 'ok',
87 2 => 'failed',
88 3 => 'degraded',
89 4 => 'warning',
90 5 => 'informational',
91 6 => 'unknown',
92 7 => 'invalid',
93 );
94
95 # map snmp state to plugin status
96 my %prioStatus = (
97 1 => OK,
98 2 => CRITICAL,
99 3 => CRITICAL,
100 4 => WARNING,
101 5 => OK,
102 6 => WARNING,
103 7 => WARNING,
104 );
105
106 # Getting SNMP output
107 my ($session, $error) = Net::SNMP->session(
108 -hostname => $host,
109 -community => $community
110 );
111
112
113 my @oidList = (keys(%infoOid),keys(%statusOid));
114
115 my $result = $session->get_request(
116 -varbindlist => \@oidList
117 );
118 $session->close;
119
120 if ( ! defined($result) ) {
121 $np->nagios_exit( UNKNOWN, "Unable to get SNMP values" );
122 }
123
124 my %infos = (
125 'Vendor' => '',
126 'Model' => '',
127 'Serial' => '',
128 );
129
130 foreach my $o ( keys %{$result} ) {
131 if ( defined($statusOid{$o}) ) {
132 my $state = $prioStatus{$result->{$o}};
133 printf STDERR ("oid: %-35s susbsystem: %-15s result: %d (%s) state: %d (%s) \n",$o,$statusOid{$o},$result->{$o},$prioName{$result->{$o}},$state,$STATUS_TEXT{$state}) if $DEBUG;
134 $np->add_message($state, sprintf(_gt("%s subsystems in state %s"),$statusOid{$o},$prioName{$result->{$o}}) );
135 } elsif ( defined($infoOid{$o}) ) {
136 $infos{$infoOid{$o}} = $result->{$o};
137 printf STDERR ("oid: %-35s info: %-35s value: %s\n",$o,$infoOid{$o},$result->{$o}) if $DEBUG;
138 } else {
139 debug ("[WARN] unknown oid: $o !",$o);
140 }
141 }
142
143 my ($status, $message) = $np->check_messages('join' => ', ');
144
145 if ($status == OK) {
146 $message = sprintf(_gt("All subsystems (%s) are OK"),join(',',values(%statusOid)));
147 }
148 if ( defined($infos{'Vendor'}) ) {
149 $message .= sprintf(_gt(" for library %s %s (sn:%s)"),$infos{'Vendor'},$infos{'Model'},$infos{'Serial'});
150 }
151
152 $np->nagios_exit( $status, $message );
153
154
155 # Print debug information if $DEBUG > 0
156 sub debug {
157 print STDERR "[DEBUG] ".$_[0]."\n" if $DEBUG;
158 }
159 # Gettext wrapper
160 sub _gt {
161 return gettext($_[0]);
162 }

  ViewVC Help
Powered by ViewVC 1.1.8