Page 1 of 1

Addon Address (x)

Posted: Wed Oct 28, 2020 8:02 am
by TethiS
HI,

I've been trying without success to use the Addon Address fields of the contacts to send the notification to an additional smtp address.
It seems that no matter what only the primary e-mail address associated with the contact is used to send the notification.

I looked upon the eventman.log and the Addon Address is not taken into consideration at any time.

I've swapped the primary with the addon address and the e-mail got sent only to the one that was at the moment attached directly on the contact (so i've excluded the possibility that some of the addresses is not "working" as expected).

Is it something i'm missing here?

Thank you

Re: Addon Address (x)

Posted: Wed Oct 28, 2020 5:17 pm
by benjaminsmith
Hi,

Good question and I'm going to have to check with the team members on this. I believe those addon addresses may only work with the Nagios Core notification handlers.

Benjamin

Re: Addon Address (x)

Posted: Thu Oct 29, 2020 2:49 am
by TethiS
While waiting for an 'official' answer/solution i've managed to render this functional with a minimal alteration of two files:

/usr/local/nagiosxi/html/includes/components/xicore/xicore.inc.php
added bit of code to loop through address1-address6 Addon "Fields" and if finding valied e-mails there add them to the recipient address, separated by comma

// Get the user's email address
$email = get_user_attr($user_id, "email");
$username_addon = get_user_attr($user_id, "username");

//look and parse the Addon Addresses
$addons=['address1','address2','address3','address4','address5','address6'];
foreach ($addons as $address){
$addon_mail = get_user_addon($username_addon, $address);
if (valid_email($addon_mail)) {
$email = $email.",".$addon_mail;
}
}


/usr/local/nagiosxi/html/includes/utils-users.inc.php
added a new function to retrieve the addressX field value using contact_name as key, as the user_id does not seem to be the same between nagiosxi and nagiosql user/contacts tables

/**
* Get the Addon Address 1 to 6 attribute from the NAGIOSQL database based on contact_name and column name
*
* @param int $contact_name The Contact Name
* @param string $addon Column name (address1 to address6)
* @return bool|mixed The value in the database or false if nothing found
*/
function get_user_addon($contact_name, $addon)
{
global $db_tables;

// Make sure we have required variables
if (!have_value($contact_name) || !have_value($addon)) {
return false;
}

// Get attribute from database
$sql = "SELECT " . escape_sql_param($addon, DB_NAGIOSQL) . " FROM nagiosql.tbl_contact WHERE contact_name='" . escape_sql_param($contact_name, DB_NAGIOSQL) . "'";
if (($rs = exec_sql_query(DB_NAGIOSQL, $sql, false))) {
if ($rs->MoveFirst()) {
return $rs->fields[$addon];
}
}

return false;
}

Re: Addon Address (x)

Posted: Thu Oct 29, 2020 3:41 pm
by benjaminsmith
Hi,

The official answer here is that they are a part of the Nagios Core object definitions, but are not officially used with Nagios XI. Sending notifications over SMTP uses the PHPmailer library, and as you know these fields are not passed. If a user migrated from Core, they may use these fields and that's why they remain.
Address directives are used to define additional "addresses" for the contact. These addresses can be anything - cell phone numbers, instant messaging addresses, etc. Depending on how you configure your notification commands, they can be used to send out an alert to the contact. Up to six addresses can be defined using these directives (address1 through address6). The $CONTACTADDRESSx$ macro will contain this value.
See: https://assets.nagios.com/downloads/nag ... ml#contact

Nice work on coming up with a solution, just remember to keep a backup of those changes as those files will be overwritten on upgrades. Let me know if you have any other questions.

Re: Addon Address (x)

Posted: Sun Nov 01, 2020 4:46 pm
by TethiS
Hi,

thank you for the clarifications!
The main key info here is the $CONTACTADDRESSx$ (wasn't aware of it or probably lazy to look for that myself).
I guess this means if the nagiosxi notification handler is replaced with a custom handler then these additional fields/addresses may be referenced through this macro(s) (and passed as arguments) which is fair enough.

Thanks again,
you may lock the current topic.

Sebastian

Re: Addon Address (x)

Posted: Mon Nov 02, 2020 11:04 am
by benjaminsmith
Hi Sebastian,
Thanks again,
you may lock the current topic
Sounds good. We'll mark this as resolved.

Thank you for using Nagios!