From e088c9be92a88b77da5f9adb4f6a0791fc5fbee2 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Fri, 12 Apr 2013 11:27:16 +0000 Subject: [PATCH] Allow fallback value for responsible email address git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36512 72102866-910b-0410-8b05-ffd578937521 --- AlertConfig.plist | 9 +++++++-- EcAlerter.h | 7 ++++--- EcAlerter.m | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/AlertConfig.plist b/AlertConfig.plist index 50756c4..5852b01 100644 --- a/AlertConfig.plist +++ b/AlertConfig.plist @@ -37,9 +37,14 @@ }, { Type = "Clear"; + /* Set a good subject for the email. + */ Subject = "Clear {Identifier} ({SeverityText})"; Email = ( - "myaccount@localhost.localdomain" + /* Send to the responsible email destination defined in the alarm + * or fall back to sending to myaccount@localhost.localdomain + */ + "{ResponsibleEmail}myaccount@localhost.localdomain" ); Stop = YES; /* Don't go on to any general alerts */ }, @@ -61,7 +66,7 @@ Type = "Alarm"; Subject = "Alarm {Identifier} ({SeverityText})"; Email = ( - "myaccount@localhost.localdomain" + "{ResponsibleEmail}myaccount@localhost.localdomain" ); Stop = YES; /* Don't go on to any general alerts */ }, diff --git a/EcAlerter.h b/EcAlerter.h index ca94cee..f7787c3 100644 --- a/EcAlerter.h +++ b/EcAlerter.h @@ -237,9 +237,10 @@ *

*

The Email array lists email addresses to which email * alerts are to be sent.
- * The address '{ResponsibleEmail}' may be used, if the alert is for an alarm, - * to email to the person/entity with primary responsibility for the alarm - * (as defined by the userInfo dictionary of the alarm).
+ * An address with the prefix '{ResponsibleEmail}' may be used as a + * special case. It means that if an alarm has a ResponsibleEmail value + * set in its userInfo dictionary, that value is used as the address, + * otherwise the text after '{ResponsibleEmail}' is used as a fallback.
* An optional Subject field may be present in the rule ... * this is used to specify that the email is to be tagged with the given * subject line. This defeats batching of messages in that diff --git a/EcAlerter.m b/EcAlerter.m index fb5d98b..4243c63 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -1131,9 +1131,22 @@ replaceFields(NSDictionary *fields, NSString *template) while ((d = [e nextObject]) != nil) { - if (YES == [d isEqualToString: @"{ResponsibleEmail}"]) + if (YES == [d hasPrefix: @"{ResponsibleEmail}"]) { - d = [m objectForKey: @"ResponsibleEmail"]; + NSString *s = [m objectForKey: @"ResponsibleEmail"]; + + if ([s length] > 0) + { + /* Use the ResponsibleEmail address from the alarm + */ + d = s; + } + else + { + /* Use the fallback (remaining text in the address) + */ + d = [d substringFromIndex: 18]; + } } if (0 == [d length]) {