Automating parent child relationship creation - NOT manually

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
toneill2000
Posts: 29
Joined: Sun Jan 14, 2018 12:56 pm
Location: Madison, WI

Automating parent child relationship creation - NOT manually

Post by toneill2000 »

For Nagios XI version 5.4.8 or 5.4.11, is there a way to automate the creation of a parent child relationship instead of having to manually do this and then apply in the UI? I have thousands of relationships I want to create, I need to find the least manual approach to accomplish this. E.g., I would prefer to write a script to send requests to establish relationships.

I don't see this functionality available in the REST API - at least not in the documentation. It looks like perhaps it would be an option to insert records directly in the MySQL DB or develop a custom API endpoint integration.

Does anyone have an idea on what the best practice would be? Thanks in advance.
Todd

p.s., I originally posted this under Nagios Core accidentally. Thus I'm reposting here.

MOD NOTE: link to original: https://support.nagios.com/forum/viewto ... 999#bottom
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by dwhitfield »

There is currently no way to not have to apply. You can have the apply work programmatically though. At this time, I cannot say when Core 5 will make it into XI. I am hoping XI 6.0, but that decision has not been made yet.

The API is getting a big facelift in XI 5.5, but we do not have a release date for that yet.

Did you see
** All normal host directives are able to be used like normal core config definition files.
in the standard documentation? Regardless, yes, http://YOURSERVER/nagiosxi/help/custom- ... points.php is an option. Were you having issues with custom endpoints, or just wondering if that was the best way to go?
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by eloyd »

Write a script to create your relationships, drop it in the import directory, and then import them.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by dwhitfield »

@toneill2000, does @eloyd's suggestion work for you?
toneill2000
Posts: 29
Joined: Sun Jan 14, 2018 12:56 pm
Location: Madison, WI

Re: Automating parent child relationship creation - NOT manu

Post by toneill2000 »

[user]@dwhitfield[/user], [user]@eloyd[/user], thank you both for your time.

To clarify a bit, we have thousands of objects already loaded into Nagios XI. The problem is the relationships don't exist for many of them. Over time, our objects and their relationships will continually evolve. I'm wanting to automate, as much as possible, the parent-child relationships in a solution that does NOT need someone to go into the UI and manually associate the objects and they apply the change on a regular basis.

IDEAL SOLUTION - If I could blue sky my solution, here are my thoughts:
I can capture (e.g., in a csv file or some external source) the object names and their relationship to other objects. Therefore, my ideal solution would be for me to write some script (Java, PHP, Perl, or whatever), that can run on a scheduled bases, where the script would traverse through a refreshed version of my csv file (which holds all my objects and relationships). It would then call Nagios' API and ask -- Does this relationship already exists? If yes, do nothing. If no, make another API call to Nagios and tell it to add the relationship and then have that "add" be committed without having a user be involved at all. Then, move onto the next record in the file until EOF.

I'm new to Nagios so my solution above might not match how Nagios operates for this requirement.
dwhitfield wrote:Were you having issues with custom endpoints, or just wondering if that was the best way to go?
[user]@dwhitfield[/user], I'm a long time programmer but I have not yet created custom endpoints in Nagios. Yes, I'm looking for the best approach as I want to build this correctly the first time. Would you suggest a custom endpoint based on my description above? Thanks.
eloyd wrote:Write a script to create your relationships, drop it in the import directory, and then import them.
[user]@eloyd[/user], I believe you are referring to the Admin->Import Config Files option - correct? I looked at that too and it seems like it's intended to import objects that don't already exist. Since all my objects exists, I only want to add the relationship. Can I import config files for hosts and only include the "parent" directive and it's smart enough to update and existing object by adding a parent? The only trouble here is that the import is manual so I need a person sitting at the UI on a regular basis running the import process after my script created new cfg files. Let me know if I'm off base here. Thanks for reply.
toneill2000
Posts: 29
Joined: Sun Jan 14, 2018 12:56 pm
Location: Madison, WI

Re: Automating parent child relationship creation - NOT manu

Post by toneill2000 »

I should also clarify that our goal with all of what I'm describing is to suppress the extra notifications based on status of related objects, such has hosts. Therefore, I want dependencies (which I thought was a parent, child) between multiple objects. Again, I want the full automation that I've described above for creating these relationships but perhaps a "dependency" relationship is more fitting than parent-child.

I see there is documentation for Host and Service dependencies here: https://assets.nagios.com/downloads/nag ... ncies.html

I still need ideas on how to get to my "ideal" state whether I go with parent-child or dependencies. Any suggestions are welcome and thanks in advance.
Todd
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by eloyd »

Pretty sure automatic importing is what you're looking for. It can all be done through host automation. Check out this document:

https://assets.nagios.com/downloads/nag ... gement.pdf
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by dwhitfield »

@toneill2000, did @eloyd's suggestion work for you?
toneill2000
Posts: 29
Joined: Sun Jan 14, 2018 12:56 pm
Location: Madison, WI

Re: Automating parent child relationship creation - NOT manu

Post by toneill2000 »

eloyd wrote:Pretty sure automatic importing is what you're looking for. It can all be done through host automation. Check out this document:

https://assets.nagios.com/downloads/nag ... gement.pdf
@eloyd - the document you provided does meet some of my needs. That is, I can create hosts and services via the REST API tools and then schedule that (e.g., with CRON) to regularly do that. I even tested that I can send a request to create a host (even if it already exists) and only include the new "parents" element to add parents. It will then update an existing object in Nagios and add the parents.

The part I'm still not able to do is to delete parents for a given host. I can delete the entire host first and then recreate it - less the parents - which would do a delete parent operation for me but then I've essentially wiped all history of the host and need to re-establish the everything about that host. Is there a way to remove parents in a more straight forward process?

Additionally, this REST API doesn't allow for adding host dependencies. There doesn't seem to be any support for that except importing cfg files - but then I'm back to having some manual intervention from what I understand of that process. Thanks in advance for your help on this.
Todd
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Automating parent child relationship creation - NOT manu

Post by eloyd »

You can "cheat" with regards to parent. Set the parent host to be localhost and that effectively means nothing. Localhost will always be reachable to Nagios or else Nagios isn't running. In which case, localhost won't be reachable but neither will anything else. So you can essentially set "parents=localhost" to clear out any existing parent relationship that you have.

As for host dependencies, we've never used them. Parents are almost always what you want instead of host dependencies. However, if you really do need dependencies, you can use the same logic for creating/destroying host dependencies in the import configs as well.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
Locked