note; I have all my scripts setup so that the lwt (last will and testament) publishes 'offline' if the scripts die.
Last active
August 29, 2015 13:57
-
-
Save matbor/9657897 to your computer and use it in GitHub Desktop.
Last Will and Testament Notification Function for mqttwarn. https://github.com/jpmens/mqttwarn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################ | |
##### Last Will and Testament Notification Function ##### | |
################################################################ | |
#lwt offline message to check for | |
lwtmsg_offline = 'offline' | |
#last will and Testaments topics to not suppress | |
lwttopics2mon = [ | |
'/lwt/testing1', #testing topic | |
] | |
#filter to check to see if the device/software is offline | |
def lwtfilter(topic, message): | |
for t in lwttopics2mon: | |
if t in topic: | |
if message == lwtmsg_offline: | |
return False #dont suppress the notifcations | |
return True #suppress the notification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[lwt] | |
topic = /lwt/# | |
targets = log:info,pushover:software | |
filter = lwtfilter() | |
format = Device: {topic} went ==> {payload} @{_dthhmm} | |
title = MQTT LWT Notification |
Just added a change to allow you to specify the lwt payload in mqttwarn.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@summerboy12, thx, was one commit behind... forgot to chk that. Have updated the script above to reflect that now
JP's explains lwt the best, here in an old post...
http://jpmens.net/2013/02/25/lots-of-messages-mqtt-pub-sub-and-the-mosquitto-broker/
"Clients can optionally set a Will (in Python before the connect() call). This "last will and testament" (so to speak) is published by the broker when a client disconnects unexpectedly. This can be useful to notify of particular clients' deaths. In other words, if a client issues the following request before connecting, and it dies at some later point, the broker will publish the payload on this client's behalf."
I have most of my scripts setup, so that when they start it publishes to the /lwt/%scriptname$ topic saying tat the script is online and if it dies it publishes offline usng the lwt... that is where the lwt script i made comes in handy.
Dont believe there is a standard as to what the lwt message should be, have seen lots of different versions, 0's and 1's etc, I just use online/offline for my use.