• Stars
    star
    185
  • Rank 201,725 (Top 5 %)
  • Language
    Python
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Execute shell commands triggered by published MQTT messages

mqtt-launcher

mqtt-launcher is a Python program which subscribes to a set of MQTT topics and executes processes on the host it's running on. Launchable processes are configured on a per/wildcard basis, and they can be constrained to run only if a particular text payload is contained in the message.

For example, I can publish a message to my MQTT broker requesting mqtt-launcher create a particular semaphore file for me:

mosquitto_pub -t sys/file -m create

The configuration file must be valid Python and it is loaded once. It contains the topic / process associations.

# topic         payload value           program & arguments
"sys/file"  :   {
                    'create'        :   [ '/usr/bin/touch', '/tmp/file.one' ],
                    'false'         :   [ '/bin/rm', '-f', '/tmp/file.one'    ],
                    'info'          :   [ '/bin/ls', '-l', '/tmp/file.one' ],
                },

Above snippet instructs mqtt-launcher to:

  • subscribe to the MQTT topic sys/file
  • look up the payload string and launch the associated programs:
    • if the payload is create, then touch a file
    • if the payload is the string false, remove a file
    • if the payload is info, return information on the file

The payload value may be None in which case the eacho of the list elements defining the program and arguments are checked for the magic string @!@ which is replaced by the payload contents. (See example published at dev/2, dev/3 and dev/4 below.)

mqtt-launcher publishes stdout and stderr of the launched program to the configured topic with /report added to it. So, in the example above, a non-retained message will be published to sys/file/report. (Note that this message contains whatever the command outputs; trailing white space is truncated.)

Screenshot

Here's the obligatory "screenshot".

Publishes					Subscribes
-----------------------		------------------------------------------------------------------
						$ mosquitto_sub -v -t 'dev/#' -t 'sys/file/#' -t 'prog/#' 


mosquitto_pub -t prog/pwd -n
						prog/pwd (null)
						prog/pwd/report /private/tmp

mosquitto_pub -t sys/file -m create
						sys/file create
						sys/file/report (null)	# command has no output

mosquitto_pub -t sys/file -m info
						sys/file info
						sys/file/report -rw-r--r--  1 jpm  wheel  0 Jan 22 16:10 /tmp/file.one

mosquitto_pub -t sys/file -m remove
						sys/file remove
						# report not published: subcommand ('remove') doesn't exist
						# log file says:
						2014-01-22 16:11:30,393 No matching param (remove) for sys/file

mosquitto_pub -t dev/1 -m hi
						dev/1 hi
						dev/1/report total 16231
						drwxrwxr-x+ 157 root  admin     5338 Jan 20 10:48 Applications
						drwxrwxr-x@   8 root  admin      272 Jan 25  2013 Developer
						drwxr-xr-x+  72 root  wheel     2448 Oct 14 10:54 Library
						...
mosquitto_pub -t dev/2 -m 'Hi Jane!'
						dev/2 Hi Jane!
						dev/2/report 111 * Hi Jane! 222 Hi Jane! 333

mosquitto_pub -t dev/3 -m 'foo-bar'
						dev/3 foo-bar
						dev/3/report foo-bar

mosquitto_pub -t dev/4 -m 'foo/bar'
						dev/4 foo/bar
						dev/4/report var1=foo var2=bar

Configuration

mqtt-launcher loads a Python configuration from the path contained in the environment variable $MQTTLAUNCHERCONFIG; if unset, the path defaults to launcher.conf. See the provided launcher.conf.example.

Logging

mqtt-launcher logs its operation in the file configured as logfile.

Requirements

Credits

This program was inspired by two related tools:

  • Peter van Dijk's mqtt-spawn
  • Dennis Schulte's mqtt-exec. (I'm not terribly comfortable running NodeJS programs, so I implemented the idea in Python.)

More Repositories

1

jo

JSON output from a shell
C
4,592
star
2

mqttwarn

Subscribe to MQTT topics (with wildcards) and notify pluggable services
Python
908
star
3

mosquitto-auth-plug

Authentication plugin for Mosquitto with multiple back-ends (MySQL, Redis, CDB, SQLite3)
C
808
star
4

homie-ota

OTA "server" in Python for Homie
Python
128
star
5

simple-mqtt-websocket-example

Simple MQTT Websocket example
JavaScript
111
star
6

scrumptious

Scrumptious Bookmarks in CouchDB
JavaScript
72
star
7

mqtt2graphite

Subscribe to MQTT topics and push to Graphite's Carbon server
Python
70
star
8

tempgauge

HTML5 canvas gauge for temperature obtained from an MQTT subscribe
Python
68
star
9

mqtt-svg-dash

SVG "live" dashboard from MQTT
JavaScript
60
star
10

check-mqtt

A Nagios/Icinga plugin for testing an MQTT broker
Python
58
star
11

mqtt-watchdir

Recursively watch a directory for modifications and publish file content to an MQTT broker
Python
38
star
12

ansible-m-dnsupdate

Ansible module to perform RFC 2136 dynamic DNS updates
Python
32
star
13

pico

C++
28
star
14

ansible-facts

Ansible module (python) to produce own "facts"
Python
24
star
15

mqttcollect

collectd "Exec" plugin for MQTT
C
22
star
16

qtripp

Queclink Track (air) Interface Protocol Processor
C
22
star
17

msoak

MQTT subscribe to mutliple servers / topics simultaneously
C
20
star
18

ansible-m-pdns_zone

Ansible module to create/delete/list PowerDNS zones
Python
19
star
19

mqtt-osx-notifier

Notify OSX from topics published on OSX (see mqttwarn)
Python
18
star
20

from-traccar

Traccar positions and events to MQTT
C
16
star
21

ansible-jinja2-templates

Example Jinja2 templates for Ansible
15
star
22

n-repo

Sample repository for Ansible in "Pull"-mode
Python
15
star
23

hared-hare

Alerting or notifying on SSH logins
C
14
star
24

nagval

Nagios/Icinga plugin to check validity of one or more DNSSEC domains
C
14
star
25

notify-by-mqtt

A Nagios/Icinga module to submit notifications to mqttwarn
Python
14
star
26

tempmonitor

A simple MQTT Websocket temperature monitoring page with Arduino support
JavaScript
13
star
27

ansible-graphite

very experimental: install Graphite via Ansible
Python
13
star
28

facts2sshfp

Create SSHFP records for DNS from YAML fact files on Puppet master
Python
12
star
29

1090-to-owntracks

Import ADS-B data into OwnTracks via MQTT
Python
11
star
30

sonospauseIR

Arduino-based remote control for Sonos
Java
11
star
31

couch-sdb

BIND SDB driver for CouchDB
C
10
star
32

ansible-booklet

A reference card/cheat sheet/booklet for Ansible
Shell
10
star
33

dlz_lua

Lua "back-end" for BIND with dlz_dlopen()
C
10
star
34

revgeod

A reverse Geo lookup service written in C, accessible via HTTP and backed by OpenCage and LMDB
C
9
star
35

pudo

Upload JSON documents and attachments to a CouchDB instance
9
star
36

mqtt-prowl

Subscribe to topics on an MQTT broker and notify via Prowl (obsolete: see mqttwarn)
Python
9
star
37

twitter2mqtt

A Twitter to MQTT gateway (1-shot)
Python
8
star
38

dnssecmagic.js

Minimal HTML/JavaScript/jQuery code to determine if Web-browser is using a DNSSEC-validating cache
JavaScript
8
star
39

fritzuploader

Upload phonebook to Fritz!Box from the command-line
8
star
40

ansible-zypp

Ansible module (shell) to install/remove packages on Suse Linux
8
star
41

bzl

Bind Zone List
C
8
star
42

airportsd

IATA airport code lookup server
C
8
star
43

ansible-ntfy

Ansible action plugin to post JSON messages to nfty
Python
7
star
44

syncthing-activity

Monitor file changes as syncthing performs them
Python
6
star
45

mqtt-chronos

Periodically submit time/date-related data to an MQTT broker
C
5
star
46

jopleet

Copy individual tweet status URLs into Joplin notes
Python
5
star
47

whatmon

Mozilla Firefox/Thunderbird add-on for Monitoring Whatever
JavaScript
4
star
48

bind9stats

BIND9 statistics-server plugin for Munin
C
4
star
49

diablo

diablo-5-CUR-20090530-00 + XS4ALL patches
C
4
star
50

mqtwit

MQTT to Twitter. (obsolete: see mqttwarn)
Python
4
star
51

tt

to T
Python
3
star
52

check_nix

This is a Nagios/Icinga plugin for checking a particular DNS TXT RR. See the documentation in the program.
C
3
star
53

go-progs

Go programs (single binary, dependencies included)
3
star
54

owntracks-livetable

OwnTracks Live table
Python
2
star
55

make-big-aa

create a large RFC 1035 zone file
Perl
2
star
56

eitime

print an RRSIG expiration / inception time in the form `YYYYMMDD000000`
C
2
star
57

SensorTag_iOS

SensorTag_iOS from https://git.ti.com
Objective-C
2
star
58

ob

openBerlin
JavaScript
2
star
59

beanstalkc3-ot

A simple beanstalkd client library for Python3 patched for YAML.safe_load
Python
2
star
60

mqtt-speedo

Speedometer for MQTT messages (unreliable!)
CSS
2
star
61

pdns-remote-airports

pdns remote backend for airport codes
Python
2
star
62

rfc2136tweetr

Twitter status updates via RFC 2136 dynamic DNS updates
JavaScript
2
star
63

pdns2graphite

pdns2graphite
Python
2
star
64

powerdns-datacheck

MySQL UDF to check data in PowerDNS tables
C
2
star
65

cattled

This is !NOCOWS for Ansible: a repo of a cattle daemon
Go
1
star
66

ypom-cli

Python
1
star
67

t3

test pubkey
1
star
68

zabbix

Bastille Template to create a Zabbix Monitoring Jail
Shell
1
star
69

cy-ddns

C
1
star
70

ansible-ec2-userdata

Obtain user-data
Python
1
star
71

tpl02

HTML
1
star
72

airports-zonedata

$INCLUDE airport locations
1
star
73

revgeod-python

Python
1
star
74

luadnszones

Testing
1
star
75

openhab-workshop

Support files for my openHAB Workshop
C++
1
star
76

jndcalx

Get iCal/Sunbird to subscribe to your Lotus Notes calendar
C
1
star
77

whatmon-s

Whatmon for Safari
JavaScript
1
star
78

owa11-owntracks

owa11 MQTT to OwnTracks JSON
C
1
star
79

b1

tmp don't use
JavaScript
1
star
80

dv

POC: Lightweight file "signing" and verification using DNSSEC
C
1
star
81

jpmens.github.com

1
star
82

yaus

Yet Another URL Shortner
C
1
star