(**kwargs)
Perform a http get request and validate the return code
Perform a http get request and validate the return code
Perform a http get request and validate the return code
def check(**kwargs):
    """ Perform a http get request and validate the return code """
    jdata = kwargs['jdata']
    logger = kwargs['logger']
    headers = {}
    if 'extra_headers' in jdata['data']:
      headers = ParseHeaders(jdata['data']['extra_headers'])
    headers['host'] = jdata['data']['host']
    timeout = 3.00
    url = jdata['data']['url']
    try:
        result = requests.get(
            url, timeout=timeout, headers=headers, verify=False, stream=True)
    except Exception as e:
        line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' \
               'had an exception: {2}'.format(url, jdata['cid'], e)
        logger.error(line)
        return False
    rcode = str(result.status_code)
    result.close()
    if rcode in jdata['data']['codes']:
        line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' \
               'Successful'.format(url, jdata['cid'])
        logger.info(line)
        return True
    else:
        line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' \
               'Failure'.format(url, jdata['cid'])
        logger.info(line)
        return False
def check ( * * kwargs ) : jdata = kwargs [ 'jdata' ] logger = kwargs [ 'logger' ] headers = { } if 'extra_headers' in jdata [ 'data' ] : headers = ParseHeaders ( jdata [ 'data' ] [ 'extra_headers' ] ) headers [ 'host' ] = jdata [ 'data' ] [ 'host' ] timeout = 3.00 url = jdata [ 'data' ] [ 'url' ] try : result = requests . get ( url , timeout = timeout , headers = headers , verify = False , stream = True ) except Exception as e : line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' 'had an exception: {2}' . format ( url , jdata [ 'cid' ] , e ) logger . error ( line ) return False rcode = str ( result . status_code ) result . close ( ) if rcode in jdata [ 'data' ] [ 'codes' ] : line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' 'Successful' . format ( url , jdata [ 'cid' ] ) logger . info ( line ) return True else : line = 'http-get-statuscode: Reqeust to {0} sent for monitor {1} - ' 'Failure' . format ( url , jdata [ 'cid' ] ) logger . info ( line ) return False