check_zarafa_login.py
changeset 1 ec1f8cb59b7e
parent 0 9da56a166477
equal deleted inserted replaced
0:9da56a166477 1:ec1f8cb59b7e
     1 #!/usr/bin/python
     1 #!/usr/bin/python
       
     2 # vim: set fileencoding=utf-8 :
     2 
     3 
     3 import sys, traceback
     4 # argparse gibt es erst ab python 2.7
       
     5 import sys, getopt, traceback
       
     6 import ConfigParser
     4 import MAPI
     7 import MAPI
     5 from MAPI.Util import *
     8 from MAPI.Util import *
     6 
     9 
     7 user = 'klaus'
    10 configfile = '/etc/nagios-plugins/config/zarafa-login.cfg'
     8 pw   = 'geheim!'
    11 exitcodes = { 'OK': 0, 'CRITICAL': 2 }
     9 url  = 'http://localhost:236/zarafa'
       
    10 
    12 
    11 exit = { 'OK': 0, 'CRITICAL': 2 }
    13 # backtrace abfangen damit wir den exit status setzen können
       
    14 try:
       
    15 	opts, args = getopt.getopt(sys.argv[1:], "c:", ["config-file="])
       
    16 	for o, a in opts:
       
    17 		if o in ("-c", "--config-file"):
       
    18 			configfile = a
       
    19 		else:
       
    20 			assert False, "Unhandled option"
       
    21 	config = ConfigParser.RawConfigParser()
       
    22 	config.read(configfile)
       
    23 	p = [config.get('DEFAULT', k) for k in ['user', 'pw', 'url']]
       
    24 	session = OpenECSession(*p)
       
    25 	ec = 'OK'
    12 
    26 
    13 try:
       
    14 	session = OpenECSession(user, pw, url)
       
    15 except:
    27 except:
       
    28 	ec = 'CRITICAL'
       
    29 
       
    30 print ec
       
    31 if ec != 'OK':
    16 	traceback.print_exc(file=sys.stdout)
    32 	traceback.print_exc(file=sys.stdout)
    17 	sys.exit(exit['CRITICAL'])
       
    18 
    33 
    19 sys.exit(exit['OK']);
    34 sys.exit(exitcodes[ec]);