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
This commit is contained in:
rfm 2013-04-05 13:50:10 +00:00
parent 6427be06f5
commit 5fdd699dcf
2 changed files with 76 additions and 20 deletions

View file

@ -189,9 +189,14 @@
- (void) flushSms; - (void) flushSms;
/** <p>This method handles an error/alert event (an 'error' is one which may /** <p>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).<br />
* 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.
* </p> * </p>
* <p>Each event must consist of text associated with a host anme, * <p>Each event must consist of text associated with a host name,
* server name (usually the process on the host) and timestamp. * server name (usually the process on the host) and timestamp.
* </p> * </p>
* <p>Each message is matched against each rule in the <em>Rules</em> * <p>Each message is matched against each rule in the <em>Rules</em>
@ -205,7 +210,8 @@
withHost: (NSString*)hostName withHost: (NSString*)hostName
andServer: (NSString*)serverName andServer: (NSString*)serverName
timestamp: (NSString*)timestamp timestamp: (NSString*)timestamp
immediate: (BOOL)immediate; identifier: (NSString*)identifier
isClear: (BOOL)isClear;
/** <p>This method handles error/alert messages. It is able to handle /** <p>This method handles error/alert messages. It is able to handle
* multiple (newline separated messages. * multiple (newline separated messages.
@ -214,34 +220,56 @@
* serverName(hostName): YYYY-MM-DD hh:mm:ss.mmm szzzz type - text * serverName(hostName): YYYY-MM-DD hh:mm:ss.mmm szzzz type - text
* </p> * </p>
* <p>Each message is parsed an then the components are passed to * <p>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.
* </p> * </p>
*/ */
- (void) handleInfo: (NSString*)str; - (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. * 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; - (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. * to pass a message to an array of destinations.
* The message is actually appended to any cached messages for those * The message is actually appended to any cached messages for those
* destinations ... and the cache is periodically flushed. * 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 /** 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. * so we don't need to regenerate it every time we check a message.
*/ */
- (BOOL) setRules: (NSArray*)ra; - (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. * to pass a message to an array of destinations.
* The message replaces any cached messages for those * The message replaces any cached messages for those
* destinations (and has a count of the lost messages noted) ... and * destinations (and has a count of the lost messages noted) ... and
* the cache is periodically flushed. * 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; - (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations;
/** Responsible for the periodic calling of -flushEmail and -flushSms /** Responsible for the periodic calling of -flushEmail and -flushSms

View file

@ -359,8 +359,13 @@ replaceFields(NSDictionary *fields)
withHost: (NSString*)hostName withHost: (NSString*)hostName
andServer: (NSString*)serverName andServer: (NSString*)serverName
timestamp: (NSString*)timestamp timestamp: (NSString*)timestamp
immediate: (BOOL)immediate identifier: (NSString*)identifier
isClear: (BOOL)isClear
{ {
if (nil == identifier)
{
isClear = NO;
}
NS_DURING NS_DURING
{ {
NSUInteger i; NSUInteger i;
@ -368,7 +373,7 @@ replaceFields(NSDictionary *fields)
NSMutableDictionary *m; NSMutableDictionary *m;
if (YES == immediate) if (nil != identifier)
{ {
type = @"Alert"; type = @"Alert";
} }
@ -470,8 +475,7 @@ replaceFields(NSDictionary *fields)
s = @"{Message}"; s = @"{Message}";
} }
[m setObject: s forKey: @"Replacement"]; [m setObject: s forKey: @"Replacement"];
[self log: m identifier: identifier isClear: isClear to: o];
[self log: m to: o];
} }
} }
NS_HANDLER NS_HANDLER
@ -511,8 +515,7 @@ replaceFields(NSDictionary *fields)
s = @"{Server}({Host}): {Timestamp} {Type} - {Message}"; s = @"{Server}({Host}): {Timestamp} {Type} - {Message}";
} }
[m setObject: s forKey: @"Replacement"]; [m setObject: s forKey: @"Replacement"];
[self mail: m identifier: identifier isClear: isClear to: o];
[self mail: m to: o];
} }
} }
NS_HANDLER NS_HANDLER
@ -546,8 +549,7 @@ replaceFields(NSDictionary *fields)
s = @"{Server}({Host}):{Timestamp} {Type}-{Message}"; s = @"{Server}({Host}):{Timestamp} {Type}-{Message}";
} }
[m setObject: s forKey: @"Replacement"]; [m setObject: s forKey: @"Replacement"];
[self sms: m identifier: identifier isClear: isClear to: o];
[self sms: m to: o];
} }
} }
NS_HANDLER NS_HANDLER
@ -658,7 +660,8 @@ replaceFields(NSDictionary *fields)
withHost: hostName withHost: hostName
andServer: serverName andServer: serverName
timestamp: timestamp timestamp: timestamp
immediate: immediate]; identifier: (YES == immediate) ? (id)@"" : (id)nil
isClear: NO];
} }
} }
NS_HANDLER NS_HANDLER
@ -687,7 +690,10 @@ replaceFields(NSDictionary *fields)
return self; 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]; NSEnumerator *e = [destinations objectEnumerator];
NSString *d; 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]; NSEnumerator *e = [destinations objectEnumerator];
NSString *d; 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]; NSEnumerator *e = [destinations objectEnumerator];
NSString *d; 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 - (void) timeout: (NSTimer*)t
{ {
[self flushSms]; [self flushSms];