Page 1 of 1

Remove 'disable notifications' quick action

Posted: Thu Jan 26, 2017 5:07 am
by WillemDH
I'm a bit tired of people using the 'disable notification' quick action. is there some way to remove this "Disable notifications" quick action?

Re: Remove 'disable notifications' quick action

Posted: Thu Jan 26, 2017 11:16 am
by mcapra
Officially, no.

If you were feeling ambitious, In the following files:

Code: Select all

/usr/local/nagiosxi/html/includes/components/xicore/ajaxhelpers-servicestatus.inc.php
/usr/local/nagiosxi/html/includes/components/xicore/ajaxhelpers-hoststatus.inc.php
You might comment out blocks of code that look like this:

Code: Select all

#ajaxhelpers-hoststatus.inc.php line 609
            // NOTIFICATIONS
            if (intval($xml->hoststatus->notifications_enabled) == 1) {
                $cmd["command_args"]["cmd"] = NAGIOSCORE_CMD_DISABLE_HOST_NOTIFICATIONS;
                $output .= '<li>' . get_host_detail_command_link($cmd, "nonotifications.png", _("Disable notifications")) . '</li>';
            } else {
                $cmd["command_args"]["cmd"] = NAGIOSCORE_CMD_ENABLE_HOST_NOTIFICATIONS;
                $output .= '<li>' . get_host_detail_command_link($cmd, "enablenotifications.png", _("Enable notifications")) . '</li>';
            }

#ajaxhelpers-servicestatus.inc.php line 766
            // NOTIFICATIONS
            if (intval($xml->servicestatus->notifications_enabled) == 1) {
                $cmd["command_args"]["cmd"] = NAGIOSCORE_CMD_DISABLE_SVC_NOTIFICATIONS;
                $output .= '<li>' . get_service_detail_command_link($cmd, "nonotifications.png", _("Disable notifications")) . '</li>';
            } else {
                $cmd["command_args"]["cmd"] = NAGIOSCORE_CMD_ENABLE_SVC_NOTIFICATIONS;
                $output .= '<li>' . get_service_detail_command_link($cmd, "enablenotifications.png", _("Enable notifications")) . '</li>';
            }
Though those alterations are likely to be overwritten on upgrades. You could probably write a custom JS includes file to achieve a similar effect and have more staying power.

Re: Remove 'disable notifications' quick action

Posted: Thu Jan 26, 2017 12:05 pm
by mcapra
Javascript is actually a much more elegant solution in my opinion. With the understanding that I threw this together in a few minutes with minimal testing, you could try throwing this in a .js file and uploading it via the Custom Includes component:

Code: Select all

$(document).ajaxComplete(function () {
	$("div.service_state_quick_actions").children("li").each(function () {
		if ($(this).find("a").attr("onclick")) {
			if ($(this).find("a").attr("onclick").match(/("cmd":23)/)) {
				$(this).hide();
			}
		}
	});
	$("div.host_state_quick_actions").children("li").each(function () {
		if ($(this).find("a").attr("onclick")) {
				if ($(this).find("a").attr("onclick").match(/("cmd":25)/)) {
				$(this).hide();
			}
		}	
	});
});

We have to use ajaxComplete as the trigger unfortunately since the page is constantly updating which regenerates the quick actions.

EDIT: updated the code to account for a thing

Re: Remove 'disable notifications' quick action

Posted: Thu Jan 26, 2017 6:50 pm
by SteveBeauchemin
Willem,

Suggestion - edit the php and make the ability to disable notifications for 'Everyone' just go away. As suggested already.

Then - put them back - but just for you or whoever you designate...

I like the disable all service notifications feature that Nagios core provided. Since I missed it so much I added it back. As a Quick Action.
These open a separate tab, make your selection, and close the tab.
action3.PNG
Disable the notification feature that you don't want everyone to have. Set up a Quick Action and allow the specific users that you decide should have it.

I have some notes I took from when I did this. go to Admin --> Manage Components --> Actions -- Edit Settings
At the bottom, fill in a new action.
To Enable Notifications for ALL services on a Host

Code: Select all

Object Type: Host
Host: /.*/
Service: [blank]
Hostgroup: [blank]
Servicegroup: [blank]

Action Type: URL
URL / Command: http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=28&host=%host%
Target: _blank
Action Text: Enable Notifications for all Services on the host

On the far right - choose Custom - and you control who can see and use the command
To Disable Notifications for ALL services on a Host

Code: Select all

Object Type: Host
Host: /.*/
Service: [blank]
Hostgroup: [blank]
Servicegroup: [blank]

Action Type: URL
URL / Command: http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=29&host=%host%
Target: _blank
Action Text: Disable Notifications for all Services on the host

On the far right - choose Custom - and you control who can see and use the command
for other actions, choose your poison... these URLs work.

Code: Select all

turn off Service Notify
http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=23&host=%host%&service=%servicedisplayname%
turn on Service Notify
http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=22&host=%host%&service=%servicedisplayname%

turn off host notify
http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=25&host=%host%
turn on host notify
http://[Nagios Host]/nagiosxi/includes/components/nagioscore/ui/cmd.php?cmd_typ=24&host=%host%
Just keep in mind that if you converted your Nagios instance to use SSL, then remember to change these http to https.
The URL from Nagios Core uses cmd.cgi, but I choose to use the Nagios XI cmd.php instead.

I gotta say, that Nagios is some flexible system huh.

Steve B

Re: Remove 'disable notifications' quick action

Posted: Fri Jan 27, 2017 10:22 am
by dwhitfield
@WillemDH, what do you think of the solutions provided? Ready to lock this up?