email user based on container items

Started by curruscanis, July 28, 2015, 12:15:57 AM

Previous topic - Next topic

curruscanis

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!

Alex Kirhenshtein

Just add additional rule into EPP. Set events=(list), source=container, action=email-to-additional-user

curruscanis

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.


Victor Kirhenshtein

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

curruscanis

Thank you Victor, I will give that a try.  It is easier than setting up different alerts and actions for each email address.


Marco Incalcaterra

#5
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

Victor Kirhenshtein

Hi,

how script to extract recipients looks like?

Best regards,
Victor

Marco Incalcaterra

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

Victor Kirhenshtein

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

Marco Incalcaterra

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