in contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php [284:362]
function query_alerts ($status_file_content, $alert_type, $host) {
$servicestatus_attributes = array ("service_description", "host_name", "current_attempt",
"current_state", "plugin_output", "last_hard_state_change", "last_hard_state",
"last_time_ok", "last_time_warning", "last_time_unknown",
"last_time_critical", "is_flapping", "last_check");
$num_matches = preg_match_all("/servicestatus \{([\S\s]*?)\}/", $status_file_content, $matches, PREG_PATTERN_ORDER);
#echo $matches[0][0] . ", " . $matches[0][1] . "\n";
#echo $matches[1][0] . ", " . $matches[1][1] . "\n";
$services_objects = array ();
$i = 0;
foreach ($matches[0] as $object) {
$servicestatus = array ();
switch ($alert_type) {
case "all":
if (empty($host) || getParameter($object, "host_name") == $host) {
foreach ($servicestatus_attributes as $attrib) {
$servicestatus[$attrib] = htmlentities(getParameter($object, $attrib), ENT_COMPAT);
}
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
$servicestatus['service_description'] = $srv_desc[1];
}
break;
case "nok":
if (getParameter($object, "last_hard_state") != ok &&
(empty($host) || getParameter($object, "host_name") == $host)) {
foreach ($servicestatus_attributes as $attrib) {
$servicestatus[$attrib] = htmlentities(getParameter($object, $attrib), ENT_COMPAT);
}
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
$servicestatus['service_description'] = $srv_desc[1];
}
break;
case "ok":
if (getParameter($object, "last_hard_state") == ok &&
(empty($host) || getParameter($object, "host_name") == $host)) {
foreach ($servicestatus_attributes as $attrib) {
$servicestatus[$attrib] = htmlentities(getParameter($object, $attrib), ENT_COMPAT);
}
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
$servicestatus['service_description'] = $srv_desc[1];
}
break;
case "warn":
if (getParameter($object, "last_hard_state") == warn &&
(empty($host) || getParameter($object, "host_name") == $host)) {
foreach ($servicestatus_attributes as $attrib) {
$servicestatus[$attrib] = htmlentities(getParameter($object, $attrib), ENT_COMPAT);
}
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
$servicestatus['service_description'] = $srv_desc[1];
}
break;
case "critical":
if (getParameter($object, "last_hard_state") == critical &&
(empty($host) || getParameter($object, "host_name") == $host)) {
foreach ($servicestatus_attributes as $attrib) {
$servicestatus[$attrib] = htmlentities(getParameter($object, $attrib), ENT_COMPAT);
}
$servicestatus['service_type'] = get_service_type($servicestatus['service_description']);
$srv_desc = explode ("::",$servicestatus['service_description'],2);
$servicestatus['service_description'] = $srv_desc[1];
}
break;
}
if (!empty($servicestatus)) {
$services_objects[$i] = $servicestatus;
$i++;
}
}
/* echo "COUNT : " . count ($services_objects) . "\n"; */
return $services_objects;
}