Page 1 of 2

Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 8:35 am
by krobertson71
Had great success using the command line 'curl' to add hosts/services in mass.

What I would like to do is have a simple php page where a user could enter a host name and then all the baseline checks are implemented.

Just curious if anyone has tried this. I have poured over PHP Curl docs but they don't seem to fit what I am trying to do.

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 9:00 am
by BanditBBS
I've done it :)

I wrote it as a component with a crazy amount of coding. I can share, but it'd need cleaned up bad as it has my API key and other items hardcoded...you'd have to redo a bunch, but it'd be a start.

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 9:04 am
by krobertson71
That would be a great help. Thanks!

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 9:33 am
by BanditBBS
Attached! Good luck figuring out my hacked code :)

It adds to the menu on the left when you click "Configure" across the top menu. Advanced users can see it. At the bottom of the addl and addw files there are two different options for applying the changes remarked out, one gives a link and the other auto does it. I am having a service receive a passive check and alert me so I can manually apply changes when I want.

Edit #1 - I redacted URL and APIKey in all the files

Edit #2 - We are a hosting company, all customers have their own templates and stuff, you'll see the code that figures that all out, just wanted to explain that.

Edit #3 - You'll also see it sends a passive result to the same "Host Automation" service if for some reason an API call fails so that my team and figure the issue and get the host added

Edit #4 - Woot, my 2000th post!

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 9:53 am
by krobertson71
Great stuff!!

This will help a lot. I wasn't sure you could just echo the curl url with the post variables and have it work.. Bravo.

So just echo $result does the trick? Just making sure my above statement was correct...

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 9:57 am
by BanditBBS
I put the command within ` marks(same key as ~) assigning it to a variable, that runs the command. No echo was used except to actually echo text.

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 10:07 am
by krobertson71
Got ya. This is nice. Just need to chop some stuff out as we use NCPA, but this makes sense to me. GO ME!

Thanks for the help. Greatly appreciated!!!

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 11:33 am
by lmiltchev
Thanks for sharing, BanditBBS!

@krobertson71
Is it all right to lock this thread?

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 11:56 am
by WillemDH
Edit #4 - Woot, my 2000th post!
Congrats! :D

I'll have a look at your component too. Tx

Re: Nagios XI 5 - restapi php

Posted: Tue Mar 15, 2016 12:07 pm
by WillemDH
So I had a look at the component. It definitely is a nice starting point for more customization. Would be nice to see this in GitHub? :)