Service Status Freshness indicator
Posted: Thu Apr 09, 2015 11:42 am
Thought I would share something from this mornings efforts. I have been having issues with XI crashing and I was getting tired of having to open a check and then comparing the next check against the current time. Not knowing PHP, javascript, or much about HTML or DOM I managed to come up with this. The hardest part was finding the file to modify. In /usr/local/nagiosxi/html/includes/components/xicore modified ajaxhelpers-servicestatus.inc.php. I changed
to

I know I should be using classes instead of in-line styles and I'm sure my hacknslash coding make some people cringe. I wonder about timezone issues or if it will really go red when not fresh. Feel free to tell me how I'm doing it wrong. For now I need to get back to my actual projects. Just wanted to share and hopefully something like this might make it into future versions. I do want something on hosts and summary pages as well but I don't want to make yet another thing I have to retro-fit into multiple files on every upgrade.
Code: Select all
$nextcheck = get_datetime_string_from_datetime($xml->servicestatus->next_check, "", DT_SHORT_DATE_TIME, DF_AUTO, gettext("Not scheduled"));
$output .= '<tr'><td>' . gettext('Next Check') . ':</td><td>' . $nextcheck . '</td></tr>';
Code: Select all
$nextcheck = get_datetime_string_from_datetime($xml->servicestatus->next_check, "", DT_SHORT_DATE_TIME, DF_AUTO, gettext("Not scheduled"));
$nowepoch = time();
$nextcheckepoch = strtotime($xml->servicestatus->next_check);
if ($nowepoch > $nextcheckepoch) {
$nextcheckclass = ' style="background-color:#FF795F"';
} else {
$nextcheckclass = ' style="background-color:#B2FF5F"';
}
$output .= '<tr' . $nextcheckclass . '><td>' . gettext('Next Check') . ':</td><td>' . $nextcheck . '</td></tr>';

I know I should be using classes instead of in-line styles and I'm sure my hacknslash coding make some people cringe. I wonder about timezone issues or if it will really go red when not fresh. Feel free to tell me how I'm doing it wrong. For now I need to get back to my actual projects. Just wanted to share and hopefully something like this might make it into future versions. I do want something on hosts and summary pages as well but I don't want to make yet another thing I have to retro-fit into multiple files on every upgrade.