Esempio n. 1
0
define("INFLUX_QUERY", sprintf("show series from /%s%s%s.*/", str_replace("/", '\\/', HOST), INFLUX_FIELDSEPERATOR, str_replace('/', '\\/', SERVICE)));
// database load perfdata
$influx = new Influxdb(INFLUX_URL);
$request = $influx->makeRequest(INFLUX_QUERY);
$perfData = $influx->filterPerfdata($request, HOST, SERVICE, '\\' . INFLUX_FIELDSEPERATOR);
$perfDataSize = sizeof($perfData);
if ($perfDataSize < 4) {
    if ($perfDataSize == 1) {
        returnData(Debug::errorMarkdownDashboard('#Influxdb Error: ' . $perfData[0] . ' Query: ' . INFLUX_QUERY), 1);
    } else {
        returnData(Debug::errorMarkdownDashboard('#Host / Service not found in Influxdb'), 1);
    }
}
// load templates
$templates = Folder::loadFolders(array(CUSTOM_TEMPLATE_FOLDER, DEFAULT_TEMPLATE_FOLDER));
Rule::setCheck($perfData['host'], $perfData['service'], $perfData['command'], array_keys($perfData['perfLabel']));
usort($templates, 'Template::compare');
$valid = $templates[0]->isValid();
foreach ($templates as $template) {
    Debug::add($template);
}
Debug::add("Is the first template valid: " . Debug::printBoolean($valid));
if ($valid) {
    $template = $templates[0];
} else {
    $template = Template::findDefaultTemplate($templates, 'default.php');
}
if (isset($template) && !empty($template)) {
    returnData($template->getTemplate($perfData), 0, 'OK');
} else {
    returnData(Debug::errorMarkdownDashboard('#No template found!'), 1);