[ZBX-12662] Preprocessing with regex issue Created: 2017 Sep 02  Updated: 2017 Sep 02  Resolved: 2017 Sep 02

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 3.4.1
Fix Version/s: None

Type: Incident report Priority: Minor
Reporter: Vitaly Zhuravlev Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: preprocessing, regexps
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello, i'm trying to parse the following 'table' with regex:

smartctl 6.4 2015-06-04 r4109 [i686-w64-mingw32-win7(64)-sp1] (sf-6.4-1)

Copyright (C) 2002-15, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===

SMART Attributes Data Structure revision number: 1

Vendor Specific SMART Attributes with Thresholds:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE

5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0

9 Power_On_Hours          0x0032   098   098   000    Old_age   Always       -       6357

12 Power_Cycle_Count       0x0032   097   097   000    Old_age   Always       -       2337

177 Wear_Leveling_Count     0x0013   096   096   000    Pre-fail  Always       -       69

179 Used_Rsvd_Blk_Cnt_Tot   0x0013   100   100   010    Pre-fail  Always       -       0

181 Program_Fail_Cnt_Total  0x0032   100   100   010    Old_age   Always       -       0

182 Erase_Fail_Count_Total  0x0032   100   100   010    Old_age   Always       -       0

183 Runtime_Bad_Block       0x0013   100   100   010    Pre-fail  Always       -       0

187 Uncorrectable_Error_Cnt 0x0032   100   100   000    Old_age   Always       -       0

190 Airflow_Temperature_Cel 0x0032   065   051   000    Old_age   Always       -       35

195 ECC_Error_Rate          0x001a   200   200   000    Old_age   Always       -       0

199 CRC_Error_Count         0x003e   099   099   000    Old_age   Always       -       11

235 POR_Recovery_Count      0x0012   099   099   000    Old_age   Always       -       86

241 Total_LBAs_Written      0x0032   099   099   000    Old_age   Always       -       28271920601

I need to grab raw value of Reallocated sectors count:

5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0

In dependent item I tried to use the following regex:

5 Reallocated.+\s([0-9]+), \1

But that returned the following string(the first value on the NEXT line actually):

9

I then switched to

5 Reallocated.+ ([0-9]+), \1

And that worked and returned me '0'

Could it be that it is because \s doesn't match space and only newline chars?
and according to http://www.pcre.org/original/doc/html/pcrepattern.html
it should match space as well.

For example, online tool https://regex101.com/ returns 0 for both regexes.

Correct if I'm wrong



 Comments   
Comment by Vladislavs Sokurenko [ 2017 Sep 02 ]

have you tried grep -E on the file ? can you please attach this file.

For example if it's

5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -	0
9 Power_On_Hours          0x0032   098   098   000    Old_age   Always       -       6357

Then regex101 also match 9 because

\s

equals

[\r\n\t\f\v ]

so it matches everything until last white space, in this case new line is last and then takes the number after new line, but if you have 2 new lines then it does not match, but are those 2 lines some extra formatting inserted by some kind of editor when you copied from a file ?
Judging by log lines it's windows so could have something to do with carriage return \r\n sequence

Comment by Glebs Ivanovskis (Inactive) [ 2017 Sep 02 ]

Dear vzhuravlev, maybe that's because you had literal space in the end of your first regexp?

Comment by Vitaly Zhuravlev [ 2017 Sep 02 ]

glebs.ivanovskis, it was Jira typo, fixed in description.

Comment by Vitaly Zhuravlev [ 2017 Sep 02 ]

Thanks, vso, I guess it's \r\n thing!

Generated at Wed Apr 24 08:44:11 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.