hello,
I thought I read it somewhere that it is now an option to do so in CCM but cant find it, my Nagios XI ver 5.4.3
Or do I have to build configuration files, then import them back into XI?
Bulk HostGoup Cloning
-
avandemore
- Posts: 1597
- Joined: Tue Sep 27, 2016 4:57 pm
Re: Bulk HostGoup Cloning
What is it you are trying to do exactly? You can simply copy a host group in the CCM if that is what you are trying to do.
Previous Nagios employee
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Bulk HostGoup Cloning
That is pretty much what I'm looking for... so where in CCM I can copy and create 50+ new ones based off existing one?
Re: Bulk HostGoup Cloning
I don't believe we have a GUI tool that would clone hostgroup multiple times, however you could accomplish this by running some commnads/scripts from the CLI. You could create your configs via some kind a scripting solution in the "/usr/local/nagios/etc/import" directory, and then run:
Note: You need to make sure that the configs, dropped in the "import" directory are valid (there are no config errors).
Another way (preferred) would be to use the new REST API in Nagios XI. You can run multiple commands ( i.e. via copy/paste or by placing them in a bash script) to add bunch of hostgroups.
Here's an example of adding 3 hostgroups from the command line via the REST API (HG1, HG2, and HG3). All 3 hostgorups have only one member - localhost. In your case, you could have multiple, comma separated members.
Note: Notice that I used "&applyconfig=1" only in the last command. I would recommend trying this out with just a few hosgroups first to see how it is done (before trying to create 50 hosgroups in bulk). To view the command that you need to use, go to the Help menu in Nagios XI, click on "Config Reference" on the left, then click on "POST config/hostgroup" link on the right.
Hope this helps.
Code: Select all
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.shAnother way (preferred) would be to use the new REST API in Nagios XI. You can run multiple commands ( i.e. via copy/paste or by placing them in a bash script) to add bunch of hostgroups.
Here's an example of adding 3 hostgroups from the command line via the REST API (HG1, HG2, and HG3). All 3 hostgorups have only one member - localhost. In your case, you could have multiple, comma separated members.
Code: Select all
[root@main-nagios-xi libexec]# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/hostgroup?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=HG1&alias=HG1&members=localhost"
{
"success": "Successfully added HG1 to the system. Config imported but not yet applied."
}
You have mail in /var/spool/mail/root
[root@main-nagios-xi libexec]# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/hostgroup?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=HG2&alias=HG2&members=localhost"
{
"success": "Successfully added HG2 to the system. Config imported but not yet applied."
}
[root@main-nagios-xi libexec]# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/hostgroup?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=HG3&alias=HG3&members=localhost&applyconfig=1"
{
"success": "Successfully added HG3 to the system. Config applied, Nagios Core was restarted."
}Hope this helps.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Bulk HostGoup Cloning
works great, thanks lmiltchev!
so hostgroups have been added and now what would be a proper syntax for API to add our hosts to each created groups?
I would assume I need at least following properties to fill in:
Name
Alias
Address
Description
HostGroups
...
Can I accomplish this task of adding hosts in bulk utilizing API as well?
so hostgroups have been added and now what would be a proper syntax for API to add our hosts to each created groups?
I would assume I need at least following properties to fill in:
Name
Alias
Address
Description
HostGroups
...
Can I accomplish this task of adding hosts in bulk utilizing API as well?
-
avandemore
- Posts: 1597
- Joined: Tue Sep 27, 2016 4:57 pm
Re: Bulk HostGoup Cloning
The API is not suitable for every task at the moment. To find what capabilities exist in the version you are using you can refer to:
XI > Help > REST API Docs
Capabilities vary a bit by version so this is the best place to check.
XI > Help > REST API Docs
Capabilities vary a bit by version so this is the best place to check.
Previous Nagios employee
-
dwhitfield
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Bulk HostGoup Cloning
While @avandemore is correct, this is the example we give at http://YOURIP/nagiosxi/help/api-config-reference.php
curl -XPOST "http://YOURIP/nagiosxi/api/v1/config/ho ... V&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"
If you go to http://YOURIP/nagiosxi/help/api-config-reference.php you'll see
Name
Alias
Address
Description
HostGroups
should all work. Basically, you just do directive=value&nextdirective=nextvalue
Please let us know if you run into any issues.
curl -XPOST "http://YOURIP/nagiosxi/api/v1/config/ho ... V&pretty=1" -d "host_name=testapihostapply&address=127.0.0.1&check_command=check_ping\!3000,80%\!5000,100%&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"
If you go to http://YOURIP/nagiosxi/help/api-config-reference.php you'll see
Thus,** All normal host directives are able to be used like normal core config definition files.
Name
Alias
Address
Description
HostGroups
should all work. Basically, you just do directive=value&nextdirective=nextvalue
Please let us know if you run into any issues.
-
nagwindmon
- Posts: 92
- Joined: Mon Dec 01, 2014 3:39 pm
Re: Bulk HostGoup Cloning
what command to use in API call when I just need to Apply config to take place?
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/? ... lyconfig=1"
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/? ... lyconfig=1"
-
dwhitfield
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Bulk HostGoup Cloning
That's in the next link down on the help menu. The direct link is: http://YOURIP/nagiosxi/help/api-system-reference.php
Obviously, I can't give the exact command because I don't know your API key.
Obviously, I can't give the exact command because I don't know your API key.