File check_messpc of Package nagios-plugins-snmp
1
#!/usr/bin/php5
2
<?php
3
/*
4
** Author
5
** Original author Carsten Schoene (cs@linux-administrator.com)
6
**
7
** Copyright
8
** Copyright (c) 2009 linux-administrator.com
9
** All Rights Reserved.
10
*/
11
12
$etherbox = ".1.3.6.1.4.1.14848.2.1.2.1.4";
13
$etherboxname = ".1.3.6.1.4.1.14848.2.1.2.1.2";
14
$messpcwin = ".1.3.6.1.4.1.14848.1.2.1.4";
15
$messpcwinname = ".1.3.6.1.4.1.14848.1.2.1.2";
16
17
define('MYNAME',"check_messpc");
18
define_syslog_variables();
19
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
20
21
if ( ! extension_loaded("snmp") ) {
22
if ( ! dl("snmp") ) {
23
syslog(LOG_ERR,"snmp extension not loaded!");
24
exit;
25
}
26
}
27
ini_set("display_errors","on");
28
29
$cmdlineopt = getopt("t:H:C:w:c:p:h");
30
31
if (empty($cmdlineopt)) {
32
print_help();
33
}
34
35
function print_help() {
36
echo "Usage: " . MYNAME . "< -t etherbox | soft > < -H HOSTNAME | -C COMMUNITY | -w | -c > <-p port>\n";
37
echo "\t -t\t type of target etherbox or software\n";
38
echo "\t -H\t target Hostname to check\n";
39
echo "\t -C\t community name\n";
40
echo "\t -w\t warning threshold\n";
41
echo "\t -c\t critical threshold\n";
42
echo "\t -p\t port of sensor ( 1 - 12)\n";
43
echo "\t -h\t this help screen\n";
44
exit(1);
45
}
46
47
function print_message ( $msg, $retval ) {
48
echo "$msg\n";
49
exit($retval);
50
}
51
52
if ( isset($cmdlineopt['t']) ) {
53
switch ($cmdlineopt['t']) {
54
case 0:
55
case "ether":
56
case "etherbox":
57
$trgtoid = $etherbox;
58
$trgtoidname = $etherboxname;
59
break;
60
case 1:
61
case "soft":
62
case "software":
63
$trgtoid = $messpcwin;
64
$trgtoidname = $messpcwinname;
65
break;
66
default:
67
print_help;
68
69
}
70
}
71
72
if ( isset($cmdlineopt['H']) && isset($cmdlineopt['C']) && isset($cmdlineopt['w']) && isset($cmdlineopt['c']) && isset($trgtoid) && isset($cmdlineopt['p']) ) {
73
74
$sensorvaluearr = explode(" " , snmpget($cmdlineopt['H'], $cmdlineopt['C'], $trgtoid . "." . $cmdlineopt['p'] ) );
75
$sensornamearr = snmpget($cmdlineopt['H'], $cmdlineopt['C'], $trgtoidname . "." . $cmdlineopt['p'] );
76
$sensornamearr = explode("STRING: " , $sensornamearr);
77
$sensorvalue = $sensorvaluearr[1];
78
$sensorname = $sensornamearr[1];
79
$sensorname = ereg_replace("\"","",$sensorname);
80
if ( $sensorvalue > $cmdlineopt['c'] ) {
81
82
$message = "SENSOR $sensorname Critical: " . $sensorvalue;
83
print_message($message,2);
84
85
} elseif ( $sensorvalue > $cmdlineopt['w'] ) {
86
87
$message = "SENSOR $sensorname Warning: " . $sensorvalue;
88
print_message($message,1);
89
90
} else {
91
92
$message = "SENSOR $sensorname OK: " . $sensorvalue;
93
print_message($message,0);
94
95
}
96
97
} else {
98
print_help();
99
}
100
?>
101