Changeset 4060 for monitoring


Ignore:
Timestamp:
11/19/13 16:46:25 (11 years ago)
Author:
sanmai
Message:
  • Fix redirects from http URLs to https URLs, taking care of the query, etc.
File:
1 edited

Legend:

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

    r4058 r4060  
    276276    #if authorize is None : authorize = True
    277277
    278     try:
     278    try :
    279279        port_number = int(port_number)
    280280    except ValueError :
     
    282282         "message"   : 'The port number specified, "{0}", cannot be converted to an integer.'.format(port_number)
    283283       }
     284    except TypeError :
     285        port_number = None
    284286
    285287    def handle_connection_failure(problem_description) :
     
    302304                                          strict = True)
    303305        elif protocol == 'https' :
     306
     307           
    304308            conn = httplib.HTTPSConnection(host = host,
    305309                                           port = port_number,
     
    314318        return {
    315319                "code"      : "CRITICAL",
    316                 "message"   : 'HTTP connection to host %s failed.' % (host)
     320                "message"   : '{protocol} connection on port {port_number} to host "{host}" failed.'.format(protocol = protocol,
     321                                                                                                            port_number = port_number,
     322                                                                                                            host = host)
    317323               }
    318324    else :
     
    344350
    345351                if well_formed :
     352
    346353                    return {
    347354                            "code"      : "OK",
    348                             "message"   : 'Host %s is up and returns well-formed data at "%s".' % (host, http_path)
     355                            "message"   : 'Host "{host}" is up and returns well-formed data at "{http_path}".'.format(host = host, http_path = http_path)
    349356                           }
    350357                else :
    351358                    return {
    352359                            "code"      : "CRITICAL",
    353                             "message"   : 'Host %s is up but returns non-well-formed data at "%s".' % (host, http_path)
     360                            "message"   : 'Host "{host}" is up but returns non-well-formed data at "{http_path}".'.format(host = host, http_path = http_path)
    354361                            }
    355362
     
    357364                new_location_URL = dict(response.getheaders())['location']
    358365
    359                 parsed_new_location_URL = urlparse.urlparse(new_location_URL)
     366                parsed_new_location_URL = urlparse.urlsplit(new_location_URL)
     367                new_http_path = parsed_new_location_URL.path
     368                if parsed_new_location_URL.query != '' :
     369                    new_http_path = new_http_path + '?' + parsed_new_location_URL.query
    360370               
    361                 if parsed_new_location_URL.scheme == protocol and host == parsed_new_location_URL.netloc and http_path == parsed_new_location_URL.path :
     371                if parsed_new_location_URL.scheme == protocol and host == parsed_new_location_URL.netloc and http_path == new_http_path :
    362372                    return {
    363                               "code"      : "CRITICAL",
    364                               "message"   : 'Host %s is up but the response to GET "%s" implies an infinite redirection (to "%s").' % (host, http_path, http_path)
     373                              "code"    : "CRITICAL",
     374                              "message" : 'Host "{host}" is up but the response to GET "{http_path}" implies an infinite redirection to itself.'.format(host = host, http_path = http_path)
    365375                            }
    366376
    367                 else : 
     377                else :
     378
     379                    pdb.set_trace()
    368380
    369381                    return check_condition(host        = parsed_new_location_URL.netloc,
    370                                            http_path   = parsed_new_location_URL.path,
     382                                           http_path   = new_http_path,
    371383                                           protocol    = parsed_new_location_URL.scheme,
    372384                                           HTTP_method = HTTP_method,
    373                                            port_number = port_number,
     385                                           port_number = parsed_new_location_URL.port,
    374386                                           authorize   = authorize,
    375387                                           validator   = validator,
     
    379391                return {
    380392                        "code"      : "OK",
    381                         "message"   : 'Host %s is up and requests authorization at "%s".' % (host, http_path)
     393                        "message"   : 'Host "{host}" is up and requests authorization at "{http_path}".'.format(host = host, http_path = http_path)
    382394                       }
    383395
     
    389401                return {
    390402                        "code"      : "CRITICAL",
    391                         "message"   : 'Host %s has a problem with the URL path component "%s".' % (host, http_path)
     403                        "message"   : 'Host "{host}" has a problem with the URL path component "{http_path}}".'.format(host = host, http_path = http_path)
    392404                       }
    393405
Note: See TracChangeset for help on using the changeset viewer.