Hi, I am using a python parser for parsing the incoming message from syslog-ng. In my log messages some fields are optional and some are not.I want to know how to handle these optional parameters in the python regual expression. for example: sample log :-> log='Sep 15 22:23:37 ecis007 codeSystemName=5 UserID="Admin"' regular expression :-> aregex=re.compile(r"(?P<destmonth>\S+) (?P<devicedate>\S+) (?P<devtime>\S+) (?P<devicename>\S+) codeSystemName=(?P<EventIDcodeSystemName>.*)") if I run the following python command then i can get all the parameters r=aregex.match(log2) but if "codeSystemName=5" is a optional parameters and it is not in some messages then my parser is not able to parse the message. log='Sep 15 22:23:37 ecis007 UserID="Admin' let me know how to write the regex for optional parameters ? Regards, Vaibhav
Hi, this is not related to syslog-ng, so have a look at: http://docs.python.org/library/re.html and search for lookahead assertion regards, Siem -----Oorspronkelijk bericht----- Van: syslog-ng-bounces@lists.balabit.hu namens Jain, Vaibhav (GE Healthcare) Verzonden: wo 16-9-2009 7:33 Aan: Syslog-ng users' and developers' mailing list Onderwerp: [syslog-ng] Python help Hi, I am using a python parser for parsing the incoming message from syslog-ng. In my log messages some fields are optional and some are not.I want to know how to handle these optional parameters in the python regual expression. for example: sample log :-> log='Sep 15 22:23:37 ecis007 codeSystemName=5 UserID="Admin"' regular expression :-> aregex=re.compile(r"(?P<destmonth>\S+) (?P<devicedate>\S+) (?P<devtime>\S+) (?P<devicename>\S+) codeSystemName=(?P<EventIDcodeSystemName>.*)") if I run the following python command then i can get all the parameters r=aregex.match(log2) but if "codeSystemName=5" is a optional parameters and it is not in some messages then my parser is not able to parse the message. log='Sep 15 22:23:37 ecis007 UserID="Admin' let me know how to write the regex for optional parameters ? Regards, Vaibhav
participants (2)
-
Jain, Vaibhav (GE Healthcare)
-
Siem Korteweg