NetXMS Support Forum

English Support => General Support => Topic started by: curruscanis on July 28, 2015, 12:15:57 AM

Title: email user based on container items
Post by: curruscanis on July 28, 2015, 12:15:57 AM
I have emails setup to email a user upon all critical alerts and resolution of given alerts.  Is there is method to email an additional user only for nodes within a container? 

Thank you for your assistance!
Title: Re: email user based on container items
Post by: Alex Kirhenshtein on July 28, 2015, 01:24:52 AM
Just add additional rule into EPP. Set events=(list), source=container, action=email-to-additional-user
Title: Re: email user based on container items
Post by: curruscanis on July 28, 2015, 11:16:04 PM
Thank you Alex, that is what I came up with too.  I was hoping there was a way to alter a given rule in the event processing that would do both.  If I have to create a new rule for each container that has a different person responsible it will eventually be a lot of redundant rules with the only difference being the email destination.

Title: Re: email user based on container items
Post by: Victor Kirhenshtein on August 04, 2015, 06:06:57 PM
You can set responsible person's in container's custom attribute, and create universal action that will use script to extract recipient. For example, you can definie recipients in email action like this:

%[GetRecipients]

Then, create script in script library caled "GetRecipients" like this:


foreach(p : GetNodeParents($node))
{
rcpt = GetCustomAttribute(p, "recipients");
if (rcpt != null)
return rcpt;
}
return "default@email";  // fallback email if nothing was set in containers


It will return emails configured in parent container for node in custom attribute "recipients", or default email if nothing is configured. Script can be made more complicated to collect all recipients on all upper layers and combine them into single recipient list.

Best regards,
Victor
Title: Re: email user based on container items
Post by: curruscanis on August 18, 2015, 05:50:44 PM
Thank you Victor, I will give that a try.  It is easier than setting up different alerts and actions for each email address.

Title: Re: email user based on container items
Post by: Marco Incalcaterra on September 11, 2015, 12:03:02 AM
Quote from: Victor Kirhenshtein on August 04, 2015, 06:06:57 PM
It will return emails configured in parent container for node in custom attribute "recipients", or default email if nothing is configured. Script can be made more complicated to collect all recipients on all upper layers and combine them into single recipient list.

Hi Victor,

Have a look to the attached image. Is it possible to find the custom attribute in a "top level" parent container? I've created the custom attribute "recipients" into the container "Thinksoft" but when the alarm is generated from an inner node (e.g. VM-REDQUEEN three levels down or SKYNET two levels down) that custom attribute seems ignored.

Best regards,
Marco
Title: Re: email user based on container items
Post by: Victor Kirhenshtein on September 11, 2015, 03:24:32 PM
Hi,

how script to extract recipients looks like?

Best regards,
Victor
Title: Re: email user based on container items
Post by: Marco Incalcaterra on September 11, 2015, 03:27:00 PM
Quote from: Victor Kirhenshtein on September 11, 2015, 03:24:32 PM
Hi,

how script to extract recipients looks like?

Best regards,
Victor

Exactly like te one you posted in your example, I assumed (wrongly at this point) that all the parents were explored in the "foreach" statement.

Marco
Title: Re: email user based on container items
Post by: Victor Kirhenshtein on September 11, 2015, 03:37:36 PM
Only direct parents are examined. Recursive script could looks like this:


rcpt = GetRecipients($node);
return (rcpt != null) ? rcpt : "default@email";  // fallback email if nothing was set in containers

sub GetRecipients(obj)
{
    rcpt = GetCustomAttribute(obj, "recipients");
    if (rcpt != null)
return rcpt;
    foreach(p : GetObjectParents(obj))
    {
        rcpt = GetRecipients(p);
  if (rcpt != null)
return rcpt;
    }
    return null;
}


and if you want that any closest parent had higher priority:


rcpt = GetRecipients($node);
return (rcpt != null) ? rcpt : "default@email";  // fallback email if nothing was set in containers

sub GetRecipients(obj)
{
    foreach(p : GetObjectParents(obj))
    {
        rcpt = GetCustomAttribute(p, "recipients");
if (rcpt != null)
return rcpt;
    }
    foreach(p : GetObjectParents(obj))
    {
        rcpt = GetRecipients(p);
if (rcpt != null)
return rcpt;
    }
    return null;
}


Best regards,
Victor
Title: Re: email user based on container items
Post by: Marco Incalcaterra on September 11, 2015, 08:39:51 PM
Quote from: Victor Kirhenshtein on September 11, 2015, 03:37:36 PM

rcpt = GetRecipients($node);
return (rcpt != null) ? rcpt : "default@email";  // fallback email if nothing was set in containers

sub GetRecipients(obj)
{
    foreach(p : GetObjectParents(obj))
    {
        rcpt = GetCustomAttribute(p, "recipients");
if (rcpt != null)
return rcpt;
    }
    foreach(p : GetObjectParents(obj))
    {
        rcpt = GetRecipients(p);
if (rcpt != null)
return rcpt;
    }
    return null;
}


I've used this one (the second) and it rocks! Thank you very much for your help.  :D

Best remarks,
Marco