~ubuntu-branches/ubuntu/precise/nagios-plugins/precise-proposed

« back to all changes in this revision

Viewing changes to contrib/check_compaq_insight.pl

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2004-06-15 15:37:48 UTC
  • Revision ID: james.westby@ubuntu.com-20040615153748-pq7702qdzghqfcns
Tags: upstream-1.3.1.0
ImportĀ upstreamĀ versionĀ 1.3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From mm@elabnet.de Mon Nov 18 09:59:04 2002
 
2
Date: Mon, 18 Nov 2002 12:19:04 +0100
 
3
From: Michael Markstaller <mm@elabnet.de>
 
4
To: nagiosplug-devel@lists.sourceforge.net
 
5
Subject: [Nagiosplug-devel] Submission: check_insight / checking Compaq
 
6
    Insight Agent status
 
7
 
 
8
Hi,
 
9
 
 
10
I've been looking to check the status/health of Compaq Insight Agents on
 
11
servers and found a spong plugin
 
12
(http://spong.sourceforge.net/downloads/plugins/spong-network/check_insi
 
13
ght) which I've slightly changed to work with Nagios.
 
14
I have pretty no idea of perl at all, just wanted to make it work for
 
15
me, so please don't shoot me for this copy-paste-code. I've tested some
 
16
basic things, it seems to work at least to report a warning if smthg is
 
17
degraded and OK of xcourse ;)
 
18
I'm also quite unsure if this is the right way to submit, so I'll just
 
19
try ;)
 
20
There're some "unknown" components on all servers I've checked so far,
 
21
if anybody has a documentation of what's exactly returned when getting
 
22
the OID 1.3.6.1.4.1.232.11.2.10.1.0 (CPQHOST_MIB isn't very descriptive)
 
23
I'd be happy to fix this.
 
24
 
 
25
--- cut ---
 
26
#!/usr/bin/perl
 
27
#
 
28
# (c)2002 Michael Markstaller, Elaborated Networks GmbH
 
29
# send bug reports to <mm@elabnet.de>
 
30
 
31
# This program is free software; you can redistribute it and/or
 
32
# modify it under the terms of the GNU General Public License
 
33
# as published by the Free Software Foundation; either version 2
 
34
# of the License, or (at your option) any later version.
 
35
#
 
36
# This program is distributed in the hope that it will be useful,
 
37
# but WITHOUT ANY WARRANTY; without even the implied warranty
 
38
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
39
# GNU General Public License for more details.
 
40
#
 
41
# you should have received a copy of the GNU General Public License
 
42
# along with this program (or with Nagios);  if not, write to the
 
43
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
44
# Boston, MA 02111-1307, USA
 
45
#
 
46
#
 
47
# Check Comapq Insight Management Agents Systems Status by SNMP
 
48
# based on the spong-plugin check_insight from:
 
49
#
 
50
http://spong.sourceforge.net/downloads/plugins/spong-network/check_insig
 
51
ht
 
52
#
 
53
# Usage:
 
54
# check_insight -H <host> -C community
 
55
#
 
56
 
 
57
use Net::SNMP;
 
58
use Getopt::Long;
 
59
Getopt::Long::Configure('bundling');
 
60
 
 
61
$version=0.01;
 
62
 
 
63
my %ERRORS = ('UNKNOWN' , '-1',
 
64
              'OK' , '0',
 
65
              'WARNING', '1',
 
66
              'CRITICAL', '2');
 
67
 
 
68
 
 
69
#
 
70
#              some default values
 
71
#
 
72
$TIMEOUT=15;
 
73
 
 
74
#
 
75
#              get command line options the regular way
 
76
#
 
77
GetOptions
 
78
        ("V"   => \$opt_V, "version"       => \$opt_V,
 
79
         "h"   => \$opt_h, "help"          => \$opt_h,
 
80
         "v" => \$verbose, "verbose"       => \$verbose,
 
81
         "H=s" => \$opt_H, "hostname=s"    => \$opt_H,
 
82
         "C=s" => \$opt_C, "community=s"    => \$opt_C);
 
83
 
 
84
#
 
85
#              handle the verbose stuff first
 
86
#
 
87
if ($opt_V) {
 
88
        print "\n";
 
89
        print "check_insight nagios plugin version $version\n";
 
90
        print "\n";
 
91
        print "The nagios plugins come with ABSOLUTELY NO WARRANTY.  You
 
92
may redistribute\n";
 
93
        print "copies of the plugins under the terms of the GNU General
 
94
Public License.\n";
 
95
        print "For more information about these matters, see the file
 
96
named COPYING.\n";
 
97
        print "\n";
 
98
        print "(c)2002 Michael Markstaller, Elaborated Networks GmbH\n";
 
99
        print "\n";
 
100
        print "\n";
 
101
        exit $ERRORS{'UNKNOWN'};
 
102
 
103
 
 
104
if ($opt_h) {
 
105
        print_help();
 
106
        exit $ERRORS{'UNKNOWN'};
 
107
}
 
108
 
 
109
#
 
110
#              now get options the weired way and set the defaults
 
111
#              if nothing else is provided
 
112
#
 
113
$opt_H = shift unless ($opt_H);
 
114
print_usage() unless ($opt_H);
 
115
 
 
116
#
 
117
#              dont let us wait forever...
 
118
#
 
119
$SIG{'ALRM'} = sub {
 
120
     print ("ERROR: No response from server (alarm)\n");
 
121
     exit $ERRORS{"UNKNOWN"};
 
122
};
 
123
alarm($TIMEOUT);
 
124
 
 
125
 
 
126
#
 
127
#              now we set things up for the real work
 
128
#              and fire up the request
 
129
#
 
130
 
 
131
########################################################################
 
132
########
 
133
my ($host) = ($opt_H);
 
134
my ($color, $summary, $message ) = ( "green", "", "" );
 
135
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
 
136
my ($community) = $opt_C;
 
137
 
 
138
# We use some look up tables for checking some config options.
 
139
my (@State) = ("Not Available", "Other", "OK", "Degraded", "Failed");
 
140
 
 
141
my (@MIBName) = ("", "Std", "Unknown", "Array",
 
142
           "Netware", "SCSI", "Health","Unknown", 
 
143
           "Store", "SM2", "Thresh", "OS", "UPS", 
 
144
           "Unknown", "IDE", "Clusters", "Fibre", 
 
145
           "MIB", "NIC");
 
146
 
 
147
# These are the positions within the table to actually look at.
 
148
my (@MIBs) = (1, 2, 3, 5, 6, 10, 11, 14, 18);
 
149
 
 
150
my ($oid) = "1.3.6.1.4.1.232.11.2.10.1.0";      # SysArray
 
151
 
 
152
# Open the connection.
 
153
my ($session, $error) = Net::SNMP->session(Hostname  => $host,
 
154
                                     Community => $community);
 
155
 
 
156
# If we can't open a connection, just return red straight away.
 
157
if (! defined $session) {
 
158
    print ("ERROR: Unable to contact server '$opt_H'\n");
 
159
    exit $ERRORS{"UNKNOWN"};
 
160
}
 
161
 
 
162
 
 
163
$session->translate;
 
164
my ($response) = $session->get_request($oid);
 
165
 
 
166
  if (!defined $response) {
 
167
    # If there's no response, something screwy is going on, give up.
 
168
    $summary = $session->error;
 
169
    print ("ERROR: $summary\n");
 
170
    exit $ERRORS{"UNKNOWN"};
 
171
    $session->close;
 
172
  } else {
 
173
    $session->close;
 
174
 
 
175
    # I'm not convinced that this is the easiest way to go about this,
 
176
this is
 
177
    # from some code which I've inherited and I've modified for use in
 
178
here.
 
179
    # Hi George!
 
180
    %h = %$response;
 
181
    my ($d) = $h{$oid};
 
182
 
 
183
    my (@list) = ();
 
184
        
 
185
    # Gobble the first two char's.
 
186
    $d = substr $d,2;
 
187
 
 
188
    while (length($d) > 0) {
 
189
      my ($v) = substr($d,0,2);
 
190
      $v = hex($v);
 
191
      $d = substr $d,2;
 
192
      push @list, $v;
 
193
    }
 
194
 
 
195
    # Value in $MIBs[1] is the overall status of the machine...
 
196
    my ($cond) = $MIBs[1];
 
197
    $message .= "Status: $State[$cond] ";
 
198
 
 
199
    foreach my $v (@MIBs) {
 
200
      $cond = $list[($v*4)+1];  # A little bit of magic.
 
201
 
 
202
      # We only bother printing the status out if it's actually
 
203
available,
 
204
      # as if it's N/A or Unknown then it's probably because the machine
 
205
      # isn't available.
 
206
      $message .= "$MIBName[$v]: $State[$cond] " if $cond > 1;
 
207
      next if $cond < 2;
 
208
 
 
209
      # What follows is some trickery to try and not to override a
 
210
previous
 
211
      # message at the same or lower color.
 
212
      if ($cond == 4) {
 
213
        if ($color ne 'red') {
 
214
          $color = 'red';
 
215
          $summary = "$MIBName[$v] is failed";
 
216
        }
 
217
      } elsif ($cond == 3) {
 
218
        if ($color ne 'red') {
 
219
          $color = 'yellow';
 
220
          $summary = "$MIBName[$v] is degraded" if $summary eq "";
 
221
        }
 
222
      } elsif ($cond < 2) {
 
223
        if ($color eq 'green') {
 
224
          $color = 'yellow';
 
225
          $summary = "$MIBName[$v] is unknown ($cond)" if $summary eq
 
226
"";
 
227
        }
 
228
      }
 
229
    }
 
230
  }
 
231
  
 
232
  $summary = "Ok" if $summary eq "";
 
233
 
 
234
#  return ($color, $summary, $message);
 
235
 
 
236
if ($color eq 'red') {
 
237
        print ("red Output: $message\n");
 
238
        exit $ERRORS{"CRITICAL"};
 
239
 } elsif ($color eq 'yellow') {
 
240
        print ("$summary $message\n");
 
241
        exit $ERRORS{"WARNING"};
 
242
 } elsif ($color eq 'green') {
 
243
        print ("$message\n");
 
244
        exit $ERRORS{"OK"};
 
245
}
 
246
 
 
247
 
 
248
sub print_usage () {
 
249
        print "Usage: $0 -H <host> -C <community> \n"; }
 
250
 
 
251
sub print_help () {
 
252
        print "\n";
 
253
        print "\n";
 
254
        print "check_insight nagios plugin version $version\n";
 
255
        print "\n";
 
256
        print "The nagios plugins come with ABSOLUTELY NO WARRANTY.  You
 
257
may redistribute\n";
 
258
        print "copies of the plugins under the terms of the GNU General
 
259
Public License.\n";
 
260
        print "For more information about these matters, see the file
 
261
named COPYING.\n";
 
262
        print "\n";
 
263
        print "(c)2002 Michael Markstaller, Elaborated Networks GmbH\n";
 
264
        print "\n";
 
265
        print "\n";
 
266
        print "This plugin checks the Compaq Insight Management agents
 
267
system status via SNMP on the specified host.\n";
 
268
        print "\n";
 
269
        print "\n";
 
270
        print_usage();
 
271
        print "\n";
 
272
        print "Options:\n";
 
273
        print " -H, --hostname=ADDRESS\n";
 
274
        print "     host name argument for server.\n";
 
275
        print " -C, --community=STRING\n";
 
276
        print "     SNMP Read-community string.\n";
 
277
        print " -h, --help\n";
 
278
        print "     print detailed help screen.\n";
 
279
        print " -V, --version\n";
 
280
        print "     print version information.\n";
 
281
        print "\n";
 
282
        print "\n";
 
283
 
284
--- cut ---
 
285
 
 
286
Michael
 
287
 
 
288
 
 
289
-------------------------------------------------------
 
290
This sf.net email is sponsored by: To learn the basics of securing 
 
291
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
 
292
Server Certificate: http://www.gothawte.com/rd524.html
 
293
_______________________________________________
 
294
Nagiosplug-devel mailing list
 
295
Nagiosplug-devel@lists.sourceforge.net
 
296
https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel