def print_alert(alert): try: alert_type = AlertType.find_one_by_code(alert.type) message = alert_type.code + '-' + alert_type.message dict_parameters = json.loads(alert.parameters) collector = DataCollector.find_one(alert.data_collector_id) if collector: message = message.replace( '{' + 'collector.name' + '}', collector.name + ' (ID ' + str(collector.id) + ')') else: message = message.replace('{' + 'collector.name' + '}', str(alert.data_collector_id)) for param_name, param_value in dict_parameters.items(): message = message.replace('{' + param_name + '}', str(param_value)) message = message.replace('{' + 'packet_id' + '}', str(alert.packet_id)) message = message.replace('{' + 'created_at' + '}', alert.created_at.strftime('%Y-%m-%d %H:%M')) except Exception as e: logging.error('Error printing alert: {0}'.format(e)) logging.debug(message)
organization_quant = Organization.count() if organization_quant > 1: print("There are more than one organizations in the DB. Provide the Organization DB explicitly.") elif organization_quant == 1: organization_obj = Organization.find_one() else: organization_obj = Organization(name="Auto-generated Organization") organization_obj.save() # Get the data collector collector_obj = None if options.collector_id: collector_obj = DataCollector.find_one(options.collector_id) if collector_obj is None: print("DataCollector doesn't exist. Please provide a valid ID") exit(0) else: if options.ip and options.port: collector_type_obj = DataCollectorType.find_one_by_type("loraserverio_collector") if collector_type_obj is None: collector_type_obj = DataCollectorType( type="loraserverio_collector", name="loraserverio_collector") collector_type_obj.save()
organization_quant = Organization.count() if organization_quant > 1: print("There are more than one organizations in the DB. Provide the Organization DB explicitly.") elif organization_quant == 1: organization_obj = Organization.find_one() else: organization_obj = Organization(name = "Auto-generated Organization") organization_obj.save() # Get the data collector collector_obj = None if options.collector_id: collector_obj = DataCollector.find_one(options.collector_id) if collector_obj is None: print("DataCollector doesn't exist. Please provide a valid ID") exit(0) else: if options.user and options.pwd and options.gw_id: collector_type_obj = DataCollectorType.find_one_by_type("ttn_collector") if collector_type_obj is None: collector_type_obj= DataCollectorType( type = "ttn_collector", name= "ttn_collector") collector_type_obj.save()
organization_quant = Organization.count() if organization_quant > 1: print("There are more than one organizations in the DB. Provide the Organization DB explicitly.") elif organization_quant == 1: organization_obj = Organization.find_one() else: organization_obj = Organization(name = "Auto-generated Organization") organization_obj.save() # Get the data collector collector_obj = None if options.collector_id: collector_obj = DataCollector.find_one(options.collector_id) if collector_obj is None: print("DataCollector doesn't exist. Please provide a valid ID") exit(0) else: if options.port: collector_type_obj = DataCollectorType.find_one_by_type("forwarder_collector") if collector_type_obj is None: collector_type_obj= DataCollectorType( type = "forwarder_collector", name= "forwarder_collector") collector_type_obj.save()
if organization_quant > 1: print( "There are more than one organizations in the DB. Provide the Organization DB explicitly." ) elif organization_quant == 1: organization_obj = Organization.find_one() else: organization_obj = Organization(name="Auto-generated Organization") organization_obj.save() # Get the data collector collector_obj = None if options.collector_id: collector_obj = DataCollector.find_one(options.collector_id) if collector_obj is None: print("DataCollector doesn't exist. Please provide a valid ID") exit(0) else: if options.ip and options.port: collector_type_obj = DataCollectorType.find_one_by_type( "generic_collector") if collector_type_obj is None: collector_type_obj = DataCollectorType( type="generic_collector", name="generic_collector") collector_type_obj.save()