Compact status response for easy parsing

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Compact status response for easy parsing

Postby Pihtahcek » Wed Feb 15, 2017 10:09 am

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.
Pihtahcek
 
Posts: 2
Joined: Tue Feb 14, 2017 9:47 am

Re: Compact status response for easy parsing

Postby rkennedy » Wed Feb 15, 2017 10:56 am

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
    }
  }
}
rkennedy
 
Posts: 6562
Joined: Mon Oct 05, 2015 11:45 am

Re: Compact status response for easy parsing

Postby Pihtahcek » Thu Feb 16, 2017 1:05 am

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?
Pihtahcek
 
Posts: 2
Joined: Tue Feb 14, 2017 9:47 am

Re: Compact status response for easy parsing

Postby rkennedy » Thu Feb 16, 2017 10:19 am

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.
rkennedy
 
Posts: 6562
Joined: Mon Oct 05, 2015 11:45 am

Re: Compact status response for easy parsing

Postby tmcdonald » Wed Mar 01, 2017 2:28 pm

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?
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tmcdonald
Support Lead / Operations Engineer
 
Posts: 8698
Joined: Mon Sep 23, 2013 8:40 am


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 40 guests