Can someone help whether my below rest paramaters are in correct format:
There's the REST tutorial on WayBackMachine of this page, which uses resty instead of nrcq, which is much closer to curl, which might help:
http://web.archive.org/web/201...
And also the example set up script still has all the curl commands for a sample setup:
https://github.com/mclarkson/n...
That will take a bit of deciphering but not huge amounts. However, If you uncomment the line near the top, '#curl() { :; }', then you can run the script without it changing anything or connecting to anything and it will show you all the curl commands that it would have run.
Lastly, is the REST reference page:
http://nagrestconf.smorg.co.uk...
Look for fields that should be encoded ('E' - The field should be URL encoded.), and you will need to url encode those fields, which is why I wrote nrcq - it does it for you. If you don't use any special characters anywhere then you could get by without url encoding. That page is worth a quick scan though.
However, you might want to try using nrcq to get to grips with the api first. The REST tutorial at http://nagrestconf.smorg.co.uk/documentation/resttut.php uses nrcq.
Cheers!
Mark
Thanks. Ended up getting it to work.
Wrote a method to handle all writing, the json being sent as a post variable kind of tricked me.
protected function post($commandarg, $post_data = array())
{
if($this->valid)
{
// build the urlencoded data
$postvars = http_build_query($post_data);
// open connection
$connection = curl_init();
// set the url, number of POST vars, POST data
curl_setopt($connection, CURLOPT_URL, $this->url . $commandarg);
curl_setopt($connection, CURLOPT_POST, count($post_data));
curl_setopt($connection, CURLOPT_POSTFIELDS, $postvars);
// execute post
$result = curl_exec($connection);
// close connection
curl_close($connection);
return $result;
}
return false;
}
From my other objects i build the json data like array("json" => $jsonData)
ending up with something like this.
$this->post("add/hosts",array("json" => $jsonData));
It is object oriented, (hence the $this-> )
Hope it might help others in similar situations.
----------------------- snip ----------------------
--
You received this message because you are subscribed to the Google Groups "nagrestconf-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nagrestconf-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1/rest/restart/nagios");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "json={\"folder\":\"local\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);