Page 1 of 1

Bulk Host Cloning and Import - Additional Fields

Posted: Tue Oct 23, 2018 8:19 pm
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

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Wed Oct 24, 2018 12:41 pm
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

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Wed Oct 24, 2018 3:44 pm
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.

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Wed Oct 31, 2018 4:50 pm
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

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Thu Nov 01, 2018 7:12 am
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!

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Fri Nov 02, 2018 5:07 pm
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

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Fri Nov 02, 2018 5:39 pm
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.

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Fri Nov 02, 2018 7:03 pm
by Maxwellb99
Ahh, reading is fundamental. Good catch & thanks for the clarification.

Cheers,
Max

Re: Bulk Host Cloning and Import - Additional Fields

Posted: Mon Nov 05, 2018 8:19 am
by scottwilkerson
Maxwellb99 wrote:Ahh, reading is fundamental. Good catch & thanks for the clarification.

Cheers,
Max
no problem