|
@@ -0,0 +1,100 @@
+#!/usr/bin/php5
+<?php
+/*
+** Author
+** Original author Carsten Schoene (cs@linux-administrator.com)
+**
+** Copyright
+** Copyright (c) 2009 linux-administrator.com
+** All Rights Reserved.
+*/
+
+$etherbox = ".1.3.6.1.4.1.14848.2.1.2.1.4";
+$etherboxname = ".1.3.6.1.4.1.14848.2.1.2.1.2";
+$messpcwin = ".1.3.6.1.4.1.14848.1.2.1.4";
+$messpcwinname = ".1.3.6.1.4.1.14848.1.2.1.2";
+
+define('MYNAME',"check_messpc");
+define_syslog_variables();
+openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
+
+if ( ! extension_loaded("snmp") ) {
+ if ( ! dl("snmp") ) {
+ syslog(LOG_ERR,"snmp extension not loaded!");
+ exit;
+ }
+}
+ini_set("display_errors","on");
+
+$cmdlineopt = getopt("t:H:C:w:c:p:h");
+
+if (empty($cmdlineopt)) {
+ print_help();
+}
+
+function print_help() {
+ echo "Usage: " . MYNAME . "< -t etherbox | soft > < -H HOSTNAME | -C COMMUNITY | -w | -c > <-p port>\n";
+ echo "\t -t\t type of target etherbox or software\n";
+ echo "\t -H\t target Hostname to check\n";
+ echo "\t -C\t community name\n";
+ echo "\t -w\t warning threshold\n";
+ echo "\t -c\t critical threshold\n";
+ echo "\t -p\t port of sensor ( 1 - 12)\n";
+ echo "\t -h\t this help screen\n";
+ exit(1);
+}
+
+function print_message ( $msg, $retval ) {
+ echo "$msg\n";
+ exit($retval);
+}
+
+if ( isset($cmdlineopt['t']) ) {
+ switch ($cmdlineopt['t']) {
+ case 0:
+ case "ether":
+ case "etherbox":
+ $trgtoid = $etherbox;
+ $trgtoidname = $etherboxname;
+ break;
+ case 1:
+ case "soft":
+ case "software":
+ $trgtoid = $messpcwin;
+ $trgtoidname = $messpcwinname;
+ break;
+ default:
+ print_help;
+
+ }
+}
+
+if ( isset($cmdlineopt['H']) && isset($cmdlineopt['C']) && isset($cmdlineopt['w']) && isset($cmdlineopt['c']) && isset($trgtoid) && isset($cmdlineopt['p']) ) {
+
+ $sensorvaluearr = explode(" " , snmpget($cmdlineopt['H'], $cmdlineopt['C'], $trgtoid . "." . $cmdlineopt['p'] ) );
+ $sensornamearr = snmpget($cmdlineopt['H'], $cmdlineopt['C'], $trgtoidname . "." . $cmdlineopt['p'] );
+ $sensornamearr = explode("STRING: " , $sensornamearr);
+ $sensorvalue = $sensorvaluearr[1];
+ $sensorname = $sensornamearr[1];
+ $sensorname = ereg_replace("\"","",$sensorname);
+ if ( $sensorvalue > $cmdlineopt['c'] ) {
+
+ $message = "SENSOR $sensorname Critical: " . $sensorvalue;
+ print_message($message,2);
+
+ } elseif ( $sensorvalue > $cmdlineopt['w'] ) {
+
+ $message = "SENSOR $sensorname Warning: " . $sensorvalue;
+ print_message($message,1);
+
+ } else {
+
+ $message = "SENSOR $sensorname OK: " . $sensorvalue;
+ print_message($message,0);
+
+ }
+
+} else {
+ print_help();
+}
+?>
|