Page 1 of 1

How to POST http request from external HTTserver to NagiosXI

Posted: Tue Jun 06, 2017 4:25 am
by network2016
Hi

I want to add device into Nagios using HTTP POST call from HTTP server . THe client at Http server should call the POST and NAgios should store it in database just same as it do in case of SNMP discovery and return some achknowledgemet to client.

Any help would be appriciated.

Regards

Re: How to POST http request from external HTTserver to Nagi

Posted: Tue Jun 06, 2017 8:48 am
by mcapra
The verbose output for check_http (via the -v flag) can display a full JSON response:

Code: Select all

[root@nagios ~]# /usr/local/nagios/libexec/check_http -H esdev00 --method=GET -t 3 -p 9200 -v
GET / HTTP/1.1
User-Agent: check_http/v2.2.1.git (nagios-plugins 2.2.1)
Connection: close
Host: esdev00:9200
Accept: */*
content-type:application/json


http://esdev00:9200/ is 416 characters
STATUS: HTTP/1.1 200 OK
**** HEADER ****
Content-Type: application/json; charset=UTF-8
Content-Length: 329
**** CONTENT ****
{
  "status" : 200,
  "name" : "esdev00",
  "cluster_name" : "esdev",
  "tagline" : "You Know, for Search"
}

HTTP OK: HTTP/1.1 200 OK - 416 bytes in 0.005 second response time |time=0.004709s;;;0.000000 size=416B;;;0
And similarly if you wanted to make a POST request and provide some data (be mindful of escaping for the CLI, bash in this case):

Code: Select all

[root@nagios ~]# /usr/local/nagios/libexec/check_http -H esdev00 -u /hits/_search?size=1 --method=POST --post="{\"query\":{\"term\":{\"browser\":\"Chrome\"}}}" -t 3  -p 9200 -v
POST /hits/_search?size=1 HTTP/1.1
User-Agent: check_http/v2.2.1.git (nagios-plugins 2.2.1)
Connection: close
Host: esdev00:9200
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 39

{"query":{"term":{"browser":"Chrome"}}}

http://esdev00:9200/hits/_search?size=1 is 1673 characters
STATUS: HTTP/1.1 200 OK
**** HEADER ****
Content-Type: application/json; charset=UTF-8
Content-Length: 1585
**** CONTENT ****
{"took":74,"timed_out":false,"_shards":{"total":4,"successful":4,"failed":0},"hits":{"total":7374340,"max_score":1.54193,"hits":[{"_index":"hits","_type":"request","_id":"AVx4vLqKZ501FTCJdzXW","_score":1.54193,"_source":{"appServer":"dev01",}}]}}
HTTP OK: HTTP/1.1 200 OK - 1673 bytes in 0.080 second response time |time=0.080303s;;;0.000000 size=1673B;;;0
I'm not sure what you mean by "store it in the database", but practically any and all status output from Nagios plugins makes it's way into the nagios database for the duration of that check's validity.

Re: How to POST http request from external HTTserver to Nagi

Posted: Tue Jun 06, 2017 12:44 pm
by avandemore
I too am unclear as to your exact request. Perhaps you are inquiring about the API? You can find that information in XI > Help > REST API Docs. We also have this document:

https://assets.nagios.com/downloads/nag ... gement.pdf

Re: How to POST http request from external HTTserver to Nagi

Posted: Wed Jun 21, 2017 1:33 pm
by tmcdonald
Just checking in since we have not heard from you in a while. Did @avandemore's post clear things up or has the issue otherwise been resolved?

Re: How to POST http request from external HTTserver to Nagi

Posted: Wed Aug 16, 2017 1:45 am
by network2016
SORRY FOR NOT REPLYING IN A WHILE
PLEASE CLOSE THIS THREAD ,IT HAS BEEN RESOLVED.

THANKS

Re: How to POST http request from external HTTserver to Nagi

Posted: Wed Aug 16, 2017 10:35 am
by scottwilkerson
No problem. Let us know if you have any other issues.