From 69c31c492444ba1bb742eb9f34e0c0299972cf6a Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Sun, 7 Apr 2013 11:38:46 +0000 Subject: [PATCH] Improve subjects for alarms/clears git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36486 72102866-910b-0410-8b05-ffd578937521 --- AlertConfig.plist | 16 +++++++++++++--- EcAlerter.h | 10 ++++++---- EcAlerter.m | 23 +++++++++++------------ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/AlertConfig.plist b/AlertConfig.plist index c6fdb21..be0167a 100644 --- a/AlertConfig.plist +++ b/AlertConfig.plist @@ -29,22 +29,32 @@ Rewrite = "{Original}\n\nAlarm outstanding for {Hours} hours."; }, { - SeverityText = "..*"; /* Any alert with an alarm severity */ + SeverityText = "..*"; DurationBelow = "60"; /* Alarm outstanding for under an hour */ Rewrite = "{Original}\n\nAlarm outstanding for {Minutes} minutes."; }, + { + SeverityText = "..*"; + Subject = "Alarm {Identifier}"; + Email = ( + "myaccount@localhost.localdomain" + ); + Stop = YES; /* Don't go on to any general alerts */ + }, + { SeverityCode = "5"; /* Any alert for a cleared alarm */ DurationAbove = "59"; /* Alarm outstanding for an hour or more */ Rewrite = "{Original}\n\nCleared after {Hours} hours."; }, { - SeverityCode = "5"; /* Any alert for a cleared alarm */ + SeverityCode = "5"; DurationBelow = "60"; /* Alarm outstanding for under an hour */ Rewrite = "{Original}\n\nCleared after {Minutes} minutes."; }, { - SeverityText = "..*"; /* Any alert with an alarm severity */ + SeverityText = "5"; + Subject = "Clear {Identifier}"; Email = ( "myaccount@localhost.localdomain" ); diff --git a/EcAlerter.h b/EcAlerter.h index 4518e56..cd77508 100644 --- a/EcAlerter.h +++ b/EcAlerter.h @@ -200,10 +200,12 @@ *

*

The Email array lists email addresses to which email alerts are * to be sent.
- * An optional 'Subject' field may be present in the rule ... this is used - * to specify that the is to be tagged with the given subject line. This - * defeats batching of messages in that only messages with the - * same subject may be batched in the same email. + * An optional Subject field may be present in the rule ... + * this is used to specify that the is to be tagged with the given + * subject line. This defeats batching of messages in that + * only messages with the same subject may be batched in the same email.
+ * NB. The value of the Subject field is used as a template + * in the same way as the Replacement fields. *

* *

Configuration of the alerter is done by the 'Alerter' key in the user diff --git a/EcAlerter.m b/EcAlerter.m index 9189aca..609f68e 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -98,11 +98,11 @@ @end static NSMutableString * -replaceFields(NSDictionary *fields) +replaceFields(NSDictionary *fields, NSString *template) { NSMutableString *m; - m = [[[fields objectForKey: @"Replacement"] mutableCopy] autorelease]; + m = [[template mutableCopy] autorelease]; if (nil != m) { NSEnumerator *e; @@ -541,8 +541,7 @@ replaceFields(NSDictionary *fields) s = [d objectForKey: @"Rewrite"]; if (nil != s) { - [m setObject: s forKey: @"Replacement"]; - s = replaceFields(m); + s = replaceFields(m, s); [m setObject: s forKey: @"Message"]; } @@ -816,7 +815,7 @@ replaceFields(NSDictionary *fields) /* * Perform {field-name} substitutions ... */ - s = replaceFields(m); + s = replaceFields(m, [m objectForKey: @"Replacement"]); while ((d = [e nextObject]) != nil) { [[EcProc cmdLogFile: d] printf: @"%@\n", s]; @@ -838,6 +837,11 @@ replaceFields(NSDictionary *fields) NSString *text; NSString *subject; + /* + * Perform {field-name} substitutions ... + */ + text = replaceFields(m, [m objectForKey: @"Replacement"]); + subject = [m objectForKey: @"Subject"]; if (nil == subject) { @@ -859,15 +863,10 @@ replaceFields(NSDictionary *fields) } else { - AUTORELEASE(RETAIN(subject)); + subject = replaceFields(m, subject); [m removeObjectForKey: @"Subject"]; } - /* - * Perform {field-name} substitutions ... - */ - text = replaceFields(m); - /* If we need to send immediately, don't buffer the message. */ if (nil != identifier) @@ -996,7 +995,7 @@ replaceFields(NSDictionary *fields) */ t = RETAIN([m objectForKey: @"Timestamp"]); [m removeObjectForKey: @"Timestamp"]; - s = replaceFields(m); + s = replaceFields(m, [m objectForKey: @"Replacement"]); if (t != nil) { [m setObject: t forKey: @"Timestamp"];