File check_snmp_klima 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) 2008 linux-administrator.com
9
** All Rights Reserved.
10
*/
11
12
// required arguments
13
// $1 = Host / IP
14
// $2 = read community string
15
16
$lowerthreshold = "SNMPv2-SMI::enterprises.1909.13.1.1.1.3.1";
17
$upperthreshold = "SNMPv2-SMI::enterprises.1909.13.1.1.1.4.1";
18
$currenttemprature = "SNMPv2-SMI::enterprises.1909.13.1.1.1.5.1";
19
$grad = iconv("UTF-8","ISO-8859-15","°");
20
define('MYNAME',"check_rms200");
21
define('OK',0);
22
define('WARNING',1);
23
define('CRITICAL',2);
24
define('UNKNOWN',3);
25
define('DEPENDENT',4);
26
27
define_syslog_variables();
28
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
29
30
if ( ! extension_loaded("snmp") ) {
31
if ( ! dl("snmp") ) {
32
syslog(LOG_ERR,"snmp extension not loaded!");
33
exit;
34
}
35
}
36
ini_set("display_errors","on");
37
// get working directory
38
define('BASE',dirname(__FILE__));
39
40
$cmdlineopt = getopt("H:C:");
41
if (empty($cmdlineopt)) {
42
echo "Usage: " . MYNAME . " -H [<hostname> | <ipaddress>] -C [<community>]\n";
43
echo "\t -H\t Hostname or IP address (default: localhost)\n";
44
echo "\t -C\t Community (default: public)\n";
45
exit(1);
46
}
47
if ( isset($cmdlineopt['H']) ) {
48
$hostname = $cmdlineopt['H'];
49
} else {
50
$hostname = "localhost";
51
}
52
53
if ( isset($cmdlineopt['C']) ) {
54
$community = $cmdlineopt['C'];
55
} else {
56
$community = "public";
57
}
58
$lowerval = @snmpget($hostname,$community,$lowerthreshold);
59
if ( $lowerval == FALSE ) {
60
echo "Can't get lower threshold\n";
61
exit(UNKNOWN);
62
} else {
63
$lowarr = explode(": ",$lowerval);
64
$lowerval = $lowarr[1];
65
}
66
$upperval = @snmpget($hostname,$community,$upperthreshold);
67
if ( $upperval == FALSE ) {
68
echo "Can't get upper threshold\n";
69
exit(UNKNOWN);
70
} else {
71
$upparr = explode(": ",$upperval);
72
$upperval = $upparr[1];
73
}
74
$currentval = @snmpget($hostname,$community,$currenttemprature);
75
if ( $currentval == FALSE ) {
76
echo "Can't get current temprature value\n";
77
exit(UNKNOWN);
78
} else {
79
$curarr = explode(": ",$currentval);
80
$currentval = $curarr[1];
81
}
82
$cur = $currentval / 100;
83
$low = $lowerval / 100;
84
$high = $upperval / 100;
85
86
if ( $currentval < $lowerval ) {
87
echo "Current Temprature " . $cur . " " .$grad . "C is below threshold of " . $low . " " . $grad . "C\n";
88
exit(WARNING);
89
}
90
if ( $currentval > $upperval ) {
91
echo "Current Temprature " . $cur . " " . $grad . "C is over threshold of " . $high . " " . $grad . "C\n";
92
exit(CRITICAL);
93
}
94
if ( $currentval < $upperval && $currentval > $lowerval ) {
95
echo "Current Temprature is " . $cur . " " . $grad . "C\n";
96
exit(OK);
97
}
98
?>
99