Nagios XI 5 - restapi php

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
krobertson71
Posts: 444
Joined: Tue Feb 11, 2014 10:16 pm

Nagios XI 5 - restapi php

Post 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.
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios XI 5 - restapi php

Post 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.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
krobertson71
Posts: 444
Joined: Tue Feb 11, 2014 10:16 pm

Re: Nagios XI 5 - restapi php

Post by krobertson71 »

That would be a great help. Thanks!
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios XI 5 - restapi php

Post 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!
You do not have the required permissions to view the files attached to this post.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
krobertson71
Posts: 444
Joined: Tue Feb 11, 2014 10:16 pm

Re: Nagios XI 5 - restapi php

Post 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...
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: Nagios XI 5 - restapi php

Post 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.
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
krobertson71
Posts: 444
Joined: Tue Feb 11, 2014 10:16 pm

Re: Nagios XI 5 - restapi php

Post 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!!!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios XI 5 - restapi php

Post by lmiltchev »

Thanks for sharing, BanditBBS!

@krobertson71
Is it all right to lock this thread?
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Nagios XI 5 - restapi php

Post by WillemDH »

Edit #4 - Woot, my 2000th post!
Congrats! :D

I'll have a look at your component too. Tx
Nagios XI 5.8.1
https://outsideit.net
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Nagios XI 5 - restapi php

Post 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? :)
Nagios XI 5.8.1
https://outsideit.net
Locked