summaryrefslogtreecommitdiffstats
path: root/contrib/check_compaq_insight.pl
blob: dfb044020dc34fe15767fa4cf5ae276d5978858d (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
From mm@elabnet.de Mon Nov 18 09:59:04 2002
Date: Mon, 18 Nov 2002 12:19:04 +0100
From: Michael Markstaller <mm@elabnet.de>
To: nagiosplug-devel@lists.sourceforge.net
Subject: [Nagiosplug-devel] Submission: check_insight / checking Compaq
    Insight Agent status

Hi,

I've been looking to check the status/health of Compaq Insight Agents on
servers and found a spong plugin
(http://spong.sourceforge.net/downloads/plugins/spong-network/check_insi
ght) which I've slightly changed to work with Nagios.
I have pretty no idea of perl at all, just wanted to make it work for
me, so please don't shoot me for this copy-paste-code. I've tested some
basic things, it seems to work at least to report a warning if smthg is
degraded and OK of xcourse ;)
I'm also quite unsure if this is the right way to submit, so I'll just
try ;)
There're some "unknown" components on all servers I've checked so far,
if anybody has a documentation of what's exactly returned when getting
the OID 1.3.6.1.4.1.232.11.2.10.1.0 (CPQHOST_MIB isn't very descriptive)
I'd be happy to fix this.

--- cut ---
#!/usr/bin/perl
#
# (c)2002 Michael Markstaller, Elaborated Networks GmbH
# send bug reports to <mm@elabnet.de>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# you should have received a copy of the GNU General Public License
# along with this program (or with Nagios);  if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
#
#
# Check Comapq Insight Management Agents Systems Status by SNMP
# based on the spong-plugin check_insight from:
#
http://spong.sourceforge.net/downloads/plugins/spong-network/check_insig
ht
#
# Usage:
# check_insight -H <host> -C community
#

use Net::SNMP;
use Getopt::Long;
Getopt::Long::Configure('bundling');

$version=0.01;

my %ERRORS = ('UNKNOWN' , '-1',
              'OK' , '0',
              'WARNING', '1',
              'CRITICAL', '2');


#
#              some default values
#
$TIMEOUT=15;

#
#              get command line options the regular way
#
GetOptions
        ("V"   => \$opt_V, "version"       => \$opt_V,
         "h"   => \$opt_h, "help"          => \$opt_h,
         "v" => \$verbose, "verbose"       => \$verbose,
         "H=s" => \$opt_H, "hostname=s"    => \$opt_H,
         "C=s" => \$opt_C, "community=s"    => \$opt_C);

#
#              handle the verbose stuff first
#
if ($opt_V) {
        print "\n";
        print "check_insight nagios plugin version $version\n";
        print "\n";
        print "The nagios plugins come with ABSOLUTELY NO WARRANTY.  You
may redistribute\n";
        print "copies of the plugins under the terms of the GNU General
Public License.\n";
        print "For more information about these matters, see the file
named COPYING.\n";
        print "\n";
        print "(c)2002 Michael Markstaller, Elaborated Networks GmbH\n";
        print "\n";
        print "\n";
        exit $ERRORS{'UNKNOWN'};
} 

if ($opt_h) {
        print_help();
        exit $ERRORS{'UNKNOWN'};
}

#
#              now get options the weired way and set the defaults
#              if nothing else is provided
#
$opt_H = shift unless ($opt_H);
print_usage() unless ($opt_H);

#
#              dont let us wait forever...
#
$SIG{'ALRM'} = sub {
     print ("ERROR: No response from server (alarm)\n");
     exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);


#
#              now we set things up for the real work
#              and fire up the request
#

########################################################################
########
my ($host) = ($opt_H);
my ($color, $summary, $message ) = ( "green", "", "" );
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my ($community) = $opt_C;

# We use some look up tables for checking some config options.
my (@State) = ("Not Available", "Other", "OK", "Degraded", "Failed");

my (@MIBName) = ("", "Std", "Unknown", "Array",
	   "Netware", "SCSI", "Health","Unknown", 
	   "Store", "SM2", "Thresh", "OS", "UPS", 
	   "Unknown", "IDE", "Clusters", "Fibre", 
	   "MIB", "NIC");

# These are the positions within the table to actually look at.
my (@MIBs) = (1, 2, 3, 5, 6, 10, 11, 14, 18);

my ($oid) = "1.3.6.1.4.1.232.11.2.10.1.0";	# SysArray

# Open the connection.
my ($session, $error) = Net::SNMP->session(Hostname  => $host,
				     Community => $community);

# If we can't open a connection, just return red straight away.
if (! defined $session) {
    print ("ERROR: Unable to contact server '$opt_H'\n");
    exit $ERRORS{"UNKNOWN"};
}


$session->translate;
my ($response) = $session->get_request($oid);

  if (!defined $response) {
    # If there's no response, something screwy is going on, give up.
    $summary = $session->error;
    print ("ERROR: $summary\n");
    exit $ERRORS{"UNKNOWN"};
    $session->close;
  } else {
    $session->close;

    # I'm not convinced that this is the easiest way to go about this,
this is
    # from some code which I've inherited and I've modified for use in
here.
    # Hi George!
    %h = %$response;
    my ($d) = $h{$oid};

    my (@list) = ();
	
    # Gobble the first two char's.
    $d = substr $d,2;

    while (length($d) > 0) {
      my ($v) = substr($d,0,2);
      $v = hex($v);
      $d = substr $d,2;
      push @list, $v;
    }

    # Value in $MIBs[1] is the overall status of the machine...
    my ($cond) = $MIBs[1];
    $message .= "Status: $State[$cond] ";

    foreach my $v (@MIBs) {
      $cond = $list[($v*4)+1];  # A little bit of magic.

      # We only bother printing the status out if it's actually
available,
      # as if it's N/A or Unknown then it's probably because the machine
      # isn't available.
      $message .= "$MIBName[$v]: $State[$cond] " if $cond > 1;
      next if $cond < 2;

      # What follows is some trickery to try and not to override a
previous
      # message at the same or lower color.
      if ($cond == 4) {
        if ($color ne 'red') {
          $color = 'red';
          $summary = "$MIBName[$v] is failed";
        }
      } elsif ($cond == 3) {
        if ($color ne 'red') {
          $color = 'yellow';
          $summary = "$MIBName[$v] is degraded" if $summary eq "";
        }
      } elsif ($cond < 2) {
        if ($color eq 'green') {
          $color = 'yellow';
          $summary = "$MIBName[$v] is unknown ($cond)" if $summary eq
"";
        }
      }
    }
  }
  
  $summary = "Ok" if $summary eq "";

#  return ($color, $summary, $message);

if ($color eq 'red') {
	print ("red Output: $message\n");
	exit $ERRORS{"CRITICAL"};
 } elsif ($color eq 'yellow') {
	print ("$summary $message\n");
	exit $ERRORS{"WARNING"};
 } elsif ($color eq 'green') {
	print ("$message\n");
	exit $ERRORS{"OK"};
}


sub print_usage () {
        print "Usage: $0 -H <host> -C <community> \n"; }
 
sub print_help () {
        print "\n";
        print "\n";
        print "check_insight nagios plugin version $version\n";
        print "\n";
        print "The nagios plugins come with ABSOLUTELY NO WARRANTY.  You
may redistribute\n";
        print "copies of the plugins under the terms of the GNU General
Public License.\n";
        print "For more information about these matters, see the file
named COPYING.\n";
        print "\n";
        print "(c)2002 Michael Markstaller, Elaborated Networks GmbH\n";
        print "\n";
        print "\n";
        print "This plugin checks the Compaq Insight Management agents
system status via SNMP on the specified host.\n";
        print "\n";
        print "\n";
        print_usage();
        print "\n";
        print "Options:\n";
        print " -H, --hostname=ADDRESS\n";
        print "     host name argument for server.\n";
        print " -C, --community=STRING\n";
	print "     SNMP Read-community string.\n";
        print " -h, --help\n";
	print "     print detailed help screen.\n";
        print " -V, --version\n";
	print "     print version information.\n";
        print "\n";
        print "\n";
} 
--- cut ---

Michael


-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
Nagiosplug-devel mailing list
Nagiosplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel