MichelFR / MqDockerUp

Mqtt Docker Updater (MqDockerUp) is a tool for updating Docker containers. It provides an easy way to check for updates and publish changes to a MQTT broker.
Apache License 2.0
55 stars 5 forks source link

Multiple instances of MqDockerUp conflict with each other #261

Open chriswood1001 opened 3 months ago

chriswood1001 commented 3 months ago

I have several docker instances on different computers, each running MqDockerUp. I'm able to successfully differentiate between the updates by having unique mqtt topics and mqtt clientID's.

However, the home assistant mqtt discovery data conflicts when the same container exists on both docker instances.

My config for docker server one:

main:
  interval: "5m"

mqtt:
  connectionUri: "mqtt://192.168.10.100:1883"
  topic: "mqdockerup/server_one"
  clientId: "mqdockerup_server_one"
  username: "homeassistant"
  password: "password"
  connectTimeout: 60
  protocolVersion: 5

accessTokens:
  dockerhub:
  github:

And, my config for docker server two:

main:
  interval: "5m"

mqtt:
  connectionUri: "mqtt://192.168.10.100:1883"
  topic: "mqdockerup/server_two"
  clientId: "mqdockerup_server_two"
  username: "homeassistant"
  password: "password"
  connectTimeout: 60
  protocolVersion: 5

accessTokens:
  dockerhub:
  github:

Using MQTT Explorer I see the status reported as expected, without conflict.

/mqdockerup/server_one/ <my containers>
/mqdockerup/server_two/ <my containers>

However, the Home Assistant discover data conflicts as both servers try to write to:

/homeassistant/sensor/micrib_mqdockerup_latest/

Is there a way to address this?

MichelFR commented 3 months ago

Since its not my use case to use MqDockerUp on multiple nodes i cannot assure that everything works fine.

One way to possibly fix this is to use the prefix configuration:

main: interval: "5m" prefix: "server_one"

main: interval: "5m" prefix: "server_two"

I hope this helps.

chriswood1001 commented 3 months ago

Thanks for the quick reply. Including "prefix:server_one" does append "server_one" to the MQTT path, but unfortunately it doesn't append it to the MQTT value so Home Assistant is still confused.

What works config.yaml

mqtt:
  topic: "mqdockerup/server_one"

This allows us to have multiple servers with their prefix.

\mqdockerup\server_one\mqdockerup\
\mqdockerup\server_two\mqdockerup\

What partially works config.yaml

main:
  prefix: "server_one"

This creates the MQTT entry under the correct path, but the data doesn't include this prefix in the object_id and unique_id, so home assistant (incorrectly) treats them as one device.

\homeassistant\sensor\server_one_micrib_mqdockerup_latest

{
    "object_id": "micrib/mqdockerup Container ID",  <-- ideally would have "server_one/" prefix
    "name": "Container ID",
    "unique_id": "micrib/mqdockerup Container ID",   <-- ideally would have "server_one/" prefix
    "state_topic": "mqdockerup/server_one/micrib_mqdockerup", <-- correct
    "device_class": null,
    "value_template": "{{ value_json.dockerId }}",
    "availability": {
        "topic": "mqdockerup/server_one/availability"
    },
    "payload_available": "Online",
    "payload_not_available": "Offline",
    "device": {
        "manufacturer": "MqDockerUp",
        "model": "micrib/mqdockerup:latest",
        "name": "server_one_mqdockerup",   <-- correct
        "sw_version": "1.8.0",
        "sa": "Docker",
        "identifiers": [
            "micrib/mqdockerup_latest"   <-- unsure 
        ]
    },
}

I presume that's what's causing home assistant to only see one container despite it existing on two servers.

atv2016 commented 2 months ago

@chriswood1001 Were you able to resolve this? Duplicate containers on different hosts keep overwriting each other's entries in home assistant, no matter if I set :

      MAIN_PREFIX: "mqtt_homeassistant"
      MQTT_TOPIC: "mqtt_homeassistant"
chriswood1001 commented 2 months ago

Unfortunately, no.

atv2016 commented 2 months ago

@MichelFR It looks like the prefix and topic settings are not working. Even if I enable this on 2 different hosts, the entries overwrite each other. Can this be looked into please?

I know it's not your use case but it might be in the future ;-)

MichelFR commented 2 months ago

@MichelFR It looks like the prefix and topic settings are not working. Even if I enable this on 2 different hosts, the entries overwrite each other. Can this be looked into please?

I know it's not your use case but it might be in the future ;-)

Yeah I'm sorry I currently had not the time to look into this one. And since it's not one of my use cases I don't see it as critical. But I can assure you I'm gonna look into this. It's not that difficult to fix this I guess.

atv2016 commented 2 months ago

Many thanks @MichelFR.

In the meantime, I would probably be able to solve my situation by excluding the containers that are overwriting each other. For example, on 2 nodes I have mqdockerup and portioner running, which are overwriting each other. Can I exclude those ?