How to add a Service to a HostGroup using NagiosXI rest-API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
imadc
Posts: 58
Joined: Wed Jun 14, 2017 12:10 pm

How to add a Service to a HostGroup using NagiosXI rest-API

Post by imadc »

Hello Team

With Nagios XI 5.4.7

I would like to add Services to host-groups using rest API of NagiosXI

Is there a way to do that?

I was able to import services and add service templates but didnt see an option for host groups

Thanks
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to add a Service to a HostGroup using NagiosXI rest-

Post by lmiltchev »

You can run something like this:
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/s ... 7&pretty=1" -d "host_name=localhost&service_description=PING&hostgroup_name=myhostgroup&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin&notification_interval=5&notification_period=24x7&applyconfig=1"
where you substitute "myhostgroup" with the actual name of your hostgroup.
Be sure to check out our Knowledgebase for helpful articles and solutions!
krutaw
Posts: 60
Joined: Wed Jul 31, 2013 6:30 pm

Re: How to add a Service to a HostGroup using NagiosXI rest-

Post by krutaw »

NICE! And for anyone who runs a Nagios server that doesn't link services directly to hosts but instead links to hostgroups, you can use the &force=1 command to force a service check to link directly to the hostgroup without defining a host.
Example:

curl -XPOST "https://YOURNAGIOSSERVERHERE/nagiosxi/a ... E&pretty=1" -d "hostgroup_name=test&service_description=PING
&check_command=check_ping\!3000,80%\!5000,100%
&check_interval=5&retry_interval=5
&max_check_attempts=2&check_period=24x7
&contacts=nagiosadmin&notification_interval=5
&notification_period=24x7&applyconfig=1&force=1"

Note: the config name in core config will be listed as the hostgroup name.

Sorry, had to break apart the command in order to make it all show up. :(
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to add a Service to a HostGroup using NagiosXI rest-

Post by lmiltchev »

@imadc Do you have any more questions or it is ok to lock this topic?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked