Page 2 of 2
Re: Interact with Nagios Interface programatically
Posted: Mon Sep 14, 2015 10:20 am
by lb2cons
WillemDH it's working now
The problem is I don't know why. Maybe some parameter was incorrect, I didn't change any code.
I've noticed that the script doesn't provide a validation for the service name. Maybe I could help you with that.
Another question, how are you using this with Windows? I need a cross platform of this automation. I'm thinking about develop this same script in Python what do you think?
Re: Interact with Nagios Interface programatically
Posted: Mon Sep 14, 2015 10:28 am
by WillemDH
Hey lb2cons,
Very nice you got it working. Once you put it in Nagios Reactor, you can use Powershell for that on Windows Servers. There should be no need to use Python for that imho. I'm at home now, but I'll post an example of how to use it with Powershell tomorrow. If you are not using Nagios Reactor yet, give it a try, you will like it (it's free) and will help you automating a lot of stuff.
If you want to try make the script better, feel free to submit a pull request.
Grtz
Willem
Re: Interact with Nagios Interface programatically
Posted: Mon Sep 14, 2015 4:48 pm
by tmcdonald
Thanks
@WillemDH! We'll keep this open for your contribution!
Re: Interact with Nagios Interface programatically
Posted: Tue Sep 15, 2015 5:24 am
by WillemDH
Well apparently I posted the examples in the wrong thread. Sorry fo that.. you can find them here:
https://support.nagios.com/forum/viewto ... 5&start=10
Example 01: Bash curl
Code: Select all
curl --data 'api_key=cb7262269da487e256d1blabla8269142' --data 'hostname=servername' --data 'version=0.4.1.105' --data 'type=legacy' http://reactorserver/nagiosreactor/index.php/api/eventchain/143/run
Example 02: Powershell v2
Code: Select all
$webc = New-Object net.WebClient
$param = New-Object system.Collections.Specialized.NameValueCollection
$param.Add('api_key', '640b1f5cblabzkdnapzjdpojadpojdazpoj1809')
$param.Add('hostname', 'servername')
$param.Add('software', 'NSClient')
$param.Add('version', '0.4.1.105')
$param.Add('type', 'legacy')
$ba = $webc.UploadValues('http://reactorserver/nagiosreactor/index.php/api/eventchain/143/run', 'POST', $param)
$xml = [xml]([char[]]$ba -join '')
Example 02: Powershell v3
Code: Select all
$postParams = @{api_key='zdjazpodjapojdoazjdaojzd8269142';hostname='servername';version= '0.4.1.105';type= 'legacy'}
Invoke-WebRequest -Uri http://reactorserver/nagiosreactor/index.php/api/eventchain/143/run -Method POST -Body $postParams
So once you create a chain, you can re-use it from anywhere.
Re: Interact with Nagios Interface programatically
Posted: Tue Sep 15, 2015 9:36 am
by tmcdonald
Thanks for the post, Willem!
lb2cons, let us know how Willem's PS script works out for you. For the sake of organization, once everything is working for you and all the loose ends are tied up, I would like to close up this thread.
Also, you might like some of the new features in XI 5 ;)
Re: Interact with Nagios Interface programatically
Posted: Tue Sep 15, 2015 11:07 am
by lb2cons
tmcdonald, you can close this thread now. Thanks again Willem!