Bulk Host Cloning and Import - Additional Fields

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
jaimie.livingston
Posts: 59
Joined: Wed Nov 23, 2016 10:41 am

Bulk Host Cloning and Import - Additional Fields

Post by jaimie.livingston »

For large organizations with thousands of hosts, it would be really useful to have the ability to use the Bulk Host Cloning and Import wizard (or something like it) to populate/override any object field, including existing free variable values.

At the very least, being able to populate the host description, notes, notes url, and action url fields would streamline systems support operations.

Thanks

Jaimie Livingston
jaimie.livingston
Posts: 59
Joined: Wed Nov 23, 2016 10:41 am

Re: Bulk Host Cloning and Import - Additional Fields

Post by jaimie.livingston »

I took some time and hacked together the attached PHP applet to replace the stock bulkhostimport.inc.php applet.
It's working well in my test environment.

This hack adds additional fields, including one free variable used to store an Amazon Instance ID that I use with the check_ec2 plugin.
Host Object Attributes that can be imported are:
host_name
address
alias
display_name
notes
notes_url
action_url
hostgroup
parenthost
_amazonid

There are probably opportunities for QA and some Polish.
Use at your own risk. Your Mileage May Vary.
This code is provided as an example only.
I take no responsibility for any harm that occurs from using this code.
Anyone reading this who cannot figure out how to use this text file to replace the stock bulkhostimport.inc.php applet probably shouldn't be making the attempt. Seriously. Wait for a packaged version from the good folks at Nagios.

Have Fun!

Jaimie L
Attachments
bulkhostimport_inc_php.txt
Alternate Code for Stock Bulk Clone & Import PHP
(41.99 KiB) Downloaded 278 times
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bulk Host Cloning and Import - Additional Fields

Post by scottwilkerson »

Thanks for sharing your findings.

There are already some feature requests for some additional fields, but I do not see any easy way to add free variables as there are unlimited possibilities.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jaimie.livingston
Posts: 59
Joined: Wed Nov 23, 2016 10:41 am

Re: Bulk Host Cloning and Import - Additional Fields

Post by jaimie.livingston »

Here's a suggestion, should anyone want to pursue it...

Provide a field that will parse the FV name and associated value as a delimited pair. Basically, a parsable 2 value array, inside of the imported csv. You would have to limit the number of allowed free variables, though.

For example:
Field Name = FreeVariable1
Field Value in CSV = "fv_name=fv_value"

It's beyond what I want to code, but I'm sure there is a PHP wizard somewhere up to the task. ;-)

Happy Coding!

~jaimie
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bulk Host Cloning and Import - Additional Fields

Post by scottwilkerson »

jaimie.livingston wrote:Here's a suggestion, should anyone want to pursue it...

Provide a field that will parse the FV name and associated value as a delimited pair. Basically, a parsable 2 value array, inside of the imported csv. You would have to limit the number of allowed free variables, though.

For example:
Field Name = FreeVariable1
Field Value in CSV = "fv_name=fv_value"

It's beyond what I want to code, but I'm sure there is a PHP wizard somewhere up to the task. ;-)

Happy Coding!

~jaimie
Thanks for the suggestion!
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Maxwellb99
Posts: 96
Joined: Tue Jan 26, 2016 5:29 pm

Re: Bulk Host Cloning and Import - Additional Fields

Post by Maxwellb99 »

Good Afternoon,

Please let me know if i'm missing something, but you're looking for the ability to add free variables to existing hosts? Or change variables within an existing nagios_host_object?

@Nagios please correct me if I'm wrong: A host is uniquely identified via its host_name similarly for a service being uniquely defined by the host & service_description? When I Post via the API the object ID stays the same as long as the unique keys of each Nagios object stay the same?

As long as Nagios confirms what I said holds, you can make these changes via the API. Because any legal variable is allowed in the API, for that object. Pass in the "_free_variable_key": "free_variable_value" free variable. Then, loop through your hosts with whatever host_object parameters you want to Post. Finally, apply the config & the hosts should change.

I wrote an example in this thread, using python.
https://support.nagios.com/forum/viewto ... 16&t=50687

Similar warnings/caveats as jamie.livingston. if you want different stuff/multiple hosts read in the csv's from the csv lib then loop through the hosts.

Thanks,
Maxwell Ramirez
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bulk Host Cloning and Import - Additional Fields

Post by scottwilkerson »

Maxwellb99 wrote:Good Afternoon,

Please let me know if i'm missing something, but you're looking for the ability to add free variables to existing hosts? Or change variables within an existing nagios_host_object?

@Nagios please correct me if I'm wrong: A host is uniquely identified via its host_name similarly for a service being uniquely defined by the host & service_description? When I Post via the API the object ID stays the same as long as the unique keys of each Nagios object stay the same?

As long as Nagios confirms what I said holds, you can make these changes via the API. Because any legal variable is allowed in the API, for that object. Pass in the "_free_variable_key": "free_variable_value" free variable. Then, loop through your hosts with whatever host_object parameters you want to Post. Finally, apply the config & the hosts should change.

I wrote an example in this thread, using python.
https://support.nagios.com/forum/viewto ... 16&t=50687

Similar warnings/caveats as jamie.livingston. if you want different stuff/multiple hosts read in the csv's from the csv lib then loop through the hosts.

Thanks,
Maxwell Ramirez
This would work after the fact or if you were just creating the hosts through the API, but I believe the OP is looking to add the variables to the new host at the time of creation using the Bulk Host Cloning and Import wizard.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Maxwellb99
Posts: 96
Joined: Tue Jan 26, 2016 5:29 pm

Re: Bulk Host Cloning and Import - Additional Fields

Post by Maxwellb99 »

Ahh, reading is fundamental. Good catch & thanks for the clarification.

Cheers,
Max
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bulk Host Cloning and Import - Additional Fields

Post by scottwilkerson »

Maxwellb99 wrote:Ahh, reading is fundamental. Good catch & thanks for the clarification.

Cheers,
Max
no problem
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked