diff options
author | mh <mh@immerda.ch> | 2015-10-25 16:28:46 +0100 |
---|---|---|
committer | mh <mh@immerda.ch> | 2015-10-25 16:28:46 +0100 |
commit | e66581b620d89e81ec02754005f3e3fa2bc603cf (patch) | |
tree | 0eb326fae835d70d600c020eb5b8654d84a867df | |
parent | edd94dd98f53c1066c7bd6253bc910c196f798fc (diff) |
add an imap_login check
-rw-r--r-- | files/plugins/check_imap_login | 80 | ||||
-rw-r--r-- | manifests/command/imap_pop3.pp | 5 | ||||
-rw-r--r-- | manifests/plugins/imap_login.pp | 7 | ||||
-rw-r--r-- | manifests/service/imap_login.pp | 20 |
4 files changed, 111 insertions, 1 deletions
diff --git a/files/plugins/check_imap_login b/files/plugins/check_imap_login new file mode 100644 index 0000000..d059822 --- /dev/null +++ b/files/plugins/check_imap_login @@ -0,0 +1,80 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# -*- Mode: Python -*- +# +# Copyright (C) 2006 Bertera Pietro <pietro@bertera.it> +# Response time monitoring with perfdata modification by Ivan Savcic <isavcic@gmail.com> and Milos Buncic, 2012. +# From: https://github.com/isavcic/check_imap_login + +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. + +import sys, os, imaplib, getopt +from time import time + +def usage(): + print sys.argv[0] + " -u <user> -p <password> -H <host> [-s] -w <warning threshold (sec)> -c <critical threshold (sec)>\n -s is for using IMAPS" + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "u:p:sH:w:c:") + except getopt.GetoptError: + usage() + return 3 + + user = host = password = use_ssl = warning = critical = None + + for o, a in opts: + if o == "-u": + user = a + elif o == "-p": + password = a + elif o == "-s": + use_ssl = True + elif o == "-H": + host = a + elif o == "-w": + warning = float(a) + elif o == "-c": + critical = float(a) + + if user == None or password == None or host == None or warning == None or critical == None: + usage() + return 1 + + if use_ssl: + M = imaplib.IMAP4_SSL(host=host) + else: + M = imaplib.IMAP4(host) + + timestamp = time() + + try: + M.login(user, password) + except Exception, e: + print "CRITICAL IMAP Login Failed: %s" % e + return 2 + + M.logout() + + timestamp = time() - timestamp + + if timestamp < warning: + status = "OK" + exitcode = 0 + if timestamp >= warning: + status = "WARNING" + exitcode = 1 + if timestamp >= critical: + status = "CRITICAL" + exitcode = 2 + + print '%s IMAP Login | response_time=%.3fs;%.3f;%.3f' % (status, timestamp, warning, critical) + + return exitcode + +if __name__ == "__main__": + sys.exit(main()) diff --git a/manifests/command/imap_pop3.pp b/manifests/command/imap_pop3.pp index f3637a7..fbe4182 100644 --- a/manifests/command/imap_pop3.pp +++ b/manifests/command/imap_pop3.pp @@ -1,7 +1,8 @@ # manage mail checks class nagios::command::imap_pop3 { + require ::nagios::plugins::imap_login case $::operatingsystem { - debian,ubuntu: { } # Debian/Ubuntu already define those checks + 'Debian','Ubuntu': { } # Debian/Ubuntu already define those checks default: { nagios_command { 'check_imap': @@ -21,5 +22,7 @@ class nagios::command::imap_pop3 { command_line => '$USER1$/check_tcp -H $ARG1$ -p 4190'; 'check_managesieve_legacy': command_line => '$USER1$/check_tcp -H $ARG1$ -p 2000'; + 'check_imap_login': + command_line => '$USER1$/check_imap_login -H $ARG1$ -u $ARG2$ -p $ARG3$ -w $ARG4$ -c $ARG5$'; } } diff --git a/manifests/plugins/imap_login.pp b/manifests/plugins/imap_login.pp new file mode 100644 index 0000000..bb53b81 --- /dev/null +++ b/manifests/plugins/imap_login.pp @@ -0,0 +1,7 @@ +# a simple imap login check +class nagios::plugins::imap_login { + nagios::plugin { 'check_imap_login': + source => 'nagios/plugins/check_imap_login', + } +} + diff --git a/manifests/service/imap_login.pp b/manifests/service/imap_login.pp new file mode 100644 index 0000000..53c432a --- /dev/null +++ b/manifests/service/imap_login.pp @@ -0,0 +1,20 @@ +# a imap login check +define nagios::service::imap_login( + $username, + $password, + $warning = 5, + $critical = 10, + $host = $::fqdn, + $ensure = 'present', +){ + nagios::service{ + "imap_login_${name}": + ensure => $ensure; + } + + if $ensure != 'absent' { + Nagios::Service["imap_login_${name}"]{ + check_command => "check_imap_login!${host}!${username}!${password}!${warning}!${critical}", + } + } +} |