regex - Parsing IBM server error message in Java -


i have error message need parse.

dsnl027i  agentname server distributed agent         luwid=xx00000.x000.xx0000000x00=00000         thread-info=xxxx00:255.255.255.255:xxxx00:application_name:*:*:*:*         received abend=00x         reason=00000000 

there thousands of these messages need parse. follow similar pattern 1 below.

dsnl027i agent-type distributed agent          luwid luw-id=token          thread-info thread-information          received abend=abend-code          reason=reason-code 

additionally, these patterns available on ibm documentation site.

http://www-01.ibm.com/support/knowledgecenter/ssepek_10.0.0/com.ibm.db2z10.doc.msgs/src/msgs/db2z_msgs.dita

i need capture of fields in message , create xml object, example given error message below.

    <agent-type>agentname</agent-type>     <luwid>xx00000.x000.xx0000000x00</luwid>     <token>00000</token>     <thread-information>xxxx00:255.255.255.255:xxxx00:application_name:*:*:*:*</thread-information>     <abend-code>00x</abend-code>     <reason-code>00000000</reason-code> 

using regular expressions match messages easy , makes sense.

is there simple programmatic method can take pattern (lowercase characters) , pull out corresponding values in actual message?

try this:

\s* (\s*) distributed agent with\s*luwid (\s*)=(\s*)\s*thread-info (\s*)\s*received abend=(\s*)\s*for reason=(\s*)$ 

(note: in java, you'll use double backslash escape chars: \\)

replace with:

<agent-type>$1</agent-type>\n<luwid>$2</luwid>\n<token>$3</token>\n<thread-information>$4</thread-information>\n<abend-code>$5</abend-code>\n<reason-code>$6</reason-code> 

output:

<agent-type>agent-type</agent-type> <luwid>luw-id</luwid> <token>token</token> <thread-information>thread-information</thread-information> <abend-code>abend-code</abend-code> <reason-code>reason-code</reason-code> 

play around here: https://regex101.com/r/yy2am6/2


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -