Page 1 of 1

Service Status Freshness indicator

Posted: Thu Apr 09, 2015 11:42 am
by rseiwert
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

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>';
to

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>';
Image

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.

Re: Service Status Freshness indicator

Posted: Thu Apr 09, 2015 11:56 am
by tmcdonald
As long as $nowepoch and $nextcheckepoch are in fact Unix timestamps then the comparison should be valid. I'm not a developer but I have made modifications like this in the past and this is how I would have done it.

Re: Service Status Freshness indicator

Posted: Thu Apr 09, 2015 1:09 pm
by rseiwert
Just a note on style. After running with this for a few hours it seems bad form that a warning or critical service would have anything green in the details. I taken to only marking it red if it is stale.

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 = '';
        }
        $output .= '<tr' . $nextcheckclass . '><td>' . gettext('Next Check') . ':</td><td>' . $nextcheck . '</td></tr>';

Re: Service Status Freshness indicator

Posted: Thu Apr 09, 2015 5:04 pm
by cmerchant
Thanks for your contribution. Would you like for us to close this thread, or leave it open for more feedback?

Re: Service Status Freshness indicator

Posted: Wed Apr 22, 2015 7:11 am
by rseiwert
Close this, please turn this into a feature request for me. This has really helped for me in detecting when XI was not updating.