Nagios Subinstances 2

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Re: Nagios Subinstances 2

Post by tariqondego »

I mean the status of ATM,which the customer will want to see.This would require me to use NSCA at my nagios server for it to forward this information to customerhost.And NSCA takes input as text file.

How would I pull this information from my nagios server and give it to NSCA?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios Subinstances 2

Post by tmcdonald »

I think I know what you mean now. Something like this will help query status info from the CLI in Core 4+:

Code: Select all

QUERY_STRING="host=all&servicestatustypes=28" REMOTE_USER="nagiosadmin" /usr/local/nagios/sbin/status-json.cgi
Reference page: http://roshamboot.org/main/guide-nagios-statuscgi/

Then it is just a matter or parsing the JSON and calling send_nsca with the required values. You do not need to use a text file for send_nsca - standard input will work just fine.
Former Nagios employee
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Re: Nagios Subinstances 2

Post by tariqondego »

Thanks,atleast now we are on the same page.This information has helped alot.
So lets say i pass this to send_nsca.Wouldnt this be received as html on the command file of the recepient machine?
Assuming its written to the command file,would nagios be able to read this information correctly?

Please advise.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios Subinstances 2

Post by tmcdonald »

Not as HTML, but as JSON which is very easy to parse using just about any language, especially if there is a library or module for JSON. Running the command I posted will only display data, it does not write anything to the command file. Your script will need to parse the JSON and write it in the proper format to the command file.
Former Nagios employee
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Re: Nagios Subinstances 2

Post by tariqondego »

When I type the below command

Code: Select all

REQUEST_METHOD="GET" QUERY_STRING="host=NIC0002&servicestatustypes=2" REMOTE_USER="paynet" /usr/local/nagios/sbin/statusjson.cgi > test2
I suppose I should get OK services for Host NIC002.

Instead what i get is syntax of json format,see file attached.

Please advise.
Attachments
statusjson.docx
(30.07 KiB) Downloaded 134 times
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Subinstances 2

Post by abrist »

Your syntax is incorrect, but really close. Try:

Code: Select all

REQUEST_METHOD="GET" QUERY_STRING="query=servicelist&details=true&hostname=NIC0002&servicestatus=critical" REMOTE_USER="paynet" /usr/local/nagios/sbin/statusjson.cgi
Note: I added "details=true", this is not necessary, but nice to have for verbosity while you are troubleshooting the query.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
tariqondego
Posts: 85
Joined: Fri Mar 28, 2014 6:18 am

Re: Nagios Subinstances 2

Post by tariqondego »

Tried that,this is the output that i got:

Code: Select all

Cache-Control: no-store
Pragma: no-cache
Last-Modified: Wed, 10 Sep 2014 10:26:49 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-type: application/json; charset=utf-8

{
  "format_version": 0,
  "result": {
    "query_time": 1410344809000,
    "cgi": "statusjson.cgi",
    "user": "paynet",
    "query": "servicelist",
    "query_status": "beta",
    "program_start": 1410334154000,
    "last_data_update": 1410344808000,
    "type_code": 0,
    "type_text": "Success",
    "message": ""
  },
  "data": {
    "selectors": {
      "service_status": 16
    },
    "servicelist": {
    }
  }
}
Please advise.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Subinstances 2

Post by abrist »

Actually, I get that too. The query works fine from the jsonquery.html utility page, through ajax, and through curl:

Code: Select all

curl -k "http://<user>:<pass>@localhost/nagios/cgi-bin/statusjson.cgi?query=servicelist&hostname=<hostname>"  
This could be a limitation of calling the cgi directly, or it could be an issue with specific queries as the following works correctly on my box:

Code: Select all

REQUEST_METHOD="GET" QUERY_STRING="query=host&hostname=<hostname>" REMOTE_USER="nagiosamdin" /usr/local/nagios/sbin/statusjson.cgi
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked