If you don't mind JSON, the JSON Query Generator is probably good for this:
http://<your_nagios_host>/nagios/jsonquery.html
In action, to get the status of the HTTP service on localhost:
Code: Select all
[root@xi-stable scheduledbackups]# curl -XGET 'http://nagiosadmin:[email protected]/nagios/cgi-bin/statusjson.cgi?query=service&hostname=localhost&servicedescription=HTTP'
{
"format_version": 0,
"result": {
"query_time": 1485210998000,
"cgi": "statusjson.cgi",
"user": "nagiosadmin",
"query": "service",
"query_status": "released",
"program_start": 1484945781000,
"last_data_update": 1485210990000,
"type_code": 0,
"type_text": "Success",
"message": ""
},
"data": {
"service": {
"host_name": "localhost",
"description": "HTTP",
"host_name": "localhost",
"description": "HTTP",
"plugin_output": "HTTP OK: HTTP/1.1 200 OK - 3302 bytes in 0.001 second response time",
"long_plugin_output": "",
"perf_data": "time=0.000647s;;;0.000000 size=3302B;;;0",
"max_attempts": 4,
"current_attempt": 1,
"status": 2,
"last_update": 1485210990000,
"has_been_checked": true,
"should_be_scheduled": true,
"last_check": 1485210723000,
"check_options": 0,
"check_type": 0,
"checks_enabled": true,
"last_state_change": 1483717750000,
"last_hard_state_change": 1483717750000,
"last_hard_state": 0,
"last_time_ok": 1485210723000,
"last_time_warning": 0,
"last_time_unknown": 0,
"last_time_critical": 0,
"state_type": 1,
"last_notification": 0,
"next_notification": 0,
"next_check": 1485211023000,
"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,
"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
}
}
}
Note that the "status" field follows slightly different conventions than regular old plugin output codes (0=OK, 1=WARNING, etc).