[Solved][RELEASE] How to catch errors in log?

Thanx to @bertabcd1234, @aaiyar, and @jlv I created a minimal solution for my problem on the base of @bptworld's great code:

You can set the monitored level (when to fire an event).
Optionally you can also set (via ID or name) a list of monitored devices and apps.
BTW: The event contains the JSON string of the log line.

Hint: In Rule Machine use "Custom Attribute" as Trigger and choose "event" and "changed".

Maybe this driver is helpful also for others... :wink:

// Idea by:  Bryan (bptworld) - https://community.hubitat.com/u/bptworld
// Based on: https://community.hubitat.com/t/release-error-monitor/91317


metadata
{
  definition(name:'jsErrorMonitor', namespace:'de.schwider', author:'Jost Schwider', description:'Just Simple Error Monitor')
  {
	capability 'Actuator'
    
    attribute 'event', 'string'
  }
  
  preferences()
  {
    input 'monitorLevel', 'enum', title:'Monitor this Log Level:<br><small>(Don\'t try <b>info</b> or even <b>debug</b>!)</small>', options:['debug', 'info', 'warn', 'error'], defaultValue:'error', required:true
    input 'monitorDevices', 'string', title:'Monitor this Devices/Apps:<br><small>(Comma-separated Names or IDs; Empty=All)</small>', defaultValue:'', required:false
    input 'logType', 'enum', title:'Logging:', options:['Debug', 'Info', 'Off'], defaultValue:'Info', required:true
  }
}


void installed()
{
  logInfo 'Installing...'
  initialize ()
}


void updated() {
  logInfo 'Updating...'
  initialize ()
}


void initialize()
{
  logDebug 'Connecting...'
  interfaces.webSocket.connect 'ws://localhost:8080/logsocket'
}


void uninstalled()
{
  logInfo 'Uninstalling...'
  interfaces.webSocket.close ()
}


// Web Socket: //


void webSocketStatus(String socketStatus)
{
  logDebug socketStatus
}


void parse(String desc)
{
  Map logEvent =  new groovy.json.JsonSlurper().parseText(desc)
  // logEvent#Fields: name, msg, id, time, type, level 
  
  if (logEvent.id == device.id) return // Don't monitor the monitor itself! ;)
  if (logEvent.level != monitorLevel) return
  
  if (monitorDevices)
  {
    String[] devices = monitorDevices.split(',')*.trim()
    logDebug "$logEvent.id/$logEvent.name in $devices?"
    if (logEvent.id.toString() in devices || logEvent.name in devices) {} else return
  }
  
  logInfo desc
  sendEvent name:'event', value:desc
}


// Logging: //


void logInfo(String info)
{
  if (logType in ['Info', 'Debug']) log.info info
}


void logDebug(String debug)
{
  if (logType == 'Debug') log.debug debug
}
3 Likes