Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # icinga Mailfilter for Acknowledgement of problems
- ICINGA_HOME=/usr/local/icinga
- #LOGFILE="${ICINGA_HOME}/mailfilter.log"
- CMDFILE=/usr/local/icinga/var/rw/icinga.cmd
- CMDLOG="${ICINGA_HOME}/commands.log"
- # define valid senders:
- FQDN="example.com"
- # a very simple regex here:
- LOCALPARTS="(john|jane|john.doe)"
- # how many SMTPs will be passed?
- # i.e.
- # you authenticate against your company's smtp + 1
- # mail is directly delivered to your icinga's smtp +1
- # stations = 2
- SMTPSTATIONS=2
- # Preferences for external commands - see http://www.nagios.org/developerinfo/externalcommands/
- STICKY=1
- NOTIFY=1
- PERSISTENT=1
- # CONFIGURATION END #
- # extract sender: must be a valid address combinatiion of LOCALPARTS and FQDN
- if ( /^From:.*$LOCALPARTS@$FQDN/ )
- {
- ADDR=escape($MATCH1)
- ADDR="$ADDR@$FQDN"
- }
- else
- {
- EXITCODE=1
- exit
- }
- # counts the Received: -headers. Mails that do pass more servers than defined propably dont originate from a trusted smtp and will not be processed.
- if (/^Received:/:1 > $SMTPSTATIONS)
- {
- EXITCODE=2
- exit
- }
- # extract ACK message:
- if ( /^ack.(.*)/:b)
- {
- COMMENT=escape($MATCH1)
- }
- else
- {
- COMMENT=""
- }
- if ( /^Subject:.*PROBLEM Service Alert:.(.*)\/(.*).is/ )
- {
- TYPE="ACKNOWLEDGE_SVC_PROBLEM"
- HOST="$MATCH1"
- SERVICE="$MATCH2"
- # log the command
- `/usr/bin/printf "[%lu] $TYPE;${HOST};${SERVICE};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) >> $CMDLOG`
- # send the command to icinga
- `/usr/bin/printf "[%lu] $TYPE;${HOST};${SERVICE};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) > $CMDFILE`
- # Backup of all incoming emails
- to ${ICINGA_HOME}/service_acknowlegements
- }
- if ( /^Subject:.*PROBLEM Host Alert:.(.*).is/ )
- {
- TYPE="ACKNOWLEDGE_HOST_PROBLEM"
- HOST="$MATCH1"
- # log the command
- `/usr/bin/printf "[%lu] $TYPE;${HOST};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) >> $CMDLOG`
- # send the command to icinga
- `/usr/bin/printf "[%lu] $TYPE;${HOST};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) > $CMDFILE`
- # Backup of all incoming emails
- to ${ICINGA_HOME}/host_acknowlegements
- }
- # no delivery to local recipients
- EXITCODE=0
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement