Changeset 3242


Ignore:
Timestamp:
08/06/13 10:40:14 (11 years ago)
Author:
sanmai
Message:
  • First work on LDAP monitoring plugin.
  • Separate processing of command-line arguments into generic plus a minimal amount of plugin-specific source code.
Location:
monitoring/plugins/mpi
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • monitoring/plugins/mpi/check_clarin_discojuice_html.py

    • Property svn:executable set to *
  • monitoring/plugins/mpi/check_clarin_discojuice_json.py

    • Property svn:executable set to *
  • monitoring/plugins/mpi/check_lat_cql_endpoint.py

    r3049 r3242  
    2323    # Check status for all UP_URLs.
    2424    results = \
    25       map(lambda UP_URL : generic_tla_monitoring.check_condition(host                      = host,
    26                                                                  UP_URL                    = UP_URL,
    27                                                                  HTTP_method               = 'GET',
    28                                                                  validator                 = generic_tla_monitoring.check_XML_validity,
    29                                                                  valid_root_element_tag    = valid_root_element_tag,
    30                                                                  special_plugin_file_name  = special_plugin_file_name),
     25        map(lambda UP_URL : generic_tla_monitoring.check_condition(host                      = host,
     26                                                                   UP_URL                    = UP_URL,
     27                                                                   HTTP_method               = 'GET',
     28                                                                   validator                 = generic_tla_monitoring.check_XML_validity,
     29                                                                   valid_root_element_tag    = valid_root_element_tag,
     30                                                                   special_plugin_file_name  = special_plugin_file_name),
    3131          UP_URLs)
    3232   
  • monitoring/plugins/mpi/generic_tla_monitoring.py

    r3051 r3242  
    3333    sys.exit(max(suggested_exit_codes))
    3434
    35 def usage() :
    36     """ returns nagios status UNKNOWN with
     35def usage(command_line_parameters_usage_string) :
     36    """ returns Nagios status UNKNOWN with
    3737        a one line usage description
    3838        usage() calls nagios_return()
    3939    """
    4040    nagios_return('UNKNOWN',
    41                   "usage: %s -h host" % (sys.argv[0]))
     41                  "usage: " + sys.argv[0] + command_line_parameters_usage_string)
    4242
    4343def generic_validator(data,
     
    133133                                       special_validator)
    134134    return (wellformedness)
     135
     136
     137def check_LDAP_validity(data,
     138                       descriptive_string,
     139                       **kwargs) :
     140
     141    def special_validator(data,
     142                          descriptive_string,
     143                          kwargs) :
     144        try :           
     145            return True # X-
     146        except :
     147            return False
     148
     149    wellformedness = generic_validator(data,
     150                                       descriptive_string,
     151                                       kwargs,
     152                                       special_validator)
     153    return (wellformedness)
     154
     155
     156def check_ldap(host,
     157               bindDN,
     158               validator,
     159               **validator_arguments) :
     160
     161    OpenDJ_directory_path = '/srv/LDAP/OpenDJ-2.5.0-Xpress1/'
     162
     163    command = [OpenDJ_directory_path + "/bin/ldapsearch",
     164              '--port', '10389',
     165              '--baseDN', 'dc=clarin,dc=eu',
     166              '--useStartTLS',
     167              '--trustAll',
     168              '--hostname', "'" + host + "'",
     169              '--bindDN', "'" + bindDN + "'",
     170              "--bindPasswordFile", "'/root/LDAP_passwdfile'",
     171              "'(objectClass=CLARINPerson)'",
     172              'isMemberOf']
     173
     174    # Run OpenDJ's "ldapsearch" command line utility
     175    pdb.set_trace()
     176   
     177    process = subprocess.Popen(command,
     178                               stdout = subprocess.PIPE,
     179                               stderr = subprocess.PIPE)
     180
     181    stdout, stderr = process.communicate()
     182
     183    print stdout
     184    print stderr
     185
     186    pdb.set_trace()
     187
     188    if response :
     189        return {
     190                "code"      : "OK",
     191                "message"   : 'Host %s is up and responds as expected.' % (host, UP_URL)
     192               }
     193    else :
     194        return {
     195                "code"      : "CRITICAL",
     196                "message"   : 'Host %s is up but does not respond as expected.' % (host, UP_URL)
     197                }
     198
    135199
    136200def check_condition(host,
     
    227291                       }
    228292
    229 def main(special_main_subroutine) :
    230     """ example options processing
    231         here we're expecting 1 option "-h"
    232         with a parameter
    233     """
    234 
    235     if len(sys.argv) < 2 :
    236         usage()
    237 
    238     try:
    239         opts, args  = getopt.getopt(sys.argv[1:], "h:u:")
     293def main(special_main_subroutine,
     294         command_line_parameters = [("-h", "host",)]) :
     295
     296    ##  Process plugin-specific command line parameters.
     297    command_line_parameters_getopt_string = command_line_parameters_usage_string = ""
     298    for (parameter, description) in command_line_parameters :
     299       command_line_parameters_usage_string = command_line_parameters_usage_string + parameter + "  " + description + "\n"
     300       command_line_parameters_getopt_string = command_line_parameters_getopt_string + parameter.lstrip("-")  + ":"
     301
     302    try :
     303        opts = filter(None, getopt.getopt(sys.argv[1:], command_line_parameters_getopt_string))[0] # X- fix other plugins with -u option
    240304    except getopt.GetoptError, err :
    241         usage()
    242    
    243     url = None
    244     for o, value in opts :
    245         if o == "-h" :
    246             host = value
    247         elif o == "-u" :
    248             url = value
    249 
     305        usage(command_line_parameters_usage_string)
     306    else :
     307        if len(command_line_parameters) == len(opts) :
     308            main_subroutine_argument_values = [parameter_value for parameter_name, parameter_value in opts]
     309            # pdb.set_trace()
     310            special_main_subroutine(*main_subroutine_argument_values)       
    250311        else :
    251             usage()
    252            
    253     # this is necessary for all old probes (annex, etc).
    254     # -u only works for cql/oai
    255     if url:   
    256         special_main_subroutine(host, url)
    257     else:
    258         special_main_subroutine(host)
     312            usage(command_line_parameters_usage_string)
     313   
    259314
    260315if __name__ == "__main__" :
Note: See TracChangeset for help on using the changeset viewer.