source: npl/monitoring/zabbix_conf/root/sbin/syn3-zabbix-send @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/bin/bash
2MONDIR=/var/lib/mon
3
4#resolution of modify times is only 2 second on some filesystems, so prevent race conditions by touching it now and sleeping 2 seconds
5touch $MONDIR/.zabbix-time
6echo "Sleeping..."
7sleep 2
8
9#traveled back in time? (e.g. systemclock is adjusted)
10if [ $MONDIR/.zabbix-time -ot $MONDIR/zabbix-latest ]; then
11        #just resend everything
12        rm $MONDIR/zabbix-latest
13fi
14
15UPDATES=""
16
17#Let zabbix rediscover all syn-3 facilities if something changed:
18if [ $MONDIR/alerts -nt $MONDIR/zabbix-latest ]; then
19        echo "Rediscovering services..."
20        cd $MONDIR/alerts
21        JSON=
22        for FACILITY in *; do
23                #JOBTTL=`cat $JOBNAME`
24                if [ "$JSON" != "" ]; then
25                        JSON=$JSON', '
26                fi
27                JSON=$JSON'{ "{#FACILITY}": "'$FACILITY'" } '
28        done
29        MODIFY_TIME=`stat --format=%Y .`
30
31        #low level discovery takes time, so send it and then wait a minute to process
32        echo -en '- syn3.discovery { "data": [ '$JSON' ] }\n' | zabbix_sender -vv  -c /etc/zabbix/zabbix_agentd.conf -i - || exit 1
33        echo "Waiting for zabbix to process discovery..."
34        sleep 65
35fi
36
37#Find all facility states that have changed since last succesfull send
38cd $MONDIR/alerts
39for FACILITY in *; do
40        #NOTE: msg-modifytime only changes if something actually changed, while state-modifytime always changes when syn3-state is called.
41        if [ $FACILITY/msg -nt $MONDIR/zabbix-latest ]; then
42                echo "Facility $FACILITY has changed since last send."
43                STATE=`cat $FACILITY/state`
44                MODIFY_TIME=`stat --format=%Y $FACILITY/state`
45                MSG=`cat $FACILITY/msg | tr '\n' ' '`
46                UPDATES="$UPDATES""- syn3.state[$FACILITY] $STATE, $MSG\n"
47        fi
48done
49
50
51if [ "$UPDATES" != "" ]; then
52        echo "Sending updates to zabbix:"
53        echo -en "$UPDATES"
54        if echo -en "$UPDATES" | zabbix_sender -vv  -c /etc/zabbix/zabbix_agentd.conf -i -; then
55                #only if everything went ok, we update the timestamp of the latest-file. otherwise everything will be send again.
56                mv $MONDIR/.zabbix-time $MONDIR/zabbix-latest
57                echo "All updates sent ok."
58        else
59                echo "Error while sending, will try again later."
60                exit 1
61        fi
62else
63        echo "No changes found"
64fi
65
Note: See TracBrowser for help on using the repository browser.