From 5fdd699dcffb5a2faf5e4228d22b01e5e2d126df Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 5 Apr 2013 13:50:10 +0000 Subject: [PATCH] allow identifier and clear for individual alerter events git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36467 72102866-910b-0410-8b05-ffd578937521 --- EcAlerter.h | 44 ++++++++++++++++++++++++++++++++++++-------- EcAlerter.m | 52 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/EcAlerter.h b/EcAlerter.h index c5ce52d..1111edf 100644 --- a/EcAlerter.h +++ b/EcAlerter.h @@ -189,9 +189,14 @@ - (void) flushSms; /**

This method handles an error/alert event (an 'error' is one which may - * be buffered, while an 'alert' must be sent immediately). + * be buffered, while an 'alert' must be sent immediately).
+ * If the identifier field is non-nil then the event is an alert which is + * identified by the value of the field and may be 'cleared' by a later + * event with the same identfier and with the isClear flag set. The use + * of an empty string as an identifier is permitted for events which should + * not be buffered, but which will never be matched by a clear. *

- *

Each event must consist of text associated with a host anme, + *

Each event must consist of text associated with a host name, * server name (usually the process on the host) and timestamp. *

*

Each message is matched against each rule in the Rules @@ -205,7 +210,8 @@ withHost: (NSString*)hostName andServer: (NSString*)serverName timestamp: (NSString*)timestamp - immediate: (BOOL)immediate; + identifier: (NSString*)identifier + isClear: (BOOL)isClear; /**

This method handles error/alert messages. It is able to handle * multiple (newline separated messages. @@ -214,34 +220,56 @@ * serverName(hostName): YYYY-MM-DD hh:mm:ss.mmm szzzz type - text *

*

Each message is parsed an then the components are passed to - * the -handleEvent:withHost:andServer:timestamp:immediate: method. + * the -handleEvent:withHost:andServer:timestamp:identifier:isClear: method. *

*/ - (void) handleInfo: (NSString*)str; -/** Called by -handleEvent:withHost:andServer:timestamp:immediate: +/** Called by -handleEvent:withHost:andServer:timestamp:identifier:isClear: * to log a message to an array of destinations. */ +- (void) log: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations; + +/** Calls -log:identifier:isClear:to: with a nil identifier. + */ - (void) log: (NSMutableDictionary*)m to: (NSArray*)destinations; -/** Called by -handleEvent:withHost:andServer:timestamp:immediate: +/** Called by -handleEvent:withHost:andServer:timestamp:identifier:isClear: * to pass a message to an array of destinations. * The message is actually appended to any cached messages for those * destinations ... and the cache is periodically flushed. */ -- (void) mail: (NSMutableDictionary*)m to: (NSArray*)destinations; +- (void) mail: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations; + +/** Calls -mail:identifier:isClear:to: with a nil identifier. + */ +- (void) mail: (NSMutableDictionary*)m + to: (NSArray*)destinations; /** Cache a copy of the Rules with modifications to store information * so we don't need to regenerate it every time we check a message. */ - (BOOL) setRules: (NSArray*)ra; -/** Called by -handleEvent:withHost:andServer:timestamp:immediate: +/** Called by -handleEvent:withHost:andServer:timestamp:identifier:isClear: * to pass a message to an array of destinations. * The message replaces any cached messages for those * destinations (and has a count of the lost messages noted) ... and * the cache is periodically flushed. */ +- (void) sms: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations; + +/** Calls -sms:identifier:isClear:to: with a nil identifier. + */ - (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations; /** Responsible for the periodic calling of -flushEmail and -flushSms diff --git a/EcAlerter.m b/EcAlerter.m index 78e8242..91057f5 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -359,8 +359,13 @@ replaceFields(NSDictionary *fields) withHost: (NSString*)hostName andServer: (NSString*)serverName timestamp: (NSString*)timestamp - immediate: (BOOL)immediate + identifier: (NSString*)identifier + isClear: (BOOL)isClear { + if (nil == identifier) + { + isClear = NO; + } NS_DURING { NSUInteger i; @@ -368,7 +373,7 @@ replaceFields(NSDictionary *fields) NSMutableDictionary *m; - if (YES == immediate) + if (nil != identifier) { type = @"Alert"; } @@ -470,8 +475,7 @@ replaceFields(NSDictionary *fields) s = @"{Message}"; } [m setObject: s forKey: @"Replacement"]; - - [self log: m to: o]; + [self log: m identifier: identifier isClear: isClear to: o]; } } NS_HANDLER @@ -511,8 +515,7 @@ replaceFields(NSDictionary *fields) s = @"{Server}({Host}): {Timestamp} {Type} - {Message}"; } [m setObject: s forKey: @"Replacement"]; - - [self mail: m to: o]; + [self mail: m identifier: identifier isClear: isClear to: o]; } } NS_HANDLER @@ -546,8 +549,7 @@ replaceFields(NSDictionary *fields) s = @"{Server}({Host}):{Timestamp} {Type}-{Message}"; } [m setObject: s forKey: @"Replacement"]; - - [self sms: m to: o]; + [self sms: m identifier: identifier isClear: isClear to: o]; } } NS_HANDLER @@ -658,7 +660,8 @@ replaceFields(NSDictionary *fields) withHost: hostName andServer: serverName timestamp: timestamp - immediate: immediate]; + identifier: (YES == immediate) ? (id)@"" : (id)nil + isClear: NO]; } } NS_HANDLER @@ -687,7 +690,10 @@ replaceFields(NSDictionary *fields) return self; } -- (void) log: (NSMutableDictionary*)m to: (NSArray*)destinations +- (void) log: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations { NSEnumerator *e = [destinations objectEnumerator]; NSString *d; @@ -703,7 +709,15 @@ replaceFields(NSDictionary *fields) } } -- (void) mail: (NSMutableDictionary*)m to: (NSArray*)destinations +- (void) log: (NSMutableDictionary*)m to: (NSArray*)destinations +{ + [self log: m identifier: nil isClear: NO to: destinations]; +} + +- (void) mail: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations { NSEnumerator *e = [destinations objectEnumerator]; NSString *d; @@ -767,7 +781,16 @@ replaceFields(NSDictionary *fields) } } -- (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations +- (void) mail: (NSMutableDictionary*)m to: (NSArray*)destinations +{ + [self mail: m identifier: nil isClear: NO to: destinations]; +} + + +- (void) sms: (NSMutableDictionary*)m + identifier: (NSString*)identifier + isClear: (BOOL)isClear + to: (NSArray*)destinations { NSEnumerator *e = [destinations objectEnumerator]; NSString *d; @@ -818,6 +841,11 @@ replaceFields(NSDictionary *fields) } } +- (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations +{ + [self sms: m identifier: nil isClear: NO to: destinations]; +} + - (void) timeout: (NSTimer*)t { [self flushSms];