def processpkt(self, drone, _unused_srcaddr, _unused_jsonobj, _discoverychanged): '''Send commands to monitor host aspects for the given System. We ignore discoverychanged because we always want to monitor even if a system has just come up with the same discovery as before it went down. ''' drone.monitors_activated = True #self.log.debug('In DiscoveryGenerateHostMonitoring::processpkt for %s with %s (%s)' # % (drone, _discoverychanged, str(_unused_jsonobj))) montuples = MonitoringRule.findallmatches((drone, ), objclass='host') for montuple in montuples: if montuple[0] == MonitoringRule.NOMATCH: continue elif montuple[0] == MonitoringRule.PARTMATCH: print >> sys.stderr, ( 'Automatic host monitoring of %s not possible with %s: missing %s' % (drone.designation, str(montuple[1]), str(montuple[2]))) self.log.warning( 'Insufficient information to monitor host %s' ' using %s: %s is missing.' % (drone.designation, str(montuple[1]), str(montuple[2]))) else: agent = montuple[1] self._add_service_monitoring(drone, drone, agent) print >> sys.stderr, ( 'START monitoring host %s using %s:%s agent' % (drone.designation, agent['monitorclass'], agent['monitortype']))
def processpkt(self, drone, unused_srcaddr, unused_jsonobj): "Send commands to monitor host aspects for the given Drone" unused_srcaddr = unused_srcaddr unused_jsonobj = unused_jsonobj drone.monitors_activated = True montuples = MonitoringRule.findallmatches((drone, ), objclass='host') for montuple in montuples: if montuple[0] == MonitoringRule.NOMATCH: continue elif montuple[0] == MonitoringRule.PARTMATCH: print >> sys.stderr, ( 'Automatic host monitoring of %s not possible with %s: missing %s' % (drone.designation, str(montuple[1]), str(montuple[2]))) self.log.warning( 'Insufficient information to monitor host %s' ' using %s: %s is missing.' % (drone.designation, str(montuple[1]), str(montuple[2]))) else: agent = montuple[1] self._add_service_monitoring(drone, drone, agent) print >> sys.stderr, ( 'START monitoring host %s using %s:%s agent' % (drone.designation, agent['monitorclass'], agent['monitortype']))
def processpkt(self, drone, _unused_srcaddr, _unused_jsonobj, _discoverychanged): '''Send commands to monitor host aspects for the given System. We ignore discoverychanged because we always want to monitor even if a system has just come up with the same discovery as before it went down. ''' drone.monitors_activated = True #self.log.debug('In DiscoveryGenerateHostMonitoring::processpkt for %s with %s (%s)' # % (drone, _discoverychanged, str(_unused_jsonobj))) montuples = MonitoringRule.findallmatches((drone,), objclass='host') for montuple in montuples: if montuple[0] == MonitoringRule.NOMATCH: continue elif montuple[0] == MonitoringRule.PARTMATCH: print >> sys.stderr, ( 'Automatic host monitoring of %s not possible with %s: missing %s' % (drone.designation, str(montuple[1]), str(montuple[2]))) self.log.warning('Insufficient information to monitor host %s' ' using %s: %s is missing.' % (drone.designation, str(montuple[1]), str(montuple[2]))) else: agent = montuple[1] self._add_service_monitoring(drone, drone, agent) print >> sys.stderr, ('START monitoring host %s using %s:%s agent' % (drone.designation, agent['monitorclass'], agent['monitortype']))
def processpkt(self, drone, unused_srcaddr, unused_jsonobj): "Send commands to monitor host aspects for the given Drone" unused_srcaddr = unused_srcaddr unused_jsonobj = unused_jsonobj drone.monitors_activated = True montuples = MonitoringRule.findallmatches((drone,), objclass='host') for montuple in montuples: if montuple[0] == MonitoringRule.NOMATCH: continue elif montuple[0] == MonitoringRule.PARTMATCH: print >> sys.stderr, ( 'Automatic host monitoring of %s not possible with %s: missing %s' % (drone.designation, str(montuple[1]), str(montuple[2]))) self.log.warning('Insufficient information to monitor host %s' ' using %s: %s is missing.' % (drone.designation, str(montuple[1]), str(montuple[2]))) else: agent = montuple[1] self._add_service_monitoring(drone, drone, agent) print >> sys.stderr, ('START monitoring host %s using %s:%s agent' % (drone.designation, agent['monitorclass'], agent['monitortype']))
def test_automonitor_search_basic(self): drone = FakeDrone({ 'data': { 'ocf': { 'assimilation/neo4j', }, 'lsb': { 'neo4j-service', } } }) MonitoringRule.monitor_objects = {'service': {}, 'host': {}} ocf_string = '''{ "class": "ocf", "type": "neo4j", "provider": "assimilation", "classconfig": [ [null, "@basename()", "java$"], [null, "$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"], ["PORT", "$serviceport"], ["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"] ] }''' MonitoringRule.ConstructFromString(ocf_string) lsb_string = '''{ "class": "lsb", "type": "neo4j-service", "classconfig": [ ["@basename()", "java$"], ["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"], ] }''' MonitoringRule.ConstructFromString(lsb_string) neoprocargs = ( "/usr/bin/java", "-cp", "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:" "AND SO ON:" "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:" "/var/lib/neo4j/conf/", "-server", "-XX:" "+DisableExplicitGC", "-Dneo4j.home=/var/lib/neo4j", "-Dneo4j.instance=/var/lib/neo4j", "-Dfile.encoding=UTF-8", "org.neo4j.server.Bootstrapper") neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs, 'root', 'root', '/', roles=(CMAconsts.ROLE_server, )) #neonode.serviceport=7474 context = ExpressionContext((neonode, drone)) first = MonitoringRule.findbestmatch(context) second = MonitoringRule.findbestmatch(context, False) list1 = MonitoringRule.findallmatches(context) neonode.serviceport = 7474 third = MonitoringRule.findbestmatch(context) list2 = MonitoringRule.findallmatches(context) # first should be the LSB instance self.assertEqual(first[1]['monitorclass'], 'lsb') self.assertEqual(first[0], MonitoringRule.LOWPRIOMATCH) # second should be the incomplete OCF instance self.assertEqual(second[1]['monitorclass'], 'ocf') self.assertEqual(second[0], MonitoringRule.PARTMATCH) # third should be the high priority OCF instance self.assertEqual(third[1]['monitorclass'], 'ocf') self.assertEqual(third[0], MonitoringRule.HIGHPRIOMATCH) # list1 should be the incomplete OCF and the complete LSB - in that order self.assertEqual(len(list1), 2) # They should come out sorted by monitorclass self.assertEqual(list1[0][0], MonitoringRule.LOWPRIOMATCH) self.assertEqual(list1[0][1]['monitorclass'], 'lsb') self.assertEqual(list1[1][0], MonitoringRule.PARTMATCH) self.assertEqual(list1[1][1]['monitorclass'], 'ocf') # third should be a complete OCF match # list2 should be the complete OCF and the complete OCF - in that order self.assertEqual(len(list2), 2) self.assertEqual(list2[0][0], MonitoringRule.LOWPRIOMATCH) self.assertEqual(list2[0][1]['monitorclass'], 'lsb') self.assertEqual(list2[1][0], MonitoringRule.HIGHPRIOMATCH) self.assertEqual(list2[1][1]['monitorclass'], 'ocf')
def test_automonitor_search_basic(self): AssimEvent.disable_all_observers() drone = FakeDrone({ 'data': { 'ocf': { 'assimilation/neo4j', }, 'lsb': { 'neo4j-service', } } }) MonitoringRule.monitor_objects = {'service': {}, 'host':{}} ocf_string = '''{ "class": "ocf", "type": "neo4j", "provider": "assimilation", "classconfig": [ [null, "@basename()", "java$"], [null, "$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"], ["PORT", "$serviceport"], ["NEOHOME", "@argequals(-Dneo4j.home)", "/.*"] ] }''' MonitoringRule.ConstructFromString(ocf_string) lsb_string = '''{ "class": "lsb", "type": "neo4j-service", "classconfig": [ ["@basename()", "java$"], ["$argv[-1]", "org\\.neo4j\\.server\\.Bootstrapper$"], ] }''' MonitoringRule.ConstructFromString(lsb_string) neoprocargs = ("/usr/bin/java", "-cp" , "/var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:" "AND SO ON:" "/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:" "/var/lib/neo4j/conf/", "-server", "-XX:" "+DisableExplicitGC" , "-Dneo4j.home=/var/lib/neo4j" , "-Dneo4j.instance=/var/lib/neo4j" , "-Dfile.encoding=UTF-8" , "org.neo4j.server.Bootstrapper") neonode = ProcessNode('global', 'foofred', 'fred', '/usr/bin/java', neoprocargs , 'root', 'root', '/', roles=(CMAconsts.ROLE_server,)) #neonode.serviceport=7474 context = ExpressionContext((neonode, drone)) first = MonitoringRule.findbestmatch(context) second = MonitoringRule.findbestmatch(context, False) list1 = MonitoringRule.findallmatches(context) neonode.serviceport=7474 third = MonitoringRule.findbestmatch(context) list2 = MonitoringRule.findallmatches(context) # first should be the LSB instance self.assertEqual(first[1]['monitorclass'], 'lsb') self.assertEqual(first[0], MonitoringRule.LOWPRIOMATCH) # second should be the incomplete OCF instance self.assertEqual(second[1]['monitorclass'], 'ocf') self.assertEqual(second[0], MonitoringRule.PARTMATCH) # third should be the high priority OCF instance self.assertEqual(third[1]['monitorclass'], 'ocf') self.assertEqual(third[0], MonitoringRule.HIGHPRIOMATCH) # list1 should be the incomplete OCF and the complete LSB - in that order self.assertEqual(len(list1), 2) # They should come out sorted by monitorclass self.assertEqual(list1[0][0], MonitoringRule.LOWPRIOMATCH) self.assertEqual(list1[0][1]['monitorclass'], 'lsb') self.assertEqual(list1[1][0], MonitoringRule.PARTMATCH) self.assertEqual(list1[1][1]['monitorclass'], 'ocf') # third should be a complete OCF match # list2 should be the complete OCF and the complete OCF - in that order self.assertEqual(len(list2), 2) self.assertEqual(list2[0][0], MonitoringRule.LOWPRIOMATCH) self.assertEqual(list2[0][1]['monitorclass'], 'lsb') self.assertEqual(list2[1][0], MonitoringRule.HIGHPRIOMATCH) self.assertEqual(list2[1][1]['monitorclass'], 'ocf')