forked from Griesbacher/histou
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rule_examinant.php
83 lines (76 loc) · 3.02 KB
/
rule_examinant.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
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
Examinates rule files and returnes the best.
PHP version 5
@category Main_File
@package Default
@author Philip Griesbacher <griesbacher@consol.de>
@license http://opensource.org/licenses/gpl-license.php GNU Public License
@link https://github.com/ConSol/histou
**/
require_once('histou/bootstrap.php');
set_error_handler(
function ($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
);
//Set path to config file
\histou\Basic::parsIni($_SERVER['OMD_ROOT'].'/etc/histou/histou.ini');
//Parse commandline and get parameter
\histou\Basic::parsArgs();
// load ForecastTemplates
$forecastTemplateFiles = \histou\Folder::loadFolders(
array(FORECAST_TEMPLATE_FOLDER)
);
$forcastTemplateCache = new \histou\template\cache('cli');
$forecastTemplates = $forcastTemplateCache->loadTemplates($forecastTemplateFiles, '\histou\template\loader::loadForecastTemplate');
if (\histou\Basic::$request) {
$result = "[";
foreach (\histou\Basic::$request as $index => $value) {
\histou\template\Rule::setCheck($value['host'], $value['service'], $value['command'], $value['perf_labels']);
usort($forecastTemplates, '\histou\template\Template::compare');
$fValid = $forecastTemplates[0]->isValid();
\histou\Debug::add("ForecastTemplate order:");
foreach ($forecastTemplates as $ftemplate) {
\histou\Debug::add($ftemplate);
}
\histou\Debug::add("Is the first ForecastTemplate valid: ".\histou\Debug::printBoolean($fValid)."\n");
if ($fValid) {
$forecastTemplate = $forecastTemplates[0];
$className = get_class($forecastTemplate);
if ($className == 'histou\template\Rule') {
$forecastTemplate = \histou\template\loader::loadForecastTemplate($forecastTemplate->getFileName(), true);
}
$result .= $forecastTemplate->getJSON();
} else {
$result .= "[]";
}
$result .= ",";
}
$result = rtrim($result, ",");
$result .= "]";
echo $result;
} else {
\histou\template\Rule::setCheck(HOST, SERVICE, COMMAND, $PERF_LABEL);
usort($forecastTemplates, '\histou\template\Template::compare');
$fValid = $forecastTemplates[0]->isValid();
\histou\Debug::add("ForecastTemplate order:");
foreach ($forecastTemplates as $ftemplate) {
\histou\Debug::add($ftemplate);
}
\histou\Debug::add("Is the first ForecastTemplate valid: ".\histou\Debug::printBoolean($fValid)."\n");
if ($fValid) {
$forecastTemplate = $forecastTemplates[0];
$className = get_class($forecastTemplate);
if ($className == 'histou\template\Rule') {
$forecastTemplate = \histou\template\loader::loadForecastTemplate($forecastTemplate->getFileName(), true);
}
echo $forecastTemplate->getJSON();
} else {
echo "[]";
}
}