Show
Ignore:
Timestamp:
11/03/08 19:44:01 (5 years ago)
Author:
kakikubo
Message:

beta version

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/nagios-plugins/check_memcached.py

    r22633 r22634  
    11#! /usr/bin/env python 
    22''' 
    3 check_memcache.py  
    4 set the temporary key and delete 
     3 
     4  2007 Kakikubo Teruo 
     5  check_memcache.py  
     6 
     7  Check Memcached Server plugin.  
     8  This Plugin requires the memcached-Python API.  
     9  This Plugin was tested only in the python 2.5  
    510 
    611''' 
    712import memcache 
    813import signal 
    9 import os 
     14import os,sys 
    1015 
    1116from optparse import OptionParser 
     17 
    1218pid = str(os.getpid()) 
    1319# option 
    1420parser = OptionParser() 
    1521parser.add_option("-H","--hostname",dest="hostaddress", 
    16                   help="Host Address", metavar="hostaddr") 
     22                  help="Host Address", metavar=" <hostaddr>") 
    1723parser.add_option("-t","--timeout",dest="timeout", 
    18                   help="timeout x seconds", metavar="timo", default=10) 
     24                  help="timeout x seconds", metavar=" <timeout>", default=10) 
    1925parser.add_option("-p","--port",dest="port", 
    20                   help="port number", metavar="pt" , default=11211) 
     26                  help="port number", metavar=" <port number>" , default=11211) 
    2127(opts,args)=parser.parse_args() 
    2228 
    2329if not opts.hostaddress: 
    2430    parser.print_help() 
    25     parser.error("Please specify Host") 
     31    parser.error("UNKNOWN - Please specify Host") 
    2632    exit(2) 
    2733 
    2834svr = u"" 
    2935svr = str(opts.hostaddress) + ":" + str(opts.port) 
    30 mc = memcache.Client([ svr ], debug=1) 
     36mc = memcache.Client([ svr ], debug=0) 
    3137#mc = memcache.Client({opts.hostaddress}:{opts.port}, debug=1) 
    3238#mc = memcache.Client(["ocnblg-tc01-int:112"], debug=1) 
     39 
     40def handler(signum, frame): 
     41    #print 'Signal handler called with signal', signum 
     42    #raise IOError, "hogehogehgoehgoe" 
     43    print "CRITICAL - timeout after " + str(opts.timeout) + " seconds" 
     44    sys.exit(2) 
     45 
     46## Set the signal handler 
     47signal.signal(signal.SIGALRM, handler) 
     48signal.alarm(int(opts.timeout)) 
     49 
    3350if not mc.set(pid,"nagios value"): 
    34     raise ValueError,"CRITICAL - cannot set the value" 
    35     exit(2) 
     51    print "CRITICAL - cannot set the value" 
     52    sys.exit(2) 
    3653else: 
    3754    if not mc.get(pid) == 'nagios value': 
    38         raise ValueError, "CRITICAL - cannot get the value" 
    39         exit(2) 
     55        print "CRITICAL - cannot get the value" 
     56        sys.exit(2) 
    4057    else: 
    4158        mc.delete(pid) 
    4259        print "OK - memcached alive" 
    43         exit  
     60        sys.exit(0) 
     61