#-*- coding: UTF-8-* #!/usr/bin/python # # Development script (not a final version) import sys, os import socket import argparse import xml.etree.ElementTree as ET import logging from shutil import copyfile reload(sys) sys.setdefaultencoding('utf-8') Type = sys.getfilesystemencoding() ## Variables Environment = "" phCustId = "= 9: severityCat = "HIGH" #organization = root.attrib.get("organization") if root.attrib.get("organization") is not None else "" incidentId = root.attrib.get("incidentId") if root.attrib.get("incidentId") is not None else "" rawEvents = root.findtext('rawEvents') if root.findtext("rawEvents") is not None else "" name = root.findtext('name') if root.findtext("name") is not None else "" new_raw_message = str(rawEvents).splitlines() messages = [] for line in new_raw_message: line = line.strip() if line != "": messages.append("phCustId=" + str(phCustId) + ", RAW=" + str(line)) def syslog(messages, level=5, facility=3, host='', port=514): """ Send syslog UDP packet to given host and port. """ for m in messages[1:]: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) data = '<%d>%s' % (5 + 3*8, m) sock.sendto(data.encode(), ('', 514)) sock.close() if __name__=="__main__": syslog(messages,level,host,port)