Getting Current State from JSON Query

Engage with the community of users including those using the open source solutions.
Includes Nagios Core, Plugins, and NCPA

Getting Current State from JSON Query

Postby grenley » Thu Mar 08, 2018 7:02 pm

Hi.
This should be an easy and quick one.
I'm using the Core JSON API to get object info.
One of the values that's in status.dat is "current_state" but I don't see that come back in the JSON.
There's a value called "status" but it has a value that does not match the current state.
In the json below, the status = 2 but the current state is "UP" (0).
How do I handle this?

Code: Select all
{
    "format_version": 0,
    "result": {
        "query_time": 1520553414000,
        "cgi": "statusjson.cgi",
        "user": "coreapiuser",
        "query": "host",
        "query_status": "released",
        "program_start": 1520355947000,
        "last_data_update": 1520553407000,
        "type_code": 0,
        "type_text": "Success",
        "message": ""
    },
    "data": {
        "host": {
            "name": "patinfra.sldc.sbc.com",
            "plugin_output": "OK - Agent is alive",
            "long_plugin_output": "",
            "perf_data": "",
            "status": 2,
            "last_update": 1520553407000,
            "has_been_checked": true,
            "should_be_scheduled": true,
            "current_attempt": 1,
            "max_attempts": 1,
            "last_check": 1520553406000,
            "next_check": 1520553577000,
            "check_options": 8,
            "check_type": 1,
            "last_state_change": 1519545569000,
            "last_hard_state_change": 1519545569000,
            "last_hard_state": 0,
            "last_time_up": 1520553407000,
            "last_time_down": 1519545569000,
            "last_time_unreachable": 0,
            "state_type": 1,
            "last_notification": 0,
            "next_notification": 0,
            "no_more_notifications": false,
            "notifications_enabled": true,
            "problem_has_been_acknowledged": false,
            "acknowledgement_type": 0,
            "current_notification_number": 0,
            "accept_passive_checks": true,
            "event_handler_enabled": true,
            "checks_enabled": true,
            "flap_detection_enabled": true,
            "is_flapping": false,
            "percent_state_change": 0,
            "latency": 0,
            "execution_time": 0,
            "scheduled_downtime_depth": 0,
            "process_performance_data": true,
            "obsess": true
        }
    }
}


Thanks, Rick
grenley
 
Posts: 95
Joined: Tue May 13, 2014 6:06 pm

Re: Getting Current State from JSON Query

Postby cdienger » Fri Mar 09, 2018 4:08 pm

The 2 actually means up in this cases. You can use the enumerate option to see this:

http://nagios_ip/nagios/cgi-bin/statusjson.cgi?query=host&formatoptions=enumerate&hostname=<hostname>
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
cdienger
Support Tech
 
Posts: 4238
Joined: Tue Feb 07, 2017 11:26 am

Re: Getting Current State from JSON Query

Postby grenley » Fri Mar 09, 2018 7:22 pm

Awesome. Thanks!
Is there full doc on all the API fields and options?
Also, I can't find any doc on how the numeric status values map (like, 2 = "ok")
Is that documented somewhere?
grenley
 
Posts: 95
Joined: Tue May 13, 2014 6:06 pm

Re: Getting Current State from JSON Query

Postby mcapra » Mon Mar 12, 2018 11:57 am

grenley wrote:Is there full doc on all the API fields and options?

I don't think so, but the JSON Query Generator (http://<nagios server>/nagios/jsonquery.html) offers all available CGIs and various variables you can set:
https://labs.nagios.com/2014/06/19/exploring-the-new-json-cgis-in-nagios-core-4-0-7-part-1/

grenley wrote:Also, I can't find any doc on how the numeric status values map (like, 2 = "ok"). Is that documented somewhere?

Kinda sorta? Things are handled a bit differently when it comes to filtering within the CGIs. Here's your "host is up" state.
Former Nagios employee
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3600
Joined: Thu May 05, 2016 3:54 pm

Re: Getting Current State from JSON Query

Postby cdienger » Mon Mar 12, 2018 1:03 pm

Thanks for the assist, @mcapra!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
cdienger
Support Tech
 
Posts: 4238
Joined: Tue Feb 07, 2017 11:26 am

Re: Getting Current State from JSON Query

Postby grenley » Tue Mar 13, 2018 1:03 pm

Perfect! Thanks very much!
grenley
 
Posts: 95
Joined: Tue May 13, 2014 6:06 pm

Re: Getting Current State from JSON Query

Postby npolovenko » Tue Mar 13, 2018 4:23 pm

@grenley, Sounds like we are ready to lock this thread as resolved?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
npolovenko
Support Tech
 
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm


Return to Community Support

Who is online

Users browsing this forum: Google [Bot] and 42 guests