Skip to content

Commit a1f8948

Browse files
committed
Send mqtt message when MQTTHOST is defined
1 parent 9cb3805 commit a1f8948

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

monitor.rc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ NSCACONF=/etc/nagios/send_nsca.cfg
33
NSCASERVER=your.nagios.system
44
HOSTNAME=`hostname`
55
CHECKPATH=/usr/lib64/nagios/plugins
6+
MQTTHOST=127.0.0.1
7+
MQTTTOPIC="nsca/monitor"
8+
MQTTWARNTOPIC="alert/monitor"
69

710
CHECKS=(
811
'check_users|check_users -w 5 -c 10'

monitor.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ if mkdir "${LOCKDIR}" &>/dev/null; then
4040
RETVAL=$?
4141

4242
echo "${HOSTNAME} ${CHECKNAME} ${RETVAL} ${DATA}" | ${NSCA} -H ${NSCASERVER} -c ${NSCACONF}
43+
44+
if [ ${MQTTHOST} ]; then
45+
mosquitto_pub -h ${MQTTHOST} -t ${MQTTTOPIC} -m "{'host':'${HOSTNAME}', 'check':'${CHECKNAME}', 'returncode':'${RETVAL}', 'data':'${DATA}'}"
46+
if [ ${RETVAL} -ne 0 ]; then
47+
mosquitto_pub -h ${MQTTHOST} -t ${MQTTWARNTOPIC} -m "{'host':'${HOSTNAME}', 'check':'${CHECKNAME}', 'returncode':'${RETVAL}', 'data':'${DATA}'}"
48+
fi
49+
fi
50+
4351
done > /dev/null
4452
else # lock failed, now check if the other PID is alive
4553
OTHERPID="$(cat "${PIDFILE}")"

0 commit comments

Comments
 (0)