Skip to content

Log Reader Binding ​

This binding reads and analyzes log files. Search patterns are fully configurable, therefore different kind of log files should be possible to monitor by this binding. When certain log events are recognized, openHAB rules can be used to send notification about the event e.g by email for further analysis.

Supported Things ​

This binding supports one ThingType: reader. A reader supports 3 separate channels

  • One for errors
  • one for warnings
  • one custom channel for other purposes.

Thing Configuration ​

The reader Thing has the following configuration parameters:

ParameterTypeRequiredDefault if omittedDescription
filePathStringyes${OPENHAB_LOGDIR}/openhab.logPath to log file. ${OPENHAB_LOGDIR} is automatically replaced by the correct directory.
refreshRateintegerno1000Time in milliseconds between individual log reads.
errorPatternsStringnoERROR+Search patterns separated by | character for error events.
errorBlacklistingPatternsStringnoSearch patterns for blacklisting unwanted error events separated by | character.
warningPatternsStringnoWARN+Search patterns separated by | character for warning events.
warningBlacklistingPatternsStringnoSearch patterns for blacklisting unwanted warning events separated by | character.
customPatternsStringnoSearch patterns separated by | character for custom events.
customBlacklistingPatternsStringnoSearch patterns for blacklisting unwanted custom events separated by | character.

Search patterns follows Java regular expression syntax. Be aware that search patterns are case sensitive.

Channels ​

List of channels

Channel Type IDItem TypeDescription
lastErrorEventStringDisplays content of last [ERROR] event
lastWarningEventStringDisplays content of last [WARN] event
lastCustomEventStringDisplays content of last [CUSTOM] event
errorEventsNumberDisplays number of [ERROR] lines matched to search pattern
warningEventsNumberDisplays number of [WARN] lines matched to search pattern
customEventsNumberDisplays number of [CUSTOM] lines matched to search pattern
logRotatedDateTimeLast time when log rotated recognized
newErrorEvent-Trigger channel for last [ERROR] line
newWarningEvent-Trigger channel for last [WARN] line
newCustomEvent-Trigger channel for last [CUSTOM] line

Examples ​

example.things ​

java

logreader:reader:openhablog[ refreshRate=1000, errorPatterns="ERROR+", errorBlacklistingPatterns="annoying error which should be ignored|Another annoying error which should be ignored" ]

example.items ​

dsl

DateTime logreaderLogRotated        "Last Log Rotation [%1$tY.%1$tm.%1$te %1$tR]"   <time>  { channel="logreader:reader:openhablog:logRotated" }
Number   logreaderErrors            "Error events matched [%d]"                     <alarm> { channel="logreader:reader:openhablog:errorEvents" }
String   logreaderLastError         "Last error [%s]"                                       { channel="logreader:reader:openhablog:lastErrorEvent" }
Number   logreaderWarnings          "Warning events matched [%d]"                   <alarm> { channel="logreader:reader:openhablog:warningEvents" }
String   logreaderLastWarning       "Last warning [%s]"                                     { channel="logreader:reader:openhablog:lastWarningEvent" }
Number   logreaderCustoms           "Custom events matched [%d]"                    <alarm> { channel="logreader:reader:openhablog:customEvents" }
String   logreaderLastCustom        "Last Custom [%s]"                                      { channel="logreader:reader:openhablog:lastCustomEvent" }

example.sitemap ​

dsl

sitemap logreader_example label="Example" {
 Frame label="openHAB Log Reader" {
  Text item=logreaderErrors
  Text item=logreaderLastError
  Text item=logreaderWarnings
  Text item=logreaderLastWarning
  Text item=logreaderCustoms
  Text item=logreaderLastCustom
  Text item=logreaderLogRotated
 }
}

example.rules ​

rules
rule "LogReader"
    when
        Channel "logreader:reader:openhablog:newErrorEvent" triggered
    then
        // do something
    end

Use the rules with your Telegram Bot (need openHAB Telegram Binding installed and configured)

rules
rule "LogReader"
    when
        Channel 'logreader:reader:openhablog:newErrorEvent' triggered
    then
        val telegramAction = getActions("telegram","telegram:telegramBot:myBot")
        telegramAction.sendTelegram("*ERROR* LogReader Event!\n%s Errors are in the log! Here is the last row of it:\n`%s`", logreaderErrors.state.toString, logreaderLastError.state.toString)
    end

Be careful when sending e.g. email notifications. You could easily send thousand of spam emails in short period if e.g. one binding is in error loop.

Thing status ​

Check Thing status for errors.

Verbose logging ​

Enable DEBUG logging in karaf console to see more precise error messages:

log:set DEBUG org.openhab.binding.logreader

See openHAB2 logging docs for more help.