Advertisement
Guest User

icinga maildrop mailfilter

a guest
Sep 2nd, 2010
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.35 KB | None | 0 0
  1. # icinga Mailfilter for Acknowledgement of problems
  2.  
  3. ICINGA_HOME=/usr/local/icinga
  4. #LOGFILE="${ICINGA_HOME}/mailfilter.log"
  5. CMDFILE=/usr/local/icinga/var/rw/icinga.cmd
  6. CMDLOG="${ICINGA_HOME}/commands.log"
  7.  
  8.  
  9.  
  10. # define valid senders:
  11. FQDN="example.com"
  12. # a very simple regex here:
  13. LOCALPARTS="(john|jane|john.doe)"
  14.  
  15.  
  16. # how many SMTPs will be passed?
  17. # i.e.
  18. # you authenticate against your company's smtp + 1
  19. # mail is directly delivered to your icinga's smtp +1
  20. # stations = 2
  21. SMTPSTATIONS=2
  22.  
  23.  
  24.  
  25. # Preferences for external commands - see http://www.nagios.org/developerinfo/externalcommands/
  26. STICKY=1
  27. NOTIFY=1
  28. PERSISTENT=1
  29.  
  30.  
  31. # CONFIGURATION END #
  32.  
  33. # extract sender: must be a valid address combinatiion of LOCALPARTS and FQDN
  34. if ( /^From:.*$LOCALPARTS@$FQDN/ )
  35. {
  36.         ADDR=escape($MATCH1)
  37.         ADDR="$ADDR@$FQDN"
  38. }
  39. else
  40. {
  41.         EXITCODE=1
  42.         exit
  43. }
  44.  
  45. # counts the Received: -headers. Mails that do pass more servers than defined propably dont originate from a trusted smtp and will not be processed.
  46. if (/^Received:/:1 > $SMTPSTATIONS)
  47. {
  48.         EXITCODE=2
  49.         exit
  50. }
  51.  
  52.  
  53. # extract ACK message:
  54. if ( /^ack.(.*)/:b)
  55. {
  56.      COMMENT=escape($MATCH1)
  57. }
  58. else
  59. {
  60.         COMMENT=""
  61. }
  62.  
  63. if ( /^Subject:.*PROBLEM Service Alert:.(.*)\/(.*).is/ )
  64. {
  65.         TYPE="ACKNOWLEDGE_SVC_PROBLEM"
  66.         HOST="$MATCH1"
  67.         SERVICE="$MATCH2"
  68.  
  69.         # log the command      
  70.         `/usr/bin/printf "[%lu] $TYPE;${HOST};${SERVICE};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) >> $CMDLOG`
  71.         # send the command to icinga
  72.         `/usr/bin/printf "[%lu] $TYPE;${HOST};${SERVICE};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) > $CMDFILE`
  73.  
  74.         # Backup of all incoming emails
  75.         to ${ICINGA_HOME}/service_acknowlegements
  76. }
  77.  
  78. if ( /^Subject:.*PROBLEM Host Alert:.(.*).is/ )
  79. {
  80.         TYPE="ACKNOWLEDGE_HOST_PROBLEM"
  81.         HOST="$MATCH1"
  82.  
  83.         # log the command      
  84.         `/usr/bin/printf "[%lu] $TYPE;${HOST};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) >> $CMDLOG`
  85.         # send the command to icinga
  86.         `/usr/bin/printf "[%lu] $TYPE;${HOST};$STICKY;$NOTIFY;$PERSISTENT;$ADDR;$COMMENT\n" $(date +%s) > $CMDFILE`
  87.  
  88.         # Backup of all incoming emails
  89.         to ${ICINGA_HOME}/host_acknowlegements
  90. }
  91.  
  92.  
  93. # no delivery to local recipients
  94. EXITCODE=0
  95. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement