The command seems to specifically ask for a hostname and wont run without it-
Code: Select all
curl -XDELETE "https://SERVER/nagiosxi/api/v1/config/service?apikey=longasskey&pretty=1&host_name=testapihost&service_description=PING&applyconfig=1"Code: Select all
curl -XDELETE "https://SERVER/nagiosxi/api/v1/config/service?apikey=longasskey&pretty=1&host_name=testapihost&service_description=PING&applyconfig=1"Code: Select all
# curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=printers&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¬ification_interval=5¬ification_period=24x7&applyconfig=1&force=1"
{
"success": "Successfully added :: PING to the system. Config applied, Nagios Core was restarted."
}Code: Select all
define service {
service_description PING
hostgroup_name printers
check_command check_ping!3000,80%!5000,100%
max_check_attempts 2
check_interval 5
retry_interval 5
check_period 24x7
notification_interval 5
notification_period 24x7
contacts nagiosadmin
register 1
}Code: Select all
{
"error": "Missing required variables",
"missing": [
"host_name"
]
}Need to know when this will be finished. Since there is no "update service" directive, then this is the only way to delete-then-add via the API. And it fails if you don't have a host_name but rely on hostgroup.lmiltchev wrote:Currently, this is not possible as the REST API verifies if the service is a "part of a host". Accepting more directives in the future, such as hostgroup_name is on our todo list.
Unfortunately, I don't have an ETA on that. Our developers will get to it as soon as they can, depending on the length or their TODO list.Need to know when this will be finished.
You can update a service with the same config_name and service_description (at least in XI 5.5.4) by re-adding it.Optionally, need to know when adding a service with the same "config_name" and "service_description" as an existing service will update the service with the information specified. That would be a real problem solver.
Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "host_name=localhost&config_name=localhostconfig&service_description=TEST&check_command=check_ping\!3000,80%\!5000,100%&check_interval=5&retry_interval=5&max_check_attempts=2&check_period=24x7&contacts=nagiosadmin¬ification_interval=5¬ification_period=24x7&applyconfig=1"
{
"success": "Successfully added localhost :: TEST to the system. Config applied, Nagios Core was restarted."
}Code: Select all
define service {
host_name localhost
service_description TEST
check_command check_ping!3000,80%!5000,100%
max_check_attempts 2
check_interval 5
retry_interval 5
check_period 24x7
notification_interval 5
notification_period 24x7
contacts nagiosadmin
register 1
}Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "host_name=localhost&config_name=localhostconfig&service_description=TEST&check_command=check_dummy\!0\!'Dummy check'&check_interval=10&retry_interval=3&max_check_attempts=1&check_period=24x7&contacts=nagiosadmin¬ification_interval=60¬ification_period=24x7&applyconfig=1"
{
"success": "Successfully added localhost :: TEST to the system. Config applied, Nagios Core was restarted."
}Code: Select all
define service {
host_name localhost
service_description TEST
check_command check_dummy!0!'Dummy check'
max_check_attempts 1
check_interval 10
retry_interval 3
check_period 24x7
notification_interval 60
notification_period 24x7
contacts nagiosadmin
register 1
}Code: Select all
curl -k -XPOST "https://127.0.0.1/nagiosxi/api/v1/config/service?apikey=ILIKEPONIES&pretty=1" -d "service_description=Eric&use=generic-service&display_name=&force=1&config_name=VoIP Peers"
Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=linux-servers&service_description=Eric&config_name=MyConfigName1&use=generic-service&check_command=check_ping\!3000,80%\!5000,100%&display_name=MyDisplayName1&applyconfig=1&force=1"Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "hostgroup_name=linux-servers&service_description=Eric&config_name=MyConfigName1&use=generic-service&check_command=check_ping\!3000,80%\!5000,100%&display_name=MyDisplayName2&applyconfig=1&force=1"Code: Select all
[root@main-nagios-xi services]# pwd
/usr/local/nagios/etc/services
[root@main-nagios-xi services]# ll MyConfig*
-rw-rw-r-- 1 apache nagios 1308 Sep 25 14:19 MyConfigName1.cfgCode: Select all
define service {
service_description Eric
use generic-service
hostgroup_name linux-servers
display_name MyDisplayName1
check_command check_ping!3000,80%!5000,100%
register 1
}
define service {
service_description Eric
use generic-service
hostgroup_name linux-servers
display_name MyDisplayName2
check_command check_ping!3000,80%!5000,100%
register 1
}Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "host_name=localhost&service_description=Eric&config_name=MyConfigName1&use=generic-service&check_command=check_ping\!3000,80%\!5000,100%&display_name=MyDisplayName1&applyconfig=1&force=1"Code: Select all
curl -XPOST "http://x.x.x.x/nagiosxi/api/v1/config/service?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "host_name=localhost&service_description=Eric&config_name=MyConfigName1&use=generic-service&check_command=check_ping\!3000,80%\!5000,100%&display_name=MyDisplayName2&applyconfig=1&force=1"