Notification and control panel for Docker in OH

To get notifications about container staus and availablity of updates, I did following:

  1. installed WUD (What’s up docker) with this stack:
version: '3.9'
services:
  whatsupdocker:
    image: fmartinou/whats-up-docker:latest
    container_name: WUD
    mem_limit: 128m
    mem_reservation: 50m
    cpu_shares: 256
    security_opt:
      - no-new-privileges=true
    read_only: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /volume1/docker/wud:/store
    ports:
      - 3555:3000
    environment:
      - WUD_TRIGGER_MQTT_MOSQUITTO_URL=mqtt://ip_of_your_mqtt_server:1883
  1. .things:
Thing mqtt:topic:mosquitto:mqtt_docker "MQTT Docker" (mqtt:broker:mosquitto) {
    Channels:
      Type switch :  wud_update                            [ stateTopic="wud/container/local/WUD", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ] 
      Type switch :  influx_update                         [ stateTopic="wud/container/local/influxdb", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ] 
      Type switch :  adguard_update                        [ stateTopic="wud/container/local/AdGuard", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ] 
      Type switch :  grafana_update                        [ stateTopic="wud/container/local/grafana", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ]             
      Type switch :  portainer_update                      [ stateTopic="wud/container/local/portainer", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ] 
      Type switch :  watchtower_update                     [ stateTopic="wud/container/local/watchtower", transformationPattern="JSONPATH:$.update_available",  off="false" , on="true" ] 
      Type string :  wud_status                            [ stateTopic="wud/container/local/WUD", transformationPattern="JSONPATH:$.status" ] 
      Type string :  influx_status                         [ stateTopic="wud/container/local/influxdb", transformationPattern="JSONPATH:$.status" ] 
      Type string :  adguard_status                        [ stateTopic="wud/container/local/AdGuard", transformationPattern="JSONPATH:$.status" ] 
      Type string :  grafana_status                        [ stateTopic="wud/container/local/grafana", transformationPattern="JSONPATH:$.status" ]             
      Type string :  portainer_status                      [ stateTopic="wud/container/local/portainer", transformationPattern="JSONPATH:$.status" ] 
      Type string :  watchtower_status                     [ stateTopic="wud/container/local/watchtower", transformationPattern="JSONPATH:$.status" ] 
    }
  1. .items:
//Docker

Group gDockerUpdates
Group gDockerStatus

Switch  wud_update           "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:wud_update"}
Switch  influx_update        "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:influx_update"}
Switch  grafana_update       "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:grafana_update"}
Switch  watchtower_update    "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:watchtower_update"}
Switch  portainer_update     "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:portainer_update"}
Switch  adguard_update       "[MAP(docker.map):%s]"                        <updated>       (gDockerUpdates)  {channel="mqtt:topic:mosquitto:mqtt_docker:adguard_update"}
String  wud_status           "What's up docker"                            <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:wud_status"}
String  influx_status        "influxdb"                                    <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:influx_status"}
String  grafana_status       "grafana"                                     <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:grafana_status"}
String  watchtower_status    "watchtower"                                  <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:watchtower_status"}
String  portainer_status     "Portainer"                                   <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:portainer_status"}
String  adguard_status       "AdGuard"                                     <selfprogram2>  (gDockerStatus)   {channel="mqtt:topic:mosquitto:mqtt_docker:adguard_status"}
  1. .sitemap:
            Text label="Docker" icon="docker" {
                Frame {
                    Text item=influx_status
                    Text item=influx_update visibility=[influx_update == ON]
                    Text item=grafana_status
                    Text item=grafana_update visibility=[grafana_update == ON]
                    Text item=portainer_status
                    Text item=portainer_update visibility=[portainer_update == ON]
                    Text item=adguard_status
                    Text item=adguard_update visibility=[adguard_update == ON]                    
                    Text item=wud_status
                    Text item=wud_update visibility=[wud_update == ON]
                }
            }
  1. .rules:
rule "Docker Update available"
when
    Member of gDockerUpdates changed
then
    val container = triggeringItem.name.split("_").get(0)
    switch triggeringItem.state {
      case ON  : sendNotification("mail@gmx.de", "Docker Update available for: " + container)
      case OFF : sendNotification("mail@gmx.de", "Docker Update installed for: " + container) }
end

rule "Docker Container not running"
when
    Member of gDockerStatus changed
then
    val iContainer = gDockerStatus.members.filter[ i | i.state != "running" ].size
    val container = triggeringItem.name.split("_").get(0)
    if (iContainer > 0)
      sendNotification("mail@gmx.de", "Docker Container not running: " + container + "\nStatus: " + triggeringItem.state.toString)
    if (iContainer == 0 )
      sendNotification("mail@gmx.de", "Docker: all containers running again.")
end

Have fun. :wink:

1 Like