def loadCSV(typ, idField): """ Local function for loading csv-file into python list Structure: [id] = description @return: Python list of descriptions """ resultList = {} try: logging.debug("-- loading %s.csv", typ) with open(globalVars.script_path+'/csv/'+typ+'.csv') as csvfile: # DictReader expected structure described in first line of csv-file reader = csv.DictReader(csvfile) for row in reader: logging.debug(row) # only import rows with an integer as id, allow subrics though if re.match("^[0-9]+[A-D]?$", row[idField], re.IGNORECASE): try: resultList[row[idField].lower()] = stringConverter.convertToUTF8(row['description']) except: # skip entry in case of an exception pass logging.debug("-- loading csv finished") except: logging.error("loading csvList for typ: %s failed", typ) logging.debug("loading csvList for typ: %s failed", typ, exc_info=True) raise return resultList;
def loadCSV(typ, idField): """ Local function for loading csv-file into python list Structure: [id] = description @return: Python list of descriptions """ resultList = {} try: logging.debug("-- loading %s.csv", typ) with open(globalVars.script_path + '/csv/' + typ + '.csv') as csvfile: # DictReader expected structure described in first line of csv-file reader = csv.DictReader(csvfile) for row in reader: logging.debug(row) # only import rows with an integer as id, allow subrics though if re.match("^[0-9A-F]+$", row[idField], re.IGNORECASE): try: resultList[row[idField].lower( )] = stringConverter.convertToUTF8(row['description']) except: # skip entry in case of an exception pass logging.debug("-- loading csv finished") except: logging.error("loading csvList for typ: %s failed", typ) logging.debug("loading csvList for typ: %s failed", typ, exc_info=True) raise return resultList
def run(typ, freq, data): """ This function is the implementation of the firEmergency-Plugin. It will send the data to an firEmergency-Instance. The configuration for the firEmergency-Connection is set in the config.ini. @type typ: string (ZVEI|POC) @param typ: Typ of the dataset for sending to firEmergency @type data: map of data (structure see readme.md in plugin folder) @param data: Contains the parameter for dispatch to firEmergency. @type freq: string @keyword freq: frequency is not used in this plugin @requires: firEmergency-Configuration has to be set in the config.ini @return: nothing """ try: if configHandler.checkConfig( "firEmergency"): #read and debug the config try: # # connect to firEmergency # firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) firSocket.connect( (globalVars.config.get("firEmergency", "firserver"), globalVars.config.getint("firEmergency", "firport"))) except: logging.error("cannot connect to firEmergency") logging.debug("cannot connect to firEmergency", exc_info=True) # Without connection, plugin couldn't work return else: # # Format given data-structure to xml-string for firEmergency # if typ == "FMS": logging.debug("FMS not supported by firEmgency") elif typ == "ZVEI": logging.debug("ZVEI to firEmergency") try: description = stringConverter.convertToUTF8( data["description"]) firXML = "<event>\n<address>" + data[ "zvei"] + "</address>\n<description>" + description + "</description>\n<message>" + data[ "zvei"] + "</message>\n</event>\n" firSocket.send(firXML) except: logging.error("%s to firEmergency failed", typ) logging.debug("%s to firEmergency failed", typ, exc_info=True) # Without connection, plugin couldn't work return elif typ == "POC": logging.debug("POC to firEmergency") try: # !!! Subric+"XX" because of an Issuse in firEmergency !!! description = stringConverter.convertToUTF8( data["description"]) msg = stringConverter.convertToUTF8(data["msg"]) firXML = "<event>\n<address>" + data[ "ric"] + "</address>\n<status>" + data[ "function"] + "XX</status>\n<description>" + description + "</description>\n<message>" + msg + "</message>\n</event>\n" firSocket.send(firXML) except: logging.error("%s to firEmergency failed", typ) logging.debug("%s to firEmergency failed", typ, exc_info=True) # Without connection, plugin couldn't work return else: logging.warning("Invalid Typ: %s", typ) finally: logging.debug("close firEmergency-Connection") try: firSocket.close() except: pass except: logging.error("unknown error") logging.debug("unknown error", exc_info=True)
def run(typ,freq,data): """ This function is the implementation of the firEmergency-Plugin. It will send the data to an firEmergency-Instance. The configuration for the firEmergency-Connection is set in the config.ini. @type typ: string (ZVEI|POC) @param typ: Typ of the dataset for sending to firEmergency @type data: map of data (structure see readme.md in plugin folder) @param data: Contains the parameter for dispatch to firEmergency. @type freq: string @keyword freq: frequency is not used in this plugin @requires: firEmergency-Configuration has to be set in the config.ini @return: nothing """ try: if configHandler.checkConfig("firEmergency"): #read and debug the config try: # # connect to firEmergency # firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) firSocket.connect((globalVars.config.get("firEmergency", "firserver"), globalVars.config.getint("firEmergency", "firport"))) except: logging.error("cannot connect to firEmergency") logging.debug("cannot connect to firEmergency", exc_info=True) # Without connection, plugin couldn't work return else: # # Format given data-structure to xml-string for firEmergency # if typ == "FMS": logging.debug("FMS not supported by firEmgency") elif typ == "ZVEI": logging.debug("ZVEI to firEmergency") try: description = stringConverter.convertToUTF8(data["description"]) firXML = "<event>\n<address>"+data["zvei"]+"</address>\n<description>"+description+"</description>\n<message>"+data["zvei"]+"</message>\n</event>\n" firSocket.send(firXML) except: logging.error("%s to firEmergency failed", typ) logging.debug("%s to firEmergency failed", typ, exc_info=True) # Without connection, plugin couldn't work return elif typ == "POC": logging.debug("POC to firEmergency") try: # !!! Subric+"XX" because of an Issuse in firEmergency !!! description = stringConverter.convertToUTF8(data["description"]) msg = stringConverter.convertToUTF8(data["msg"]) firXML = "<event>\n<address>"+data["ric"]+"</address>\n<status>"+data["function"]+"XX</status>\n<description>"+description+"</description>\n<message>"+msg+"</message>\n</event>\n" firSocket.send(firXML) except: logging.error("%s to firEmergency failed", typ) logging.debug("%s to firEmergency failed", typ, exc_info=True) # Without connection, plugin couldn't work return else: logging.warning("Invalid Typ: %s", typ) finally: logging.debug("close firEmergency-Connection") try: firSocket.close() except: pass except: logging.error("unknown error") logging.debug("unknown error", exc_info=True)