(**kwargs)
Perform a DigitalOcean droplet info retrieval and check status
Perform a DigitalOcean droplet info retrieval and check status
Perform a DigitalOcean droplet info retrieval and check status
def check(**kwargs):
    ''' Perform a DigitalOcean droplet info retrieval and check status '''
    jdata = kwargs['jdata']
    logger = kwargs['logger']
    headers = {'Content-Type': 'application/json',
               'Authorization': 'Bearer {0}'.format(jdata['data']['apikey'])}
    url = do_droplet_info_url.format(jdata['data']['dropletid'])

    try:
        req = requests.get(
            url, timeout=http_timeout, headers=headers, verify=True)
    except Exception as e:
        line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' \
               'had an exception: {2}'.format(url, jdata['cid'], e)
        logger.error(line)
        return False

    if req.status_code < 200 or req.status_code >= 300:
        line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' \
               'non-success HTTP code'.format(url, jdata['cid'])
        logger.warning(line)
        return False

    status = req.json()['droplet']['status']
    if status in jdata['data']['status']:
        line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' \
               'Successful'.format(url, jdata['cid'])
        logger.info(line)
        return True
    else:
        line = 'digitalocean-status: 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 = { 'Content-Type' : 'application/json' , 'Authorization' : 'Bearer {0}' . format ( jdata [ 'data' ] [ 'apikey' ] ) } url = do_droplet_info_url . format ( jdata [ 'data' ] [ 'dropletid' ] ) try : req = requests . get ( url , timeout = http_timeout , headers = headers , verify = True ) except Exception as e : line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' 'had an exception: {2}' . format ( url , jdata [ 'cid' ] , e ) logger . error ( line ) return False if req . status_code < 200 or req . status_code >= 300 : line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' 'non-success HTTP code' . format ( url , jdata [ 'cid' ] ) logger . warning ( line ) return False status = req . json ( ) [ 'droplet' ] [ 'status' ] if status in jdata [ 'data' ] [ 'status' ] : line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' 'Successful' . format ( url , jdata [ 'cid' ] ) logger . info ( line ) return True else : line = 'digitalocean-status: Reqeust to {0} sent for monitor {1} - ' 'Failure' . format ( url , jdata [ 'cid' ] ) logger . info ( line ) return False