check_compaq_insight.pl 8.6 KB

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