Guide: Nagios statuscgi

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:

(excuse the erratic display my syntax highlighter doesn’t always like to keep it neat)

&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 HOST_UP           2
#define HOST_DOWN         4
#define 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 its down OR the critical services if it is not”.

comments powered by Disqus