Page 1 of 1

Compact status response for easy parsing

Posted: Wed Feb 15, 2017 10:09 am
by Pihtahcek
Good day.
We'd like to make a mobile app that would push notifications every time there is a problem on a certain server, with personal customizations for every person responsible for certain services on these servers..
So i'd like to make an API that would check for errors on certain servers every amount of time.
I'm trying to parse the status of our servers by sending HTTP GET requests to the status.cgi.

The problem is that it returns loads of html, with many nested tables, which is not even valid xml, so i'd have to write my own parser for it.

Is there a way to get a more concise status output for each server and its array of check tasks, so it would make my life easier parsing it?

Thank you in advance.

Re: Compact status response for easy parsing

Posted: Wed Feb 15, 2017 10:56 am
by rkennedy
We'd like to make a mobile app that would push notifications every time there is a problem on a certain server, with personal customizations for every person responsible for certain services on these servers..
So i'd like to make an API that would check for errors on certain servers every amount of time.
This sounds a bit redundant since you're already using Nagios. Why not hook into event handlers / notification handlers / parsing the nagios.log so you can have instant push notifications? Just my two cents.

I do see the advantage of polling on your own though, but with this day in age every second counts for "live" notifications. In Core4, there is JSON output available for the statuses that I believe are what you're looking for. Take a look at this link - http://x/nagios/jsonquery.html

I used it to generate - http://x/nagios/cgi-bin/statusjson.cgi? ... =localhost -

Code: Select all

{
  "format_version": 0,
  "result": {
    "query_time": 1487174141000,
    "cgi": "statusjson.cgi",
    "user": "nagiosadmin",
    "query": "host",
    "query_status": "released",
    "program_start": 1487025268000,
    "last_data_update": 1487174137000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "host": {
      "name": "localhost",
      "name": "localhost",
      "plugin_output": "OK - 127.0.0.1: rta 0.013ms, lost 0%",
      "long_plugin_output": "",
      "perf_data": "rta=0.013ms;3000.000;5000.000;0; pl=0%;80;100;; rtmax=0.044ms;;;; rtmin=0.004ms;;;;",
      "status": 2,
      "last_update": 1487174137000,
      "has_been_checked": true,
      "should_be_scheduled": true,
      "current_attempt": 1,
      "max_attempts": 10,
      "last_check": 1487174046000,
      "next_check": 1487174346000,
      "check_options": 0,
      "check_type": 0,
      "last_state_change": 1486743300000,
      "last_hard_state_change": 1486743300000,
      "last_hard_state": 0,
      "last_time_up": 1487174046000,
      "last_time_down": 0,
      "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.00,
      "latency": 0.00,
      "execution_time": 0.00,
      "scheduled_downtime_depth": 0,
      "process_performance_data": true,
      "obsess": true
    }
  }
}

Re: Compact status response for easy parsing

Posted: Thu Feb 16, 2017 1:05 am
by Pihtahcek
We're using core 3.2.3, and afaik the json cgis are available starting with 4.0.7.

I will look into the nagios logs, thank you for this idea, but i've also seen some attempts at parsing the status.dat file, which contains all the info.
Is this a viable solution to my problem?

Re: Compact status response for easy parsing

Posted: Thu Feb 16, 2017 10:19 am
by rkennedy
Pihtahcek wrote:We're using core 3.2.3, and afaik the json cgis are available starting with 4.0.7.

I will look into the nagios logs, thank you for this idea, but i've also seen some attempts at parsing the status.dat file, which contains all the info.
Is this a viable solution to my problem?
Yeah, a lot of third party applications end up parsing through status.dat to gain the metrics they're after. This will have all of the information available. You are correct - the JSON started with 4.0.7 so what I mentioned would require an upgrade.

Re: Compact status response for easy parsing

Posted: Wed Mar 01, 2017 2:28 pm
by tmcdonald
Just checking in since we have not heard from you in a while. Did @rkennedy's post clear things up or has the issue otherwise been resolved?