Page 1 of 1
programmatically check if Notifications are disabled
Posted: Mon Jul 17, 2017 12:37 pm
by brdr
Hi Support team,
Is there a way to programmatically check from the back-end if Notifications have been disabled via front-end? We have more and more privileged users who at times maybe adding fair amount of new hosts and devices. When adding wholesale changes we sometimes disable notifications via front-end. When wholesale changes look good after configuration we then enable notifications (sometimes its forgotten to do this step) via front-end.
I'm familiar with nagios.cfg in /etc/ and .status file in /var/ directory. When I disable notification via front-end I can't tell from any of these files that notifications are off.
Thx
Re: programmatically check if Notifications are disabled
Posted: Mon Jul 17, 2017 3:06 pm
by tgriep
You could use the GET system/status API to get the current status on the system and the notifications_enabled option will tell you if notifications have been globably disabled on the system.
Code: Select all
curl -XGET "https://127.0.0.1/nagiosxi/api/v1/system/status¬ifications_enabled?apikey=j8hf9sss&pretty=1" -k
Code: Select all
{
"instance_id": "1",
"instance_name": "localhost",
"status_update_time": "2017-07-17 14:58:01",
"program_start_time": "2017-07-17 09:10:08",
"program_run_time": "20875",
"program_end_time": "0000-00-00 00:00:00",
"is_currently_running": "1",
"process_id": "15279",
"daemon_mode": "1",
"last_command_check": "1969-12-31 18:00:00",
"last_log_rotation": "1969-12-31 18:00:00",
"notifications_enabled": "0",
"active_service_checks_enabled": "1",
"passive_service_checks_enabled": "1",
"active_host_checks_enabled": "1",
"passive_host_checks_enabled": "1",
"event_handlers_enabled": "1",
"flap_detection_enabled": "0",
"process_performance_data": "1",
"obsess_over_hosts": "0",
"obsess_over_services": "0",
"modified_host_attributes": "15",
"modified_service_attributes": "15",
"global_host_event_handler": "xi_host_event_handler",
"global_service_event_handler": "xi_service_event_handler"
}
To get more details on the API, login to the XI GUI and go to the Help > System Reference menu to get the API URL you would need for your server.
Re: programmatically check if Notifications are disabled
Posted: Mon Jul 17, 2017 4:29 pm
by tacolover101
brdr wrote:Hi Support team,
Is there a way to programmatically check from the back-end if Notifications have been disabled via front-end? We have more and more privileged users who at times maybe adding fair amount of new hosts and devices. When adding wholesale changes we sometimes disable notifications via front-end. When wholesale changes look good after configuration we then enable notifications (sometimes its forgotten to do this step) via front-end.
I'm familiar with nagios.cfg in /etc/ and .status file in /var/ directory. When I disable notification via front-end I can't tell from any of these files that notifications are off.
Thx
it may be worth leveraging your test license for this as you on board new servers / applications - disabling your notifications on a prod system as you mentioned seems like a disaster waiting to happen / miss.
i believe the status.dat updates when you turn them off / on, so you could probably come up with a one liner bash script to run on the XI host itself, to parse through /usr/local/nagios/var/status.dat and look for notifications_enabled.
Re: programmatically check if Notifications are disabled
Posted: Tue Jul 18, 2017 10:29 am
by tgriep
Yes, searching the status.dat file would be another option.
If you search for this string
It will tell you if the notifications are disabled globally.
A Zero means it is disabled and a One means that it is enabled.
Re: programmatically check if Notifications are disabled
Posted: Tue Jul 18, 2017 2:27 pm
by brdr
Hi tgriep,
The status.dat and retention.dat didn't change from 1 to 0 after disabling via front-end. This is the first place I went to look.
Your first option was spot on with regards to curl and API key. I just have to tighten up my script a little bit to notify the team when it is 0.
I can try to test license mentioned below too.
But, you can close this one.... thanks again!
u guys rock.
Re: programmatically check if Notifications are disabled
Posted: Tue Jul 18, 2017 2:31 pm
by bolson
Closing this topic as resolved.
Thank you for using the Nagios Support Forum!