-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_rrd.php
72 lines (55 loc) · 1.46 KB
/
check_rrd.php
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
<?php
/*
- value is equal to expected
- value is lower/higher than expected
- value is within % of expected (below/above ?)
- value is
- value is last value
- value is avg/min/max of last 1h
- expected is a number
- expected is value from last day/week/month (avg/min/max)
- expected is value from multiple last x
*/
require_once(__DIR__.'/vendor/autoload.php');
require_once(__DIR__.'/classes/RRDValue.php');
require_once(__DIR__.'/inc/nagios.php');
require_once(__DIR__.'/inc/array_funcs.php');
// Command line parser
$parser = new Console_CommandLine(array(
'description' => 'Check RRD',
'version' => '0.0.1',
'force_posix' => true
));
$parser->addArgument('config', array(
'description' => 'Config name',
'optional' => false
));
try {
$result = $parser->parse();
// Getting config
$config = $result->args['config'];
if (empty($config)) {
echo 'No config specified'."\n";
exit(NAGIOS_UNKNOWN);
}
$config_file = __DIR__.'/configs/'.$config.'.php';
if (!file_exists($config_file)) {
echo 'Config specified doesn\'t exist'."\n";
exit(NAGIOS_UNKNOWN);
}
require_once($config_file);
$args = $argv;
array_shift($args);
array_shift($args);
array_unshift($args, $config);
$r = check($args);
if (in_array($r, array(NAGIOS_OK, NAGIOS_WARNING, NAGIOS_CRITICAL, NAGIOS_UNKNOWN))) {
exit($r);
} else {
exit(NAGIOS_UNKNOWN);
}
exit(NAGIOS_UNKNOWN);
} catch (Exception $exc) {
$parser->displayError($exc->getMessage());
exit(NAGIOS_UNKNOWN);
}