Subscribe to MQTT topics and notify pluggable services

This commit is contained in:
Dan Langille 2018-03-26 21:23:45 +00:00
parent d661363b50
commit c7b242ac48
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=465638
10 changed files with 297 additions and 2 deletions

2
GIDs
View file

@ -163,7 +163,7 @@ sddm:*:219:
bs:*:220: bs:*:220:
opensips:*:221: opensips:*:221:
rtpproxy:*:222: rtpproxy:*:222:
# free: 223 mqttwarn:*:223
# free: 224 # free: 224
postgrey:*:225: postgrey:*:225:
sqlgrey:*:226: sqlgrey:*:226:

2
UIDs
View file

@ -168,7 +168,7 @@ sddm:*:219:219::0:0:SDDM Display Manager user:/usr/local/etc/sddm/home:/usr/sbin
bs:*:220:220::0:0:Big Sister:/usr/local/bigsister:/bin/sh bs:*:220:220::0:0:Big Sister:/usr/local/bigsister:/bin/sh
opensips:*:221:221::0:0:OpenSIPS user:/nonexistent:/usr/sbin/nologin opensips:*:221:221::0:0:OpenSIPS user:/nonexistent:/usr/sbin/nologin
rtpproxy:*:222:222::0:0:& user:/nonexistent:/sbin/nologin rtpproxy:*:222:222::0:0:& user:/nonexistent:/sbin/nologin
# free: 223 mqttwarn:*:223:223::0:0:mqttwarn:/nonexistent:/sbin/nologin
# free: 224 # free: 224
postgrey:*:225:225::0:0:Postgrey Owner:/nonexistent:/usr/sbin/nologin postgrey:*:225:225::0:0:Postgrey Owner:/nonexistent:/usr/sbin/nologin
sqlgrey:*:226:226::0:0:SQLgrey Owner:/nonexistent:/usr/sbin/nologin sqlgrey:*:226:226::0:0:SQLgrey Owner:/nonexistent:/usr/sbin/nologin

View file

@ -931,6 +931,7 @@
SUBDIR += py-halite SUBDIR += py-halite
SUBDIR += py-honcho SUBDIR += py-honcho
SUBDIR += py-iowait SUBDIR += py-iowait
SUBDIR += py-mqttwarn
SUBDIR += py-nagiosplugin SUBDIR += py-nagiosplugin
SUBDIR += py-nomad SUBDIR += py-nomad
SUBDIR += py-pkginfo SUBDIR += py-pkginfo

View file

@ -0,0 +1,56 @@
# $FreeBSD$
PORTNAME= mqttwarn
DISTVERSIONPREFIX= v
DISTVERSION= 0.6-367
DISTVERSIONSUFFIX= -gc28e1d3
CATEGORIES= sysutils python
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
MAINTAINER= dvl@FreeBSD.org
COMMENT= Subscribe to MQTT topics and notify pluggable services
LICENSE= EPL
LICENSE_FILE= ${WRKSRC}/LICENSE
RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}paho-mqtt>=0:net/py-paho-mqtt@${FLAVOR}
RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}supervisor>=0:sysutils/py-supervisor@${FLAVOR}
USES= python:2.7 shebangfix
USE_PYTHON= flavors
SHEBANG_REGEX= '.*\.py$$'
USE_GITHUB= yes
GH_ACCOUNT= jpmens
#NO_BUILD= yes
NO_ARCH= yes
OPTIONS_DEFINE= DOCS EXAMPLES
USERS= mqttwarn
GROUPS= mqttwarn
SUB_FILES= pkg-message
post-patch:
@${REINPLACE_CMD} -e 's|MQTTWARN_LIBDIR|${PYTHON_SITELIBDIR}/${PORTNAME}/lib/|g' ${WRKSRC}/mqttwarn.ini.sample
do-build:
(cd ${WRKSRC} && ${PYTHON_CMD} -m compileall .)
do-install:
${MKDIR} ${STAGEDIR}/var/log/${PORTNAME}
${INSTALL_SCRIPT} ${WRKSRC}/mqttwarn.py ${STAGEDIR}${PREFIX}/sbin/mqttwarn
(cd ${WRKSRC}/etc && ${COPYTREE_SHARE} . ${STAGEDIR}${ETCDIR})
(cd ${WRKSRC}/services && ${COPYTREE_SHARE} . ${STAGEDIR}${PYTHON_SITELIBDIR}/${PORTNAME}/lib/services)
${CP} ${WRKSRC}/mqttwarn.ini.sample ${STAGEDIR}${ETCDIR}
do-install-DOCS-on:
@${MKDIR} ${STAGEDIR}${DOCSDIR}
${INSTALL_DATA} ${WRKSRC}/README.md ${STAGEDIR}${DOCSDIR}
do-install-EXAMPLES-on:
@${MKDIR} ${STAGEDIR}${EXAMPLESDIR}
(cd ${WRKSRC}/examples && ${COPYTREE_SHARE} . ${STAGEDIR}${EXAMPLESDIR})
.include <bsd.port.mk>

View file

@ -0,0 +1,3 @@
TIMESTAMP = 1522088255
SHA256 (jpmens-mqttwarn-v0.6-367-gc28e1d3_GH0.tar.gz) = 9855a89190810eebca5c18501ede4f1e736b468d167821e1ebd6c81b87b33fff
SIZE (jpmens-mqttwarn-v0.6-367-gc28e1d3_GH0.tar.gz) = 793852

View file

@ -0,0 +1,10 @@
--- mqttwarn.ini.sample.orig 2018-03-26 17:57:16 UTC
+++ mqttwarn.ini.sample
@@ -14,6 +14,7 @@ clientid = 'mqttwarn'
lwt = 'clients/mqttwarn'
skipretained = False
cleansession = False
+libdir = /usr/local/lib/python2.7/site-packages/mqttwarn/lib/
# MQTTv31 = 3 (default)
# MQTTv311 = 4

View file

@ -0,0 +1,20 @@
--- mqttwarn.py.orig 2018-03-26 20:00:37 UTC
+++ mqttwarn.py
@@ -83,6 +83,8 @@ class Config(RawConfigParser):
self.cleansession = False
self.protocol = 3
+ self.libdir = ''
+
self.logformat = '%(asctime)-15s %(levelname)-5s [%(module)s] %(message)s'
self.logfile = LOGFILE
self.loglevel = 'DEBUG'
@@ -999,7 +1001,7 @@ def load_services(services):
modulefile = 'services/%s.py' % module
try:
- service_plugins[service]['module'] = load_module(modulefile)
+ service_plugins[service]['module'] = load_module(cf.libdir + '/' + modulefile)
logging.debug("Service %s loaded" % (service))
except Exception, e:
logging.error("Can't load %s service (%s): %s" % (service, modulefile, str(e)))

View file

@ -0,0 +1,33 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
After installing mqttwarn for the first time, we recommend making the
following change to supervisord configuration settings:
1 - Add to /etc/rc.conf:
supervisord_enable="YES"
supervisord_config="%%PREFIX%%/etc/supervisord/supervisord.conf"
2 - Create this directory:
mkdir %%PREFIX%%/etc/supervisord
3 - Move the configuration file:
mv -i %%PREFIX%%/etc/supervisord.conf %%PREFIX%%/etc/supervisord/
4 - Create %%PREFIX%%/etc/supervisord/mqttwarn.conf with the following content:
[program:mqttwarn]
command = %%PREFIX%%/sbin/mqttwarn
user = mqttwarn
environment=MQTTWARNINI="%%PREFIX%%/etc/mqttwarn/mqttwarn.ini",MQTTWARNLOG="/var/log/mqttwarn/mqttwarn.log"
5 - Add this to the end of %%PREFIX%%/etc/supervisord/supervisord.conf
[include]
files = mqttwarn.conf
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

View file

@ -0,0 +1,8 @@
mqttwarn subscribes to any number of MQTT topics (which may include wildcards)
and publishes received payloads to one or more notification services, including
support for notifying more than one distinct service for the same message.
For example, you may wish to notify via e-mail and to Pushover of an alarm
published as text to the MQTT topic home/monitoring/+.
WWW: http://github.com/jpmens/mqttwarn

View file

@ -0,0 +1,164 @@
%%ETCDIR%%/OpenWRT.init
%%ETCDIR%%/mqttwarn.default
%%ETCDIR%%/mqttwarn.init
%%ETCDIR%%/mqttwarn.logrotate
%%ETCDIR%%/mqttwarn.service
%%ETCDIR%%/supervisor.ini
%%ETCDIR%%/zabbix-template.xml
%%PORTDOCS%%%%DOCSDIR%%/README.md
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/__init__.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/__init__.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/amqp-puka-get.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/amqp-puka-get.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/hiveeyes/__init__.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/hiveeyes/__init__.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/hiveeyes/hiveeyes.ini
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/hiveeyes/hiveeyes.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/hiveeyes/hiveeyes.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/homie/__init__.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/homie/__init__.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/homie/homie.ini
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/homie/homie.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/homie/homie.pyc
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/zabbix/zabbix_mqtt_agent.py
%%PORTEXAMPLES%%%%EXAMPLESDIR%%/zabbix/zabbix_mqtt_agent.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/README.md
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/amqp.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/amqp.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/apns.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/apns.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/asterisk.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/asterisk.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/autoremote.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/autoremote.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/carbon.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/carbon.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/celery.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/celery.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/dbus.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/dbus.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/dnsupdate.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/dnsupdate.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/emoncms.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/emoncms.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/execute.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/execute.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/fbchat.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/fbchat.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/file.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/file.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/freeswitch.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/freeswitch.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/gss.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/gss.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/gss2.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/gss2.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/hangbot.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/hangbot.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/hipchat.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/hipchat.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/http.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/http.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/icinga2.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/icinga2.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ifttt.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ifttt.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/influxdb.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/influxdb.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/instapush.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/instapush.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ionic.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ionic.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/iothub.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/iothub.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/irccat.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/irccat.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/linuxnotify.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/linuxnotify.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/log.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/log.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mattermost.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mattermost.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mqtt.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mqtt.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mqttpub.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mqttpub.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mysql.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mysql.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mysql_dynamic.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mysql_dynamic.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mythtv.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/mythtv.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nma.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nma.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nntp.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nntp.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nsca.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/nsca.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/osxnotify.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/osxnotify.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/osxsay.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/osxsay.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pastebinpub.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pastebinpub.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pipe.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pipe.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/postgres.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/postgres.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/prowl.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/prowl.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushalot.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushalot.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushbullet.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushbullet.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushover.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushover.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushsafer.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/pushsafer.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/redispub.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/redispub.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/rrdtool.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/rrdtool.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/serial.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/serial.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/slack.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/slack.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/smtp.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/smtp.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite_json2cols.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite_json2cols.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite_timestamp.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/sqlite_timestamp.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ssh.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/ssh.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/syslog.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/syslog.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/telegram.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/telegram.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/thingspeak.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/thingspeak.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/tootpaste.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/tootpaste.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/twilio.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/twilio.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/twitter.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/twitter.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xbmc.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xbmc.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xively.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xively.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xmpp.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/xmpp.pyc
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/zabbix.py
%%PYTHON_SITELIBDIR%%/mqttwarn/lib/services/zabbix.pyc
@sample %%ETCDIR%%/mqttwarn.ini.sample
sbin/mqttwarn
@mode 755
@owner mqttwarn
@group mqttwarn
@dir /var/log/mqttwarn
@mode
@owner
@group