Long entry getting past regex filter in logs

I have my APC UPS connected to OpenHAB using apcupsd and it works great. But the logging is driving me bonkers. This is on OpenHABian on an rPi. Latest stable release.

I have a regex filter to filter out useless junk from the logs from many different things as many people do. I added APC_* to that regex to filter out the APC_xxxx log records. It filters out all of the APC_ logging except this one really long one.

This is the filter:

# custom filter
log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .*(hem_*|REFRESH|predicted|APC_*|wx_*|temp_*|humid_*|str*|mot_*|astro).*
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

But this log entry is getting past the filter. I’m assuming it has something to do with the length of the text or something?

2019-10-19 21:22:05 [smarthome.event.ItemStateChangedEvent             ] - APC_Raw changed from APC      : 001,036,0859

DATE     : 2019-10-19 21:17:04 -0400  
HOSTNAME : openHABianPi
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : closet
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2019-10-19 11:15:50 -0400  
MODEL    : Back-UPS XS 1500M 
STATUS   : ONLINE 
LINEV    : 123.0
LOADPCT  : 25.0
BCHARGE  : 100.0
TIMELEFT : 25.6
MBATTCHG : 5
MINTIMEL : 5
MAXTIME  : 0
SENSE    : Medium
LOTRANS  : 88.0
HITRANS  : 139.0
ALARMDEL : No alarm
BATTV    : 27.3
LASTXFER : Low line voltage
NUMXFERS : 0
TONBATT  : 0
CUMONBATT: 0
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : 3B1845X28655  
BATTDATE : 2018-11-09
NOMINV   : 120
NOMBATTV : 24.0
NOMPOWER : 900
FIRMWARE : 947.d7 .D USB FW:d7
END APC  : 2019-10-19 21:17:05 -0400 to APC      : 001,036,0859
DATE     : 2019-10-19 21:22:04 -0400  
HOSTNAME : openHABianPi
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : closet
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2019-10-19 11:15:50 -0400  
MODEL    : Back-UPS XS 1500M 
STATUS   : ONLINE 
LINEV    : 123.0
LOADPCT  : 26.0
BCHARGE  : 100.0
TIMELEFT : 25.3
MBATTCHG : 5
MINTIMEL : 5
MAXTIME  : 0
SENSE    : Medium
LOTRANS  : 88.0
HITRANS  : 139.0
ALARMDEL : No alarm
BATTV    : 27.3
LASTXFER : Low line voltage
NUMXFERS : 0
TONBATT  : 0
CUMONBATT: 0
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
SERIALNO : 3B1845X28655  
BATTDATE : 2018-11-09
NOMINV   : 120
NOMBATTV : 24.0
NOMPOWER : 900
FIRMWARE : 947.d7 .D USB FW:d7
END APC  : 2019-10-19 21:22:05 -0400

Why is this getting through the regex filter, and how can I make it go away?

Just add APC_ instead of APC_*

I tried too, and it did not change anything. I just tried it again and still no change.

Try this one:
.*(hem_|REFRESH|predicted|APC_|wx_|temp_|humid_|str|mot_|astro).*
Basically remove all the * inside the bracket. They are not needed

Did you already restart openHAB?

Tried. No change.

Yes. No change.

It appears that the problem is that the data in APC_Raw is on more than one line. If you’re using the solution from aaronk, then this change worked for me:

.things file:

Thing exec:command:apc "APC UPS in the study" [
  command="c:\\apcupsd\\bin\\apcaccess -u",
  interval=5,
  timeout=2,
  autorun=false,
  // Adding this so it'll be one line so it can be suppressed from the event log
  transform="REGEX(s/[\\r\\n]/~/g)"
]

In the .rules file, change the var output = statement by adding .replace('~','\n') e.g.:

rule "APC: Parse raw output from command-line tool"
  when
  Item APC_Raw changed
then
  // Adding the .replace here to change the string back to lines
  var output = APC_Raw.state.toString.replace('~','\n')

Add this to the end of userdata\etc\org.ops4j.pax.logging.cfg

# Event log filters
# Supressing the noise from the 5-second updates from the ACP UPS
log4j2.appender.event.filter.uselessjunk.type = RegexFilter
log4j2.appender.event.filter.uselessjunk.regex = .*(APC_Raw|APC_DATE|APC_LOADPCT|APC_TIMELEFT).*
log4j2.appender.event.filter.uselessjunk.onMatch = DENY
log4j2.appender.event.filter.uselessjunk.onMisMatch = ACCEPT

Hope that works out for you.

1 Like