diff --git a/AlertConfig.plist b/AlertConfig.plist index cf71106..a7f7c46 100644 --- a/AlertConfig.plist +++ b/AlertConfig.plist @@ -3,6 +3,7 @@ * details on what you can configure here. */ Debug = NO; /* Defaults ... do not log email alerts sent */ + Quiet = NO; /* Defaults ... suppress logging of alarms */ /* If we wish to extend/oeverride the function of the EcAlerter class in * handling alerts, we may do so by specifying the name of a subclass of diff --git a/ChangeLog b/ChangeLog index 6388955..8748937 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-11-18 Richard Frith-Macdonald + + * EcProcess.m: Improve output when changing/reading defaults, and + restore tolerant behavior of doing a read by default. + * ECAlerter.h: + * ECAlerter.m: Remove obsolete methods, and a 'Quiet' configuration + option, and log alarms (and their disposition) by default. + 2015-11-18 Niels Grewe * EcProcess.m: Fix argument validation when reading/writing defaults. diff --git a/EcAlerter.h b/EcAlerter.h index c8fc66a..97a1f61 100644 --- a/EcAlerter.h +++ b/EcAlerter.h @@ -296,6 +296,9 @@ * Debug * A boolean saying whether extra debug data should be logged. * If YES, all outgoing Email messages are logged. + * Quiet + * A boolean saying whether standard debug logs should be suppressed. + * If YES, the handling of alarm messages is not logged. * EmailFrom * The sender address to use for outgoing alert Email messages. * By default 'alerter@host' where 'host' is the value defined in @@ -361,6 +364,7 @@ BOOL debug; /** Debug enabled in config */ BOOL supersede; /** If a clear should replace original */ BOOL eThreaded; /** alarm reminder emails threaded */ + BOOL quiet; /** Quiet enabled in config */ } /** Called when user defaults are updated, this fetches the dictionary @@ -441,10 +445,6 @@ 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:identifier:alarm:reminder: * to pass a message to an array of destinations. @@ -456,11 +456,6 @@ 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. */ @@ -478,10 +473,6 @@ 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 */ - (void) timeout: (NSTimer*)t; diff --git a/EcAlerter.m b/EcAlerter.m index fc98403..ea26d96 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -111,10 +111,24 @@ int duration; int reminder; int severity; + BOOL isAlarm; BOOL isClear; } +- (NSString*) alarmText; @end @implementation EcAlerterEvent +- (NSString*) alarmText +{ + if (NO == isAlarm) + { + return nil; + } + if (YES == isClear) + { + return [identifier stringByAppendingString: @"(clear)"]; + } + return [identifier stringByAppendingString: @"(alarm)"]; +} - (void) dealloc { RELEASE(hostName); @@ -246,6 +260,7 @@ replaceFields(NSDictionary *fields, NSString *template) - (BOOL) configureWithDefaults: (NSDictionary*)c { debug = [[c objectForKey: @"Debug"] boolValue]; + quiet = [[c objectForKey: @"Quiet"] boolValue]; supersede = [[c objectForKey: @"Supersede"] boolValue]; [self _setEFrom: [c objectForKey: @"EmailFrom"]]; ASSIGNCOPY(eHost, [c objectForKey: @"EmailHost"]); @@ -956,6 +971,10 @@ replaceFields(NSDictionary *fields, NSString *template) } } [event->m setObject: s forKey: @"Replacement"]; + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"Send Email for %@ to %@", [event alarmText], o); + } [self mail: event->m identifier: event->identifier isClear: event->isClear @@ -1012,6 +1031,10 @@ replaceFields(NSDictionary *fields, NSString *template) } } [event->m setObject: s forKey: @"Replacement"]; + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"Send Email for %@ to %@", [event alarmText], o); + } [self mail: event->m identifier: event->identifier isClear: event->isClear @@ -1056,6 +1079,10 @@ replaceFields(NSDictionary *fields, NSString *template) } } [event->m setObject: s forKey: @"Replacement"]; + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"Send SMS for %@ to %@", [event alarmText], o); + } [self sms: event->m identifier: event->identifier isClear: event->isClear @@ -1090,12 +1117,20 @@ replaceFields(NSDictionary *fields, NSString *template) if ([[d objectForKey: @"Stop"] boolValue] == YES) { + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"Stop %@ with %@", [event alarmText], d); + } break; // Don't want to perform any more matches. } } if (NO == found) { - if (YES == debug) + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"No match of %@ with %@", [event alarmText], rulesArray); + } + else if (YES == debug) { NSLog(@"No match of %@ with %@", event->m, rulesArray); } @@ -1129,6 +1164,7 @@ replaceFields(NSDictionary *fields, NSString *template) { event->severity = EcAlarmSeverityIndeterminate; event->severityText = @""; + event->isAlarm = NO; event->isClear = NO; if (nil != identifier) { @@ -1144,6 +1180,7 @@ replaceFields(NSDictionary *fields, NSString *template) event->severity = [alarm perceivedSeverity]; ASSIGN(event->severityText, [EcAlarm stringFromSeverity: event->severity]); + event->isAlarm = YES; if ([@"Clear" isEqual: [alarm extra]]) { event->isClear = YES; @@ -1192,6 +1229,10 @@ replaceFields(NSDictionary *fields, NSString *template) [m setObject: event->text forKey: @"Message"]; [m setObject: event->text forKey: @"Original"]; + if (YES == event->isAlarm && NO == quiet) + { + NSLog(@"Handling %@ ... %@", [event alarmText], alarm); + } [self applyRules: rules toEvent: event]; } NS_HANDLER @@ -1330,11 +1371,6 @@ replaceFields(NSDictionary *fields, NSString *template) } } -- (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 @@ -1551,12 +1587,6 @@ replaceFields(NSDictionary *fields, NSString *template) } } -- (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 @@ -1611,11 +1641,6 @@ replaceFields(NSDictionary *fields, NSString *template) } } -- (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations -{ - [self sms: m identifier: nil isClear: NO to: destinations]; -} - - (void) timeout: (NSTimer*)t { [self flushSms]; diff --git a/EcProcess.m b/EcProcess.m index 58a50fa..3c911f2 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -3045,28 +3045,19 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); [cmdDefs setCommand: nil forKey: key]; val = [cmdDefs objectForKey: key]; } - else if ([msg count] > 2 - && (([mode caseInsensitiveCompare: @"set"] == NSOrderedSame) - || [mode caseInsensitiveCompare: @"write"] == NSOrderedSame) - ) + else if ([msg count] > 3 + && [mode caseInsensitiveCompare: @"set"] == NSOrderedSame) { - if ([msg count] < 4) - { - [self cmdPrintf: @"Missing argument (please provide a value to write).\n"]; - return; - } val = [msg objectAtIndex: 3]; [cmdDefs setCommand: val forKey: key]; val = [cmdDefs objectForKey: key]; } - else if ([mode caseInsensitiveCompare: @"read"] == NSOrderedSame) - { - val = [cmdDefs objectForKey: key]; - } else { - [self cmdPrintf: @"Invalid subcommand: '%@'\n", mode]; - return; + /* To be tolerant of typing errors, anything else is + * treated as a 'read' + */ + val = [cmdDefs objectForKey: key]; } if (val == old || [val isEqual: old]) {