Interact with Nagios Interface programatically

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Re: Interact with Nagios Interface programatically

Post by lb2cons »

WillemDH it's working now :D :D :D

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?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Interact with Nagios Interface programatically

Post 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
Nagios XI 5.8.1
https://outsideit.net
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Interact with Nagios Interface programatically

Post by tmcdonald »

Thanks @WillemDH! We'll keep this open for your contribution!
Former Nagios employee
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Interact with Nagios Interface programatically

Post 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.
Nagios XI 5.8.1
https://outsideit.net
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Interact with Nagios Interface programatically

Post 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 ;)
Former Nagios employee
lb2cons
Posts: 72
Joined: Mon Dec 08, 2014 4:11 pm

Re: Interact with Nagios Interface programatically

Post by lb2cons »

tmcdonald, you can close this thread now. Thanks again Willem!
Locked