Scripting host config updates using CMDB CI Parent Info

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Scripting host config updates using CMDB CI Parent Info

Post 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
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Scripting host config updates using CMDB CI Parent Info

Post 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?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
SteveBeauchemin
Posts: 524
Joined: Mon Oct 14, 2013 7:19 pm

Re: Scripting host config updates using CMDB CI Parent Info

Post 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
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Scripting host config updates using CMDB CI Parent Info

Post by awilson »

Yes. This was very helpful. Thank you for the rapid reply!

Alan
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Scripting host config updates using CMDB CI Parent Info

Post by tmcdonald »

@awilson was there anything else you needed clarification for? Or can we close this up?
Former Nagios employee
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Scripting host config updates using CMDB CI Parent Info

Post by awilson »

We can close it.

Thx!
Locked