Page 2 of 2

Re: Connecting to Nagios API via a Website

Posted: Tue Jul 19, 2016 11:24 am
by mcapra
The API is configured to adhere to the Same-origin Policy, which is what I think is happening here. Javascript/jQuery probably won't be of much help without making changes to the API in your Core installation (not recommended).

I was able to write a simple PHP script that accomplished what the previous jQuery function did (192.168.3.87 is a separate machine from where this script was run):

Code: Select all

<?php
$url = 'http://nagiosadmin:[email protected]/nagios/cgi-bin/objectjson.cgi?query=hostlist&parenthost=none&childhost=none';
$obj = json_decode(file_get_contents($url), true);

print_r($obj);
?>
Which returns the following and stores it in $obj:

Code: Select all

Array ( [format_version] => 0 [result] => Array ( [query_time] => 1468945372000 [cgi] => objectjson.cgi [user] => nagiosadmin [query] => hostlist [query_status] => released [program_start] => 1468867888000 [last_data_update] => 1468867888000 [type_code] => 0 [type_text] => Success [message] => ) [data] => Array ( [selectors] => Array ( [parenthost] => none [childhost] => none ) [hostlist] => Array ( [0] => localhost ) ) )
My [hostlist] on this Core installation is a bit boring and only contains localhost. There's probably options for just about every language. file_get_contents isn't doing anything terribly special.

Re: Connecting to Nagios API via a Website

Posted: Wed Jul 20, 2016 1:21 am
by Zeedinstein
Hi thank you so much for the help it work and I'm receiving the correct information!

Re: Connecting to Nagios API via a Website

Posted: Wed Jul 20, 2016 9:36 am
by mcapra
Good news then! Is it alright if we lock this thread and mark the issue as resolved?