Diagnostics for alarms

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@39175 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-11-18 11:25:49 +00:00
parent 69a9bcaf56
commit 1f8f656b8b
5 changed files with 61 additions and 45 deletions

View file

@ -3,6 +3,7 @@
* details on what you can configure here. * details on what you can configure here.
*/ */
Debug = NO; /* Defaults ... do not log email alerts sent */ 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 /* 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 * handling alerts, we may do so by specifying the name of a subclass of

View file

@ -1,3 +1,11 @@
2015-11-18 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <niels.grewe@halbordnung.de> 2015-11-18 Niels Grewe <niels.grewe@halbordnung.de>
* EcProcess.m: Fix argument validation when reading/writing defaults. * EcProcess.m: Fix argument validation when reading/writing defaults.

View file

@ -296,6 +296,9 @@
* <term>Debug</term> * <term>Debug</term>
* <desc>A boolean saying whether extra debug data should be logged. * <desc>A boolean saying whether extra debug data should be logged.
* If YES, all outgoing Email messages are logged.</desc> * If YES, all outgoing Email messages are logged.</desc>
* <term>Quiet</term>
* <desc>A boolean saying whether standard debug logs should be suppressed.
* If YES, the handling of alarm messages is not logged.</desc>
* <term>EmailFrom</term> * <term>EmailFrom</term>
* <desc>The sender address to use for outgoing alert Email messages. * <desc>The sender address to use for outgoing alert Email messages.
* By default 'alerter@host' where 'host' is the value defined in * By default 'alerter@host' where 'host' is the value defined in
@ -361,6 +364,7 @@
BOOL debug; /** Debug enabled in config */ BOOL debug; /** Debug enabled in config */
BOOL supersede; /** If a clear should replace original */ BOOL supersede; /** If a clear should replace original */
BOOL eThreaded; /** alarm reminder emails threaded */ BOOL eThreaded; /** alarm reminder emails threaded */
BOOL quiet; /** Quiet enabled in config */
} }
/** Called when user defaults are updated, this fetches the dictionary /** Called when user defaults are updated, this fetches the dictionary
@ -441,10 +445,6 @@
isClear: (BOOL)isClear isClear: (BOOL)isClear
to: (NSArray*)destinations; to: (NSArray*)destinations;
/** Calls -log:identifier:isClear:to: with a nil identifier.
*/
- (void) log: (NSMutableDictionary*)m to: (NSArray*)destinations;
/** Called by /** Called by
* -handleEvent:withHost:andServer:timestamp:identifier:alarm:reminder: * -handleEvent:withHost:andServer:timestamp:identifier:alarm:reminder:
* to pass a message to an array of destinations. * to pass a message to an array of destinations.
@ -456,11 +456,6 @@
isClear: (BOOL)isClear isClear: (BOOL)isClear
to: (NSArray*)destinations; 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.
*/ */
@ -478,10 +473,6 @@
isClear: (BOOL)isClear isClear: (BOOL)isClear
to: (NSArray*)destinations; 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 /** Responsible for the periodic calling of -flushEmail and -flushSms
*/ */
- (void) timeout: (NSTimer*)t; - (void) timeout: (NSTimer*)t;

View file

@ -111,10 +111,24 @@
int duration; int duration;
int reminder; int reminder;
int severity; int severity;
BOOL isAlarm;
BOOL isClear; BOOL isClear;
} }
- (NSString*) alarmText;
@end @end
@implementation EcAlerterEvent @implementation EcAlerterEvent
- (NSString*) alarmText
{
if (NO == isAlarm)
{
return nil;
}
if (YES == isClear)
{
return [identifier stringByAppendingString: @"(clear)"];
}
return [identifier stringByAppendingString: @"(alarm)"];
}
- (void) dealloc - (void) dealloc
{ {
RELEASE(hostName); RELEASE(hostName);
@ -246,6 +260,7 @@ replaceFields(NSDictionary *fields, NSString *template)
- (BOOL) configureWithDefaults: (NSDictionary*)c - (BOOL) configureWithDefaults: (NSDictionary*)c
{ {
debug = [[c objectForKey: @"Debug"] boolValue]; debug = [[c objectForKey: @"Debug"] boolValue];
quiet = [[c objectForKey: @"Quiet"] boolValue];
supersede = [[c objectForKey: @"Supersede"] boolValue]; supersede = [[c objectForKey: @"Supersede"] boolValue];
[self _setEFrom: [c objectForKey: @"EmailFrom"]]; [self _setEFrom: [c objectForKey: @"EmailFrom"]];
ASSIGNCOPY(eHost, [c objectForKey: @"EmailHost"]); ASSIGNCOPY(eHost, [c objectForKey: @"EmailHost"]);
@ -956,6 +971,10 @@ replaceFields(NSDictionary *fields, NSString *template)
} }
} }
[event->m setObject: s forKey: @"Replacement"]; [event->m setObject: s forKey: @"Replacement"];
if (YES == event->isAlarm && NO == quiet)
{
NSLog(@"Send Email for %@ to %@", [event alarmText], o);
}
[self mail: event->m [self mail: event->m
identifier: event->identifier identifier: event->identifier
isClear: event->isClear isClear: event->isClear
@ -1012,6 +1031,10 @@ replaceFields(NSDictionary *fields, NSString *template)
} }
} }
[event->m setObject: s forKey: @"Replacement"]; [event->m setObject: s forKey: @"Replacement"];
if (YES == event->isAlarm && NO == quiet)
{
NSLog(@"Send Email for %@ to %@", [event alarmText], o);
}
[self mail: event->m [self mail: event->m
identifier: event->identifier identifier: event->identifier
isClear: event->isClear isClear: event->isClear
@ -1056,6 +1079,10 @@ replaceFields(NSDictionary *fields, NSString *template)
} }
} }
[event->m setObject: s forKey: @"Replacement"]; [event->m setObject: s forKey: @"Replacement"];
if (YES == event->isAlarm && NO == quiet)
{
NSLog(@"Send SMS for %@ to %@", [event alarmText], o);
}
[self sms: event->m [self sms: event->m
identifier: event->identifier identifier: event->identifier
isClear: event->isClear isClear: event->isClear
@ -1090,12 +1117,20 @@ replaceFields(NSDictionary *fields, NSString *template)
if ([[d objectForKey: @"Stop"] boolValue] == YES) 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. break; // Don't want to perform any more matches.
} }
} }
if (NO == found) 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); NSLog(@"No match of %@ with %@", event->m, rulesArray);
} }
@ -1129,6 +1164,7 @@ replaceFields(NSDictionary *fields, NSString *template)
{ {
event->severity = EcAlarmSeverityIndeterminate; event->severity = EcAlarmSeverityIndeterminate;
event->severityText = @""; event->severityText = @"";
event->isAlarm = NO;
event->isClear = NO; event->isClear = NO;
if (nil != identifier) if (nil != identifier)
{ {
@ -1144,6 +1180,7 @@ replaceFields(NSDictionary *fields, NSString *template)
event->severity = [alarm perceivedSeverity]; event->severity = [alarm perceivedSeverity];
ASSIGN(event->severityText, ASSIGN(event->severityText,
[EcAlarm stringFromSeverity: event->severity]); [EcAlarm stringFromSeverity: event->severity]);
event->isAlarm = YES;
if ([@"Clear" isEqual: [alarm extra]]) if ([@"Clear" isEqual: [alarm extra]])
{ {
event->isClear = YES; event->isClear = YES;
@ -1192,6 +1229,10 @@ replaceFields(NSDictionary *fields, NSString *template)
[m setObject: event->text forKey: @"Message"]; [m setObject: event->text forKey: @"Message"];
[m setObject: event->text forKey: @"Original"]; [m setObject: event->text forKey: @"Original"];
if (YES == event->isAlarm && NO == quiet)
{
NSLog(@"Handling %@ ... %@", [event alarmText], alarm);
}
[self applyRules: rules toEvent: event]; [self applyRules: rules toEvent: event];
} }
NS_HANDLER 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 - (void) mail: (NSMutableDictionary*)m
identifier: (NSString*)identifier identifier: (NSString*)identifier
isClear: (BOOL)isClear 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 - (void) sms: (NSMutableDictionary*)m
identifier: (NSString*)identifier identifier: (NSString*)identifier
isClear: (BOOL)isClear 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 - (void) timeout: (NSTimer*)t
{ {
[self flushSms]; [self flushSms];

View file

@ -3045,28 +3045,19 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval);
[cmdDefs setCommand: nil forKey: key]; [cmdDefs setCommand: nil forKey: key];
val = [cmdDefs objectForKey: key]; val = [cmdDefs objectForKey: key];
} }
else if ([msg count] > 2 else if ([msg count] > 3
&& (([mode caseInsensitiveCompare: @"set"] == NSOrderedSame) && [mode caseInsensitiveCompare: @"set"] == NSOrderedSame)
|| [mode caseInsensitiveCompare: @"write"] == NSOrderedSame)
)
{ {
if ([msg count] < 4)
{
[self cmdPrintf: @"Missing argument (please provide a value to write).\n"];
return;
}
val = [msg objectAtIndex: 3]; val = [msg objectAtIndex: 3];
[cmdDefs setCommand: val forKey: key]; [cmdDefs setCommand: val forKey: key];
val = [cmdDefs objectForKey: key]; val = [cmdDefs objectForKey: key];
} }
else if ([mode caseInsensitiveCompare: @"read"] == NSOrderedSame)
{
val = [cmdDefs objectForKey: key];
}
else else
{ {
[self cmdPrintf: @"Invalid subcommand: '%@'\n", mode]; /* To be tolerant of typing errors, anything else is
return; * treated as a 'read'
*/
val = [cmdDefs objectForKey: key];
} }
if (val == old || [val isEqual: old]) if (val == old || [val isEqual: old])
{ {