how to add a field depending on different judgment statement

Tags:

#1 tuankun

Hi All,

   I use nxlog-ce-2.9.1504 to read log and parse it,the format of log is like:

20160523 10:58:22 sda              0      0    0    0      14      2    2    9       9     1     1      0    0

20160523 10:58:22 sdb              0      3    2    0      20      4    8    4       2     5     1      7    2

I want get the purpose:

if the third field is "sda",nxlog automatically add a string value "disk1" at the tail of  the same row,if "sdb",add "disk2",like

20160523 10:58:22 sda              0      0    0    0      14      2    2    9       9     1     1      0    0  disk1

20160523 10:58:22 sdb              0      3    2    0      20      4    8    4       2     5     1      7    2  disk2

 

I configure the nxlog.conf as following,but it can not add any fields,I don't know where the mistake,anybody could help me? thanks so so so much~

<Extension kvp>
    Module      xm_kvp
</Extension>

<Input perf>
    Module      im_file
    File        "/collectl/LKNODE01*.dsk"
    SavePos     FALSE
    ReadFromLast FALSE
    Exec    if $raw_event =~ /^(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/\
                 {\
                        kvp->parse_kvp();\
                        if $3 == "sda" $raw_event = $raw_event + " disk1";\

                        else if $3 == "sdb" $raw_event = $raw_event + " disk2";\
                }
</Input>

<Output file>
    Module      om_file
    file        '/tmp/2.txt'
</Output>


<Route 1>
    Path        perf=> file
</Route>

#2 adm Nxlog ✓
#1 tuankun
Hi All,    I use nxlog-ce-2.9.1504 to read log and parse it,the format of log is like: 20160523 10:58:22 sda              0      0    0    0      14      2    2    9       9     1     1      0    0 20160523 10:58:22 sdb              0      3    2    0      20      4    8    4       2     5     1      7    2 I want get the purpose: if the third field is "sda",nxlog automatically add a string value "disk1" at the tail of  the same row,if "sdb",add "disk2",like 20160523 10:58:22 sda              0      0    0    0      14      2    2    9       9     1     1      0    0  disk1 20160523 10:58:22 sdb              0      3    2    0      20      4    8    4       2     5     1      7    2  disk2   I configure the nxlog.conf as following,but it can not add any fields,I don't know where the mistake,anybody could help me? thanks so so so much~ <Extension kvp>     Module      xm_kvp </Extension> <Input perf>     Module      im_file     File        "/collectl/LKNODE01*.dsk"     SavePos     FALSE     ReadFromLast FALSE     Exec    if $raw_event =~ /^(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/\                  {\                         kvp->parse_kvp();\                         if $3 == "sda" $raw_event = $raw_event + " disk1";\                         else if $3 == "sdb" $raw_event = $raw_event + " disk2";\                 } </Input> <Output file>     Module      om_file     file        '/tmp/2.txt' </Output> <Route 1>     Path        perf=> file </Route>

This is not KVP. You can either parse it with a regular expression like you do (though that needs to be fixed) or use xm_csv - parse_csv().