diff --git a/ChangeLog b/ChangeLog index 999ebd6..d4e970a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-09-02 Richard Frith-Macdonald + + * EcControl.m: If a Command server on a host registers and we already + have a Command server registered, have the new registration replace + the old one rather than rejecting it. The aim is to handle a race + condition where a Command server is re-registering after some network + problem and the old registration is still in place. + * EcAlerter.m: Add more debug logging to show what elarms/alerts are + handled by what rules. + 2014-07-30 Richard Frith-Macdonald * EcProcess.h: diff --git a/EcAlerter.m b/EcAlerter.m index e5d7f66..23c9e2b 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -441,6 +441,7 @@ replaceFields(NSDictionary *fields, NSString *template) toEvent: (EcAlerterEvent*)event { CREATE_AUTORELEASE_POOL(pool); + BOOL found = NO; NSUInteger i; for (i = 0; i < [rulesArray count]; i++) @@ -544,6 +545,13 @@ replaceFields(NSDictionary *fields, NSString *template) [event->m setObject: match forKey: @"Match"]; } + + found = YES; + if (YES == debug) + { + NSLog(@"Rule %u matched %@ with %@", (unsigned)i, d, event->m); + } + /* * If the Extra1 or Extra2 patterns are matched, * The matching strings are made available for @@ -801,6 +809,13 @@ replaceFields(NSDictionary *fields, NSString *template) break; // Don't want to perform any more matches. } } + if (NO == found) + { + if (YES == debug) + { + NSLog(@"No match of %@ with %@", event->m, rulesArray); + } + } RELEASE(pool); } diff --git a/EcControl.m b/EcControl.m index e31f882..afe86ed 100644 --- a/EcControl.m +++ b/EcControl.m @@ -1829,7 +1829,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) { obj = old; m = [NSString stringWithFormat: - @"Re-registered new host with name '%@' at %@\n", + @"Re-registered existing host with name '%@' at %@\n", n, [NSDate date]]; [self information: m type: LT_AUDIT @@ -1846,50 +1846,27 @@ static NSString* cmdWord(NSArray* a, unsigned int pos) with: self]; old = (CommandInfo*)[self findIn: commands byName: n]; - if (old != nil) - { - NS_DURING - { - [[old obj] cmdPing: self sequence: 0 extra: nil]; - } - NS_HANDLER - { - NSLog(@"Ping %@ - Caught: %@", n, localException); - } - NS_ENDHANDLER - } - - if ((old = (CommandInfo*)[self findIn: commands byName: n]) != nil) - { - RELEASE(obj); - m = [NSString stringWithFormat: - @"Rejected new host with name '%@' at %@\n", - n, [NSDate date]]; - [self information: m - type: LT_AUDIT - to: nil - from: nil]; - [dict setObject: @"client with that name already registered." - forKey: @"rejected"]; - return [NSPropertyListSerialization - dataFromPropertyList: dict - format: NSPropertyListBinaryFormat_v1_0 - errorDescription: 0]; - } + [commands addObject: obj]; + RELEASE(obj); + [commands sortUsingSelector: @selector(compare:)]; + if (nil == old) + { + m = [NSString stringWithFormat: + @"Registered new host with name '%@' at %@\n", + n, [NSDate date]]; + [self domanage: EcMakeManagedObject(n, @"Command", nil)]; + } else - { - [commands addObject: obj]; - RELEASE(obj); - [commands sortUsingSelector: @selector(compare:)]; - [self domanage: EcMakeManagedObject(n, @"Command", nil)]; - m = [NSString stringWithFormat: - @"Registered new host with name '%@' at %@\n", - n, [NSDate date]]; - [self information: m - type: LT_AUDIT - to: nil - from: nil]; - } + { + m = [NSString stringWithFormat: + @"Re-registered new host with name '%@' at %@\n", + n, [NSDate date]]; + [commands removeObjectIdenticalTo: old]; + } + [self information: m + type: LT_AUDIT + to: nil + from: nil]; } /* Inform SNMP monitoring of new Command server.