Page 1 of 1

Scripting host config updates using CMDB CI Parent Info

Posted: Thu Apr 21, 2016 6:05 pm
by awilson
Hello. I have searched the forum and Nagios documentation and I haven''t found an explanation for how to update host configuration information. If it is already covered, please point out the topic or docs.

We are running Nagios XI 5.2.7 on Red Hat Enterprise 6.7; Gnome is not installed; PHP 5.3.3; No Proxy; API v1;

We want to leverage Nagios XI's ability to suppress downstream/sympathetic (I think you call them upstream) alerts using the "parents" feature. Our parent/child relationship information is in our CMDB. We want to insert the parents directive into the host configuration for each CI managed with Nagios.

Are there recommendations that are consistent with Nagios XI's internal processing methods? Looking at the API, it appears that we should iterate with:
  • GET the host config (back it up)
    DELETE the host config
    POST the updated host config
    clean up
Is that the way it is done?
Or can we do the updates in the nagios MySQL database?

There are tables in the nagios database instance in the MySQL database that appear to contain variables/fields that would hold that information. Does Nagios XI process host information from the MySQL data or does it use the host config files in ../nagios/etc/hosts? Why do both of them exist?

Thanks!
Alan

Re: Scripting host config updates using CMDB CI Parent Info

Posted: Thu Apr 21, 2016 7:37 pm
by Box293
awilson wrote:There are tables in the nagios database instance in the MySQL database that appear to contain variables/fields that would hold that information. Does Nagios XI process host information from the MySQL data or does it use the host config files in ../nagios/etc/hosts? Why do both of them exist?
The database is where the CCM objects live. It's a staging area. When you "Apply Configuration", the flat config files in /usr/local/nagios/etc/ are updated and Nagios Core is restarted. Nagios Core reads the flat config files, it has no knowledge of the database.
awilson wrote:Or can we do the updates in the nagios MySQL database?
Direct manipulation of the database is not supported, it can lead to problems.
awilson wrote:Are there recommendations that are consistent with Nagios XI's internal processing methods? Looking at the API, it appears that we should iterate with:

GET the host config (back it up)
DELETE the host config
POST the updated host config
clean up
From testing I've done, you don't need to delete the object, you can just post an updated object and it gets updated. However it does not remove directives from the objects.

Some directives are mandatory, however when using templates you might not want to define some directives. You need to use &force=1 to allow that.

Code: Select all

curl -k -XPOST "https://xitest.box293.local/nagiosxi/api/v1/config/host?apikey=5goacg8s&pretty=1" -d "host_name=my_test_host&address=127.0.0.1&use=linux-server&force=1&applyconfig=1"
Does this help?

Re: Scripting host config updates using CMDB CI Parent Info

Posted: Fri Apr 22, 2016 9:51 am
by SteveBeauchemin
Wow - yes, it helps me... I use templates quite a bit. Having mandatory parameters was the only thing stopping me from using the API. Now that I know about the 'force' directive, I'm going to start development that makes user of that.

Sorry to jump on the post - but the information you provided struck a chord with me. Awesome.

Thanks.

Steve B

Re: Scripting host config updates using CMDB CI Parent Info

Posted: Fri Apr 22, 2016 1:23 pm
by awilson
Yes. This was very helpful. Thank you for the rapid reply!

Alan

Re: Scripting host config updates using CMDB CI Parent Info

Posted: Fri Apr 22, 2016 1:52 pm
by tmcdonald
@awilson was there anything else you needed clarification for? Or can we close this up?

Re: Scripting host config updates using CMDB CI Parent Info

Posted: Tue Apr 26, 2016 4:43 pm
by awilson
We can close it.

Thx!