/ Nagios ^

Nagios: status.cgi Customisation Guide

Last updated 28 Jul 2021

My most used page in Nagios is Services (Unhandled), essentially as a dashboard for any new issues. The problem is that it won't show anything for a host being down, so I've added an All Unhandled link to my side.php with the following line of code:

<li><a href="<?php echo $cfg["cgi_base_url"];?>/status.cgi?host=all&type=detail&hoststatustypes=6&hostprops=10&serviceprops=42&servicestatustypes=60" target="<?php echo $link_target;?>">All Unhandled</a></li>

Which ends up giving you a URL looking like:

https://server.domain.com/nagios/cgi-bin/status.cgi?host=all&type=detail&hoststatustypes=6&hostprops=10&serviceprops=42&servicestatustypes=60

And the filters display as:

Display Filters:
   Host Status Types: Up | Down
     Host Properties: Not In Scheduled Downtime & Has Not Been Acknowledged
Service Status Types: Unknown | Warning | Critical
  Service Properties: Not In Scheduled Downtime & Has Not Been Acknowledged & Active Checks Enabled

You can also use status.cgi to build your own searchbars to add to your side.php - I use the following code to give me searchbars for hosts, services and host groups (with inset prompts):

<div class="navbarsearch">
    <form method="get" action="<?php echo $cfg["cgi_base_url"];?>/status.cgi" target="<?php echo $link_target;?>">
        <fieldset>
            <legend>Quick Search:</legend>
            <input type='text' name='host' placeholder='Host (exact name)' size='18' class="NavBarSearchItem">
        </fieldset>
    </form>
    <form method="get" action="<?php echo $cfg["cgi_base_url"];?>/status.cgi" target="<?php echo $link_target;?>">
        <fieldset>
            <input type='text' name='servicefilter' placeholder='Service (case-sensitive)' size='18' class="NavBarSearchItem">
        </fieldset>
    </form>
    <form method="get" action="<?php echo $cfg["cgi_base_url"];?>/status.cgi" target="<?php echo $link_target;?>">
        <fieldset>
            <input type='text' name='hostgroup' placeholder='Host Group (short name)' size='18' class="NavBarSearchItem">
        </fieldset>
    </form>
</div>

This gives you something looking like this:

I think I came across that handy URL on Stack Overflow but I couldn't find any official Nagios documentation on the bitwise operators to understand how to craft or modify these URLs. Luckily, a Nagios MVP called jsmurphy on their support forums put together a blog post detailing them back in 2012. Unfortunately, their website roshamboot.org no longer exists but a snapshot of the page is available on archive.org here, and I wanted to post the contents of it here so it's available on a current website. I've left most of it intact but I think it was written for Nagios Core 3 so I checked the files in the source code (currently at version 4.4.6) and updated the hoststatustypes with their newer names.

jsmurphy - 26 Jun 2012
Every now and then I see a question along the lines of "How do I customize the Nagios problems screen?", "How do I customize status.cgi?" or "What are the parameters or arguments for status.cgi". Well wonder no more! Hidden deep within the nagios source code and by deep I mean the "include" directory, is the cgiutils.h and statusdata.h these two files have all the information you need.

But lets make it a little simpler, if you were to copy the URL of the problems heading in Nagios and then paste it, it would look something like this: http://nagioswebsite/cgi-bin/status.cgi?host=all&servicestatustypes=28

Nagios uses bitwise operations to quickly calculate what to display, the 28 next to servicestatustypes is the number used for selecting what service statuses to display on the Nagios problem page. So how do we arrive at that number of 28? Well lets have a look at the table:

&servicestatustypes=
#define SERVICE_PENDING     1
#define SERVICE_OK          2
#define SERVICE_WARNING     4
#define SERVICE_UNKNOWN     8
#define SERVICE_CRITICAL    16

If you add the numbers of the service states you want to see together you will arrive at the number required for that particular argument. So in the case of our example if we add warning(4), Unknown(8) and Critical(16) together we get the number 28! That's all there is to it! Below are the tables for the other parameters you may wish to use to customize your status.cgi.

&hoststatustypes=
#define HOST_PENDING            1
#define SD_HOST_UP              2
#define SD_HOST_DOWN            4
#define SD_HOST_UNREACHABLE     8
&hostprops=
#define HOST_SCHEDULED_DOWNTIME         1
#define HOST_NO_SCHEDULED_DOWNTIME      2
#define HOST_STATE_ACKNOWLEDGED         4
#define HOST_STATE_UNACKNOWLEDGED       8
#define HOST_CHECKS_DISABLED            16
#define HOST_CHECKS_ENABLED             32
#define HOST_EVENT_HANDLER_DISABLED     64
#define HOST_EVENT_HANDLER_ENABLED      128
#define HOST_FLAP_DETECTION_DISABLED    256
#define HOST_FLAP_DETECTION_ENABLED     512
#define HOST_IS_FLAPPING                1024
#define HOST_IS_NOT_FLAPPING            2048
#define HOST_NOTIFICATIONS_DISABLED     4096
#define HOST_NOTIFICATIONS_ENABLED      8192
#define HOST_PASSIVE_CHECKS_DISABLED    16384
#define HOST_PASSIVE_CHECKS_ENABLED     32768
#define HOST_PASSIVE_CHECK              65536
#define HOST_ACTIVE_CHECK               131072
#define HOST_HARD_STATE                 262144
#define HOST_SOFT_STATE                 524288
&serviceprops=
#define SERVICE_SCHEDULED_DOWNTIME          1
#define SERVICE_NO_SCHEDULED_DOWNTIME       2
#define SERVICE_STATE_ACKNOWLEDGED          4
#define SERVICE_STATE_UNACKNOWLEDGED        8
#define SERVICE_CHECKS_DISABLED             16
#define SERVICE_CHECKS_ENABLED              32
#define SERVICE_EVENT_HANDLER_DISABLED      64
#define SERVICE_EVENT_HANDLER_ENABLED       128
#define SERVICE_FLAP_DETECTION_ENABLED      256
#define SERVICE_FLAP_DETECTION_DISABLED     512
#define SERVICE_IS_FLAPPING                 1024
#define SERVICE_IS_NOT_FLAPPING             2048
#define SERVICE_NOTIFICATIONS_DISABLED      4096
#define SERVICE_NOTIFICATIONS_ENABLED       8192
#define SERVICE_PASSIVE_CHECKS_DISABLED     16384
#define SERVICE_PASSIVE_CHECKS_ENABLED      32768
#define SERVICE_PASSIVE_CHECK               65536
#define SERVICE_ACTIVE_CHECK                131072
#define SERVICE_HARD_STATE                  262144
#define SERVICE_SOFT_STATE                  524288

The sort functions only allow one option to be selected at a time so there's no bitwise operations going on here. Just type the numbers as you see them i.e. &sortoption=1 (to sort by hostname)

&sortoption=
#define SORT_NOTHING            0
#define SORT_HOSTNAME           1
#define SORT_SERVICENAME        2
#define SORT_SERVICESTATUS      3
#define SORT_LASTCHECKTIME      4
#define SORT_CURRENTATTEMPT     5
#define SORT_STATEDURATION      6
#define SORT_NEXTCHECKTIME      7
#define SORT_HOSTSTATUS         8
#define SORT_HOSTURGENCY        9
&sorttypes=
#define SORT_NONE           0
#define SORT_ASCENDING      1
#define SORT_DESCENDING     2

You can also use &service=, &servicegroup=, &host= and &hostgroup= these fields all accept the phrase "all" (which will select everything) or a string string that matches a specific Nagios object; url encoded of course so you need to use %20 for spaces in service names. There is also an &servicefilter= option that matches based on case sensitive regex.

Note: As far as I know there is no way to do an "OR" so you can't do "I want it to display only the server if it's down OR the critical services if it is not"


Return to roddie.digital / top