Coder Social home page Coder Social logo

pentagridsec / icinga_check_mail_loop Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 7 KB

check_mail_loop.py is a Nagios/Icinga plugin that checks an e-mail flow from sending an e-mail via SMTP to retrieving it from an IMAP server.

License: Other

Python 100.00%
icinga2-plugin imap monitoring-plugin nagios-plugin smtp

icinga_check_mail_loop's Introduction

Introduction

check_mail_loop.py is a Nagios/Icinga plugin that checks an e-mail flow from sending an e-mail via SMTP to retrieving it from an IMAP server.

Testing mail delivery is not only a matter of SMTP server availability, but nowadays also a matter of mail server reputation. If your mail server's reputation is poor, delivered e-mails may end up in spam folders.

The plugin creates an E-mail with a UUID tag in the E-mail header and tries to find it later via IMAP. It checks the Inbox and if necessary also the Junk mail box. E-mails are deleted by default in the test box.

The script returns OK if the expected UUID was found (exit code 0). If the E-mail was not found at all, the ERROR is returned (exit code 2). If the E-mail ended up in the Spam box, a WARNING is returned (exit code 1).

You may want to use this check script with:

Installation

  • Install dependencies:
apt install python3-imaplib2
  • Install the script check_mail_loop.py on your monitoring station under /usr/local/bin/check_mail_loop.py.
  • Now, define the check command. Depending on your setup, edit for example /etc/icinga2/conf.d/commands_check_mail_loop.conf:
object CheckCommand "mail_loop" {
  import "plugin-check-command"

  env.SMTP_PASS = "$mail_loop_smtp_pass$"
  env.IMAP_PASS = "$mail_loop_imap_pass$"

  command = [ "/usr/local/bin/check_mail_loop.py",
          "--mail-from", "$mail_loop_mail_from$",
          "--mail-to", "$mail_loop_mail_to$",
          "--smtp-host", "$mail_loop_smtp_host$",
          "--smtp-port", "$mail_loop_smtp_port$",
          "--smtp-user", "$mail_loop_smtp_user$",
          "--imap-host", "$mail_loop_imap_host$",
          "--imap-port", "$mail_loop_imap_port$",
          "--imap-user", "$mail_loop_imap_user$",
          "--imap-spam", "$mail_loop_imap_spam$",
          "--imap-cleanup" ]
}
  • Set up dedicated E-mail accounts. The flag --imap-cleanup instructs the plugin to remove all E-mails from the IMAP account.
  • Add a configuration file for Icinga, for example /etc/icinga2/conf.d/services_mail_loop.conf:
object Service "mail-loop-mail.example.org" {
  import "generic-service-internet"
  host_name = "mail.example.org"
  check_command = "mail_loop"

  vars.mail_loop_mail_from = "[email protected]"
  vars.mail_loop_mail_to = "[email protected]"

  # Configuration for E-mail delivery.
  vars.mail_loop_smtp_host = "mail.example.org"
  vars.mail_loop_smtp_port = "465"
  vars.mail_loop_smtp_user = "[email protected]"
  vars.mail_loop_smtp_pass = "secret"

  # IMAP configuration on the Receiving side.
  # If you use Gmail, you need to enable IMAP with password.
  vars.mail_loop_imap_host = "imap.gmail.com"
  vars.mail_loop_imap_port = "993"
  vars.mail_loop_imap_user = "[email protected]"
  vars.mail_loop_imap_pass = "secret"
  vars.mail_loop_imap_spam = "[Gmail]/Spam"

  # Be polite and do not send too frequently.
  check_interval = 24h
  max_check_attempts = 4
  retry_interval = 4h
}
  • Fix permissions of your config file. Otherwise passwords may leak.
chown root.icinga /etc/icinga2/conf.d/services_mail_loop.conf
chmod 640 /etc/icinga2/conf.d/services_mail_loop.conf

Copyright and Licence

check_mail_loop.py is developed by Martin Schobert <[email protected]> and published under a BSD licence with a non-military clause. Please read LICENSE.txt for further details.

icinga_check_mail_loop's People

Contributors

nitram2342 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.