コード例 #1
0
ファイル: rules.py プロジェクト: jnovinger/monscale
def evaluate():
    mappings = get_mappings()
       
    for service in MonitoredService.objects.filter(active=True):
        logging.debug("[rules_evaluate]############################################### %s ###########################" % service)
        table = RuleTable("Service Rule", mappings, "RegexParser",
             #rawfile,
            "RAWFile",
            None)
        table.setPolicy(False)
              
        table.addRule(service.to_pypelib())
        
        if settings.DEBUG:
            table.dump()
    
        try:
            ctxt = {"service": service}
            table.evaluate(ctxt)
            logging.info("[evaluate] service: %s has evaluate ALARM" % service)
            set_indicator(ctxt)
        except Exception, er:
            try:
                logging.debug("[evaluate] threshold has evaluate no alarm: %s" % er)
                service.alarm_indicators.get().delete()
            except AlarmIndicator.DoesNotExist: pass
            print("No ha cumplido para el servicio: %s" % service)
        logging.debug("[rules_evalute] iteration ended")
コード例 #2
0
ファイル: rules.py プロジェクト: jnovinger/monscale
def evaluate_traps():
    mappings = get_mappings()
    while True:                
        monitored_service, rule = MonitoredService.from_redis_trap()
        if monitored_service is None: break
        
        logging.debug("[evaluate_traps] retrieved trap: %s" % rule)
        table = RuleTable("Trap rule", mappings, "RegexParser",
             #rawfile,
            "RAWFile",
            None)
        table.addRule(rule)
        
        if settings.DEBUG:  table.dump()
    
        try:
            ctxt = {"service": monitored_service}
            table.evaluate(ctxt)
            logging.info("[evaluate_traps] service: %s has evaluate ALARM" % monitored_service)
            set_indicator(ctxt)
        except Exception, er:
            try:
                logging.debug("[evaluate_traps] threshold has evaluate no alarm, exception: %s" % er)
                monitored_service.alarm_indicators.get().delete()
            except AlarmIndicator.DoesNotExist: pass
            print("No ha cumplido para el servicio: %s" % monitored_service)
コード例 #3
0
ファイル: Django.py プロジェクト: jnovinger/monscale
	def load(tableName, mappings, parser):
		Django.logger.info('Django.load')
		try:
			Table =  PolicyRuleTableModel.objects.get(name = tableName)
		# Translation of exceptions: Django -> PyPElib
		except ObjectDoesNotExist:
			raise ZeroPolicyObjectsReturned("[Django Driver] There is no table with name: " + tableName)
		except MultipleObjectsReturned:
			raise MultiplePolicyObjectsReturned("[Django Driver] There are multiple tables with name: " + tableName)
		except Exception as e:
			raise Exception("[Django Driver] Some error occurred when trying to fetch table table with name: " + tableName + ". Exception: " + str(e))
		print "type de table %s" % Table.type
		ruleTable = RuleTable(Table.name,mappings,Table.defaultParser, Table.defaultPersistence,False, eval(Table.type), Table.uuid)
		ruleTable._ruleSet = Django.loadRuleSet(Table.uuid)
		ruleTable._persist = Table.defaultPersistenceFlag
		ruleTable._mappings = mappings
		ruleTable._resolver = Resolver(mappings)
		return ruleTable