Page 1 of 1

REST API and disabling active and passive checks

Posted: Fri Nov 10, 2017 9:53 am
by nortonhealthcare
Is there a way within the REST API to disable active and passive checks for a host.

Re: REST API and disabling active and passive checks

Posted: Fri Nov 10, 2017 11:13 am
by lmiltchev
It can be done, but you would not be modifying the config file. Basically, you would be re-adding (replacing) the host object. Here's a simple example.

I have an existing "test" host, called "MyHost". See the config below:

Code: Select all

define host {
	host_name			MyHost
	use				xiwizard_generic_host
	address				127.0.0.1
	check_command			check_dummy!0!!!!!!!
	active_checks_enabled		1
	passive_checks_enabled		0
	register			1
	}
If I wanted to disable active checks on this host, and enable passive checks, I would run:

Code: Select all

[root@main-nagios-xi ~]# curl -XPOST "http://192.168.5.151/nagiosxi/api/v1/config/host?apikey=LTltbjobR0X3V5ViDIitYaI8hjsjoFBaOcWYukamF7oAsD8lhJRvSPWq8I3PjTf7&pretty=1" -d "host_name=MyHost&address=127.0.0.1&check_command=check_dummy\!0\!&use=xiwizard_generic_host&active_checks_enabled=0&passive_checks_enabled=1&force=1&applyconfig=1"
{
    "success": "Successfully added MyHost to the system. Config applied, Nagios Core was restarted."
}
The "new" config would be:

Code: Select all

define host {
	host_name			MyHost
	use				xiwizard_generic_host
	address				127.0.0.1
	check_command			check_dummy!0!
	active_checks_enabled		0
	passive_checks_enabled		1
	register			1
	}