REST API mixing sequential service DELETEs and POSTs
Posted: Fri Nov 09, 2018 3:41 pm
Our automated deployment is creating/updating Nagios services using the REST API. Since there is no mechanism to update/modify a service, you have to delete and re-post the service. However, if you do this too quickly, as automation will do, the deletes and posts will get mixed up, and you'll only have a subset of the services. The number of services kept is random enough that it feels like it's an asynchronous processing issue behind the scenes. I can get around it with a sleep for a couple seconds after (all) the delete(s), but this feels like a horrible workaround. Am I missing something, such as a better update mechanism, etc.?
To recreate, here's the Help curl commands simply lumped together for 4 services:
When I run that, I get a random number of PING1-4 services to actually get applied, and the configuration snapshots do not appear to be applied in the order in which the curl commands execute.
Note that this also happens if I defer applying the config until the end of all processing.
Finally, we are running Nagios XI 5.4.11.
To recreate, here's the Help curl commands simply lumped together for 4 services:
Code: Select all
curl -sS -XDELETE "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1&host_name=testapihost&service_description=PING&applyconfig=1"
curl -sS -XPOST "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1" -d "host_name=testapihost&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"
curl -sS -XDELETE "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1&host_name=testapihost&service_description=PING2&applyconfig=1"
curl -sS -XPOST "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1" -d "host_name=testapihost&service_description=PING2&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"
curl -sS -XDELETE "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1&host_name=testapihost&service_description=PING3&applyconfig=1"
curl -sS -XPOST "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1" -d "host_name=testapihost&service_description=PING3&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"
curl -sS -XDELETE "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1&host_name=testapihost&service_description=PING4&applyconfig=1"
curl -sS -XPOST "https://nagios.domain.name/nagiosxi/api/v1/config/service?apiKey=<redacted>&pretty=1" -d "host_name=testapihost&service_description=PING4&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"Note that this also happens if I defer applying the config until the end of all processing.
Finally, we are running Nagios XI 5.4.11.