Page 1 of 2
Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 2:21 pm
by perric
Hello,
I am running Nagios XI 2014R2.6.
Is possible to modify the xi_host_notification_handler command to specify a sender name like "Nagios Power Alert"?
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$ -- r TEST" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$"
David
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 2:44 pm
by abrist
Just to clarify, you wish to stamp all outgoing emails with a new "From", correct? If so, just edit the "Send Mail From" field in the XI interface at --> Admin --> Manage email settings.
If not, could you clarify?
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 3:02 pm
by perric
Thanks for your reply.
No, I want to specify a different "e-mail display name" depending on the situation. For example, if there's a power related alert, I want it to come from one e-mail display name, like "Nagios Power Alert". if there's a server related alert, I want it to come from a different e-mail display name, like "Nagios Server Alert". I understand that this would mean configuring multiple contacts, etc. to make this happen.
David
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 3:10 pm
by tmcdonald
Not necessarily multiple contacts, but Nagios needs a way to know what constitutes a power outage vs a server problem. You could create a custom variable, either in templates or on the services themselves, called
_type and then use
$_SERVICETYPE$ as a macro. Then just set
_type with whatever type of outage it is, and use that in your notification to set the email display name appropriately.
http://nagios.sourceforge.net/docs/3_0/ ... tvars.html
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 4:38 pm
by perric
Thanks again. I did not think of doing that. To recap (so I understand), I can do the following:
1. Add a variable (using the GUI for example) under "Misc Settings" of a service, host or service/host template
2. Call it _SERVICETYPE (for example) and give is a value of something like POWER, SERVER, etc.
If yes, then how would I incorporate this variable, so that it appears as the "e-mail Display" field? Would I add it to the handle_nagioscore_notification.php script file?
David
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Wed Jul 01, 2015 4:40 pm
by tmcdonald
I'm still not 100% sure what you mean by the "e-mail Display" field. You stated earlier that you are not referring to the From field, so are you talking about the Subject? Do you have a screenshot of an email that you could mock up with the changes you want made?
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Fri Jul 10, 2015 2:02 pm
by perric
Sorry about the slow reply. I was away on business.
The e-mail address field has two components that relate to this... an e-mail address and a display name or alias. The e-mail display name can be anything and is shown in an e-mail Inbox in the From field, instead of the real e-mail address. Or it often appears in quotes like the following example when viewing an e-mail in clear text:
Joe Plumber
<
[email protected]>
I would like to have my alerts come into our mailboxes with a sender address showing Nagios NETWORK, Nagios SERVER or Nagios POWER depending on the situation (or depending on the defined variables).
David
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Fri Jul 10, 2015 2:04 pm
by perric
Sorry - that did not format properly - the e-mail display name would look like this:
"Joe Plumber"<
[email protected]>
David
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Mon Jul 13, 2015 11:06 am
by ssax
I see what you mean, I'm looking through the code now to see if it's easily doable, I'll let you know what I find.
Are your contacts using xi_host_notification_handler and xi_service_notification_handler? You can tell by editing a contact, click on the alert settings tab, and looking in the Manage Host Notification Commands and Manage Service Notification Commands sections. If they are empty go back to to the Common Settings tab and click on the Manage Contact Templates button to look at the contact templates, if it's using xi_contact_generic template that means it is using xi_host/service_notificaiton_handler commands instead of the notify_host/service_by email commands.
Re: Specify "Sender Name" in xi_host_notification_handler?
Posted: Mon Jul 13, 2015 1:03 pm
by ssax
*** This will get reverted by an upgrade, you may have to redo the file modifications after each upgrade.
*** Make sure you have good backups/snapshots in case something goes wrong.
*** This is based on Nagios XI 2014R2.7, you version may differ.
Note: This is an example for a host, it should be handled the same for services. You would just edit the xi_service_notification_handler command and use --emailtype="$_SERVICEEMAILTYPE$" instead.
Go to Configure > Core Config Manager > Hosts and edit the host you want.
- Click on the Misc Settings tab
- Click the Manage Variable Definitions button
- Variable name: _emailtype
- Variable value: Power (or whatever you want the email to show)
Go to Configure > Core Config Manager > Commands and edit xi_host_notification_handler
Here is mine as an example:
Code: Select all
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$"
Add this code to the end of it:
So it looks something like this:
Code: Select all
/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=host --contact="$CONTACTNAME$" --contactemail="$CONTACTEMAIL$" --type=$NOTIFICATIONTYPE$ --escalated="$NOTIFICATIONISESCALATED$" --author="$NOTIFICATIONAUTHOR$" --comments="$NOTIFICATIONCOMMENT$" --host="$HOSTNAME$" --hostaddress="$HOSTADDRESS$" --hostalias="$HOSTALIAS$" --hostdisplayname="$HOSTDISPLAYNAME$" --hoststate=$HOSTSTATE$ --hoststateid=$HOSTSTATEID$ --lasthoststate=$LASTHOSTSTATE$ --lasthoststateid=$LASTHOSTSTATEID$ --hoststatetype=$HOSTSTATETYPE$ --currentattempt=$HOSTATTEMPT$ --maxattempts=$MAXHOSTATTEMPTS$ --hosteventid=$HOSTEVENTID$ --hostproblemid=$HOSTPROBLEMID$ --hostoutput="$HOSTOUTPUT$" --longhostoutput="$LONGHOSTOUTPUT$" --datetime="$LONGDATETIME$" --emailtype="$_HOSTEMAILTYPE$"
Now edit this file:
Code: Select all
/usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php
Change this code (around line 235):
Code: Select all
$opts = array(
"from" => "Nagios XI <" . $admin_email . ">",
"to" => $email,
"subject" => $subject,
"type" => $meta['type']
);
To:
Code: Select all
$opts = array(
"from" => "Nagios XI <" . $admin_email . ">",
"to" => $email,
"subject" => $subject,
"type" => $meta['type'],
"emailtype" => "$meta[emailtype]"
);
Then edit this file:
Code: Select all
/usr/local/nagiosxi/html/includes/utils-email.inc.php
Change this code (around line 68):
Code: Select all
$mail->SetFrom($address_parts[0]["email"], $address_parts[0]["name"]);
To:
Code: Select all
if($opts["emailtype"] != '$') {
$mail->SetFrom($address_parts[0]["email"], "Nagios $opts[emailtype]");
} else {
$mail->SetFrom($address_parts[0]["email"], $address_parts[0]["name"]);
}
Now it should do what you want.