<s> import socket <EOL> from os import getenv <EOL> from os import path <EOL> from sys import exit <EOL> import sys <EOL> import urlparse <EOL> import uuid <EOL> from swiftclient import Connection <EOL> from swiftclient import ClientException <EOL> from swiftclient import http_connection <EOL> from swiftclient import RequestException <EOL> from requests . exceptions import ConnectionError <EOL> import time <EOL> import argparse <EOL> import ConfigParser <EOL> from swiftlm . utils . utility import get_logger <EOL> from swiftlm . utils . utility import dump_swiftlm_uptime_data , timestamp , Enum <EOL> from httplib import HTTPException <EOL> SERVICE_NAME = '<STR_LIT>' <EOL> AVG_LATENCY = '<STR_LIT>' <EOL> MAX_LATENCY = '<STR_LIT>' <EOL> HARD_STATE = '<STR_LIT>' <EOL> INFO_STATE = '<STR_LIT>' <EOL> COMPONENT_KEYSTONE_GET_TOKEN = '<STR_LIT>' <EOL> COMPONENT_REST_API = '<STR_LIT>' <EOL> COMPONENT_HEALTHCHECK_API = '<STR_LIT>' <EOL> common_dimensions = dict ( ) <EOL> component_states = Enum ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> STATE_VALUE_OK = <NUM_LIT:0> <EOL> STATE_VALUE_FAILED = <NUM_LIT:1> <EOL> STATE_VALUE_UNKNOWN = <NUM_LIT:3> <EOL> severities = Enum ( [ '<STR_LIT:info>' , '<STR_LIT>' ] ) <EOL> class UPtimeMonException ( Exception ) : <EOL> pass <EOL> def health_check ( url , logger ) : <EOL> scheme = urlparse . urlparse ( url ) . scheme <EOL> netloc = urlparse . urlparse ( url ) . netloc <EOL> url = scheme + '<STR_LIT>' + netloc + '<STR_LIT>' <EOL> parsed , conn = http_connection ( url ) <EOL> logger . debug ( '<STR_LIT>' % url ) <EOL> conn . request ( '<STR_LIT:GET>' , parsed . path , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> resp = conn . getresponse ( ) <EOL> resp . read ( ) <EOL> if resp . status < <NUM_LIT:200> or resp . status >= <NUM_LIT> : <EOL> raise ClientException ( '<STR_LIT>' , <EOL> http_scheme = parsed . scheme , <EOL> http_host = conn . host , http_port = conn . port , <EOL> http_path = parsed . path , http_status = resp . status , <EOL> http_reason = resp . reason ) <EOL> resp_headers = { } <EOL> for header , value in resp . getheaders ( ) : <EOL> resp_headers [ header . lower ( ) ] = value <EOL> return resp_headers <EOL> def endpoint_trim ( url , extension = None ) : <EOL> s = urlparse . urlparse ( url ) . netloc . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> if extension is None : <EOL> return s <EOL> else : <EOL> return s + '<STR_LIT:->' + extension <EOL> class TrackConnection ( Connection ) : <EOL> def __init__ ( self , auth_url , user_name , key , logger , cache_file_path , <EOL> object_store_url = None , auth_version = "<STR_LIT:2>" , <EOL> os_options = None ) : <EOL> socket . setdefaulttimeout ( <NUM_LIT> ) <EOL> Connection . __init__ ( self , auth_url , user_name , key , retries = <NUM_LIT:0> , <EOL> os_options = os_options , <EOL> auth_version = auth_version ) <EOL> self . object_store_url = object_store_url <EOL> self . state = dict ( ) <EOL> for sev in severities : <EOL> for component_name in self . component_names ( ) : <EOL> self . state [ component_name + sev ] = dict ( current_state = component_states . unknown , <EOL> reason = '<STR_LIT>' , <EOL> metrics = { } ) <EOL> self . latency = dict ( ) <EOL> self . metric_data = [ ] <EOL> self . latency_reset ( ) <EOL> self . logger = logger <EOL> self . cache_file_path = cache_file_path <EOL> @ staticmethod <EOL> def component_names ( ) : <EOL> return ( COMPONENT_KEYSTONE_GET_TOKEN , <EOL> COMPONENT_REST_API , <EOL> COMPONENT_HEALTHCHECK_API ) <EOL> def metric_data_reset ( self ) : <EOL> self . metric_data = [ ] <EOL> def dump_metric_data ( self ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> for sev in severities : <EOL> for component_name in self . component_names ( ) : <EOL> self . metric_data . append ( self . state [ component_name + <EOL> sev ] [ '<STR_LIT>' ] ) <EOL> self . logger . debug ( self . metric_data ) <EOL> dump_swiftlm_uptime_data ( self . metric_data , <EOL> self . cache_file_path , <EOL> self . logger ) <EOL> def latency_reset ( self ) : <EOL> for component_name in self . component_names ( ) : <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] = <NUM_LIT:0> <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] = <NUM_LIT:0> <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] = <NUM_LIT:0> <EOL> def latency_record ( self , component_name , duration ) : <EOL> if duration > self . latency [ ( component_name , '<STR_LIT>' ) ] : <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] = duration <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] += <NUM_LIT:1> <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] += duration <EOL> def latency_write_log ( self ) : <EOL> for component_name in self . component_names ( ) : <EOL> if self . latency [ ( component_name , '<STR_LIT>' ) ] == <NUM_LIT:0> : <EOL> self . logger . debug ( '<STR_LIT>' <EOL> % component_name ) <EOL> continue <EOL> avg_latency = float ( self . latency [ ( component_name , '<STR_LIT>' ) ] / <EOL> self . latency [ ( component_name , '<STR_LIT>' ) ] ) <EOL> max_latency = self . latency [ ( component_name , '<STR_LIT>' ) ] <EOL> self . logger . debug ( '<STR_LIT>' <EOL> % ( component_name , avg_latency ) ) <EOL> self . logger . debug ( '<STR_LIT>' <EOL> % ( component_name , max_latency ) ) <EOL> dimensions = common_dimensions . copy ( ) <EOL> dimensions [ '<STR_LIT>' ] = component_name <EOL> if component_name == COMPONENT_KEYSTONE_GET_TOKEN : <EOL> dimensions [ '<STR_LIT:url>' ] = self . authurl <EOL> else : <EOL> dimensions [ '<STR_LIT:url>' ] = self . object_store_url <EOL> self . metric_data . append ( <EOL> dict ( metric = AVG_LATENCY , value = avg_latency , <EOL> dimensions = dimensions , timestamp = timestamp ( ) ) ) <EOL> self . metric_data . append ( <EOL> dict ( metric = MAX_LATENCY , value = max_latency , <EOL> dimensions = dimensions , timestamp = timestamp ( ) ) ) <EOL> def record_state ( self , sev , component_name , new_state , reason ) : <EOL> self . logger . debug ( "<STR_LIT>" % <EOL> ( sev , component_name , new_state , reason ) ) <EOL> k = component_name + sev <EOL> if k in self . state . keys ( ) : <EOL> old_state = self . state [ component_name + sev ] <EOL> else : <EOL> old_state = component_states . unknown <EOL> state_details = dict ( current_state = old_state , <EOL> reason = '<STR_LIT>' , <EOL> metrics = { } ) <EOL> self . state [ component_name + severities . info ] = state_details <EOL> self . state [ component_name + severities . hard ] = state_details <EOL> if old_state != new_state : <EOL> now = time . time ( ) <EOL> state_details = self . state [ component_name + sev ] <EOL> state_details [ '<STR_LIT>' ] = new_state <EOL> state_details [ '<STR_LIT>' ] = reason <EOL> dimensions = common_dimensions . copy ( ) <EOL> dimensions [ '<STR_LIT>' ] = component_name <EOL> if component_name == COMPONENT_KEYSTONE_GET_TOKEN : <EOL> dimensions [ '<STR_LIT:url>' ] = self . authurl <EOL> else : <EOL> dimensions [ '<STR_LIT:url>' ] = self . object_store_url <EOL> if sev == severities . info : <EOL> metric_name = INFO_STATE <EOL> elif sev == severities . hard : <EOL> metric_name = HARD_STATE <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % sev ) <EOL> if new_state == component_states . failed : <EOL> state_details [ '<STR_LIT>' ] = dict ( metric = metric_name , <EOL> value = STATE_VALUE_FAILED , <EOL> dimensions = dimensions , <EOL> timestamp = timestamp ( ) , <EOL> value_meta = { '<STR_LIT>' : str ( reason ) } ) <EOL> elif new_state == component_states . ok : <EOL> state_details [ '<STR_LIT>' ] = dict ( metric = metric_name , <EOL> value = STATE_VALUE_OK , <EOL> dimensions = dimensions , <EOL> timestamp = timestamp ( ) ) <EOL> else : <EOL> state_details [ '<STR_LIT>' ] = dict ( metric = metric_name , <EOL> value = STATE_VALUE_UNKNOWN , <EOL> dimensions = dimensions , <EOL> timestamp = timestamp ( ) ) <EOL> message = '<STR_LIT>' . format ( component_name , new_state , reason ) <EOL> self . logger . info ( '<STR_LIT>' <EOL> % ( time . strftime ( '<STR_LIT>' , <EOL> time . gmtime ( now ) ) , now , sev , <EOL> message . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) ) ) <EOL> def check_keystone_get_token ( self ) : <EOL> retries = <NUM_LIT:1> <EOL> attempts = <NUM_LIT:0> <EOL> component = COMPONENT_KEYSTONE_GET_TOKEN <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> while attempts <= retries : <EOL> start_time = time . time ( ) <EOL> try : <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> start_time = time . time ( ) <EOL> self . url , token = self . get_auth ( ) <EOL> duration = time . time ( ) - start_time <EOL> self . latency_record ( component , duration ) <EOL> self . logger . debug ( '<STR_LIT>' <EOL> % ( self . token , duration ) ) <EOL> self . token = token <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> except ( socket . error , HTTPException , ClientException , <EOL> ConnectionError ) as err : <EOL> duration = time . time ( ) - start_time <EOL> self . latency_record ( component , duration ) <EOL> self . record_state ( severities . info , component , <EOL> component_states . failed , err ) <EOL> component_state = component_states . failed <EOL> reason = err <EOL> if component_state == component_states . failed : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> attempts += <NUM_LIT:1> <EOL> else : <EOL> attempts = retries + <NUM_LIT:1> <EOL> self . record_state ( severities . hard , component , component_state , reason ) <EOL> self . record_state ( severities . info , component , component_state , reason ) <EOL> return component_state <EOL> def check_object_store ( self ) : <EOL> if not self . token : <EOL> self . record_state ( severities . info , COMPONENT_REST_API , <EOL> component_states . failed , <EOL> '<STR_LIT>' ) <EOL> self . record_state ( severities . hard , COMPONENT_REST_API , <EOL> component_states . failed , <EOL> '<STR_LIT>' ) <EOL> return <EOL> retries = <NUM_LIT:3> <EOL> attempts = <NUM_LIT:0> <EOL> tinyobj_contents = str ( uuid . uuid4 ( ) ) <EOL> tinyobj_name = '<STR_LIT>' + socket . gethostname ( ) <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> while attempts <= retries : <EOL> obj_start_time = time . time ( ) <EOL> start_time = obj_start_time <EOL> try : <EOL> self . http_conn = None <EOL> self . logger . debug ( '<STR_LIT>' ) <EOL> obj_start_time = time . time ( ) <EOL> start_time = obj_start_time <EOL> self . head_account ( ) <EOL> duration = time . time ( ) - start_time <EOL> self . logger . debug ( '<STR_LIT>' % duration ) <EOL> start_time = time . time ( ) <EOL> self . put_container ( '<STR_LIT>' ) <EOL> duration = time . time ( ) - start_time <EOL> self . logger . debug ( '<STR_LIT>' % duration ) <EOL> start_time = time . time ( ) <EOL> self . put_object ( '<STR_LIT>' , tinyobj_name , <EOL> tinyobj_contents ) <EOL> duration = time . time ( ) - start_time <EOL> self . logger . debug ( '<STR_LIT>' % duration ) <EOL> start_time = time . time ( ) <EOL> headers , body = self . get_object ( '<STR_LIT>' , <EOL> tinyobj_name , <EOL> resp_chunk_size = <NUM_LIT> ) <EOL> chunks = [ ] <EOL> for chunk in body : <EOL> self . logger . debug ( '<STR_LIT>' % chunk ) <EOL> chunks . append ( chunk ) <EOL> duration = time . time ( ) - start_time <EOL> self . logger . debug ( '<STR_LIT>' % duration ) <EOL> start_time = time . time ( ) <EOL> self . delete_object ( '<STR_LIT>' , tinyobj_name ) <EOL> duration = time . time ( ) - start_time <EOL> self . logger . debug ( '<STR_LIT>' % duration ) <EOL> duration = time . time ( ) - obj_start_time <EOL> self . latency_record ( COMPONENT_REST_API , duration ) <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> except ( socket . error , HTTPException , ClientException , <EOL> ConnectionError ) as err : <EOL> duration = time . time ( ) - start_time <EOL> self . latency_record ( COMPONENT_REST_API , duration ) <EOL> self . record_state ( severities . info , COMPONENT_REST_API , <EOL> component_states . failed , err ) <EOL> component_state = component_states . failed <EOL> reason = err <EOL> if component_state == component_states . failed : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> attempts += <NUM_LIT:1> <EOL> else : <EOL> attempts = retries + <NUM_LIT:1> <EOL> self . record_state ( severities . hard , COMPONENT_REST_API , component_state , <EOL> reason ) <EOL> self . record_state ( severities . info , COMPONENT_REST_API , component_state , <EOL> reason ) <EOL> return component_state <EOL> def check_object_store_health_check ( self , logger ) : <EOL> component = COMPONENT_HEALTHCHECK_API <EOL> retries = <NUM_LIT:3> <EOL> attempts = <NUM_LIT:0> <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> while attempts <= retries : <EOL> start_time = time . time ( ) <EOL> try : <EOL> self . http_conn = None <EOL> logger . debug ( '<STR_LIT>' ) <EOL> start_time = time . time ( ) <EOL> health_check ( self . object_store_url , self . logger ) <EOL> duration = time . time ( ) - start_time <EOL> self . latency_record ( component , duration ) <EOL> logger . debug ( '<STR_LIT>' % duration ) <EOL> component_state = component_states . ok <EOL> reason = '<STR_LIT:success>' <EOL> except ( socket . error , HTTPException , ClientException , <EOL> RequestException , ConnectionError ) as err : <EOL> duration = time . time ( ) - start_time <EOL> self . latency_record ( component , duration ) <EOL> self . record_state ( severities . info , component , <EOL> component_states . failed , err ) <EOL> component_state = component_states . failed <EOL> reason = err <EOL> if component_state == component_states . failed : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> attempts += <NUM_LIT:1> <EOL> else : <EOL> attempts = retries + <NUM_LIT:1> <EOL> self . record_state ( severities . hard , component , component_state , reason ) <EOL> self . record_state ( severities . info , component , component_state , reason ) <EOL> return component_state <EOL> def main_loop ( parsed_arguments , logger ) : <EOL> args_to_log = [ ( key , value ) for key , value in parsed_arguments . iteritems ( ) <EOL> if key != '<STR_LIT:password>' ] <EOL> logger . info ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT:%s>' % args_to_log ) <EOL> os_options = { } <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> os_options [ '<STR_LIT>' ] = parsed_arguments [ '<STR_LIT>' ] <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> os_options [ '<STR_LIT>' ] = parsed_arguments [ '<STR_LIT>' ] <EOL> elif parsed_arguments [ '<STR_LIT>' ] : <EOL> os_options [ '<STR_LIT>' ] = parsed_arguments [ '<STR_LIT>' ] <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> os_options [ '<STR_LIT>' ] = parsed_arguments [ '<STR_LIT>' ] <EOL> conn = TrackConnection ( parsed_arguments [ '<STR_LIT>' ] , <EOL> parsed_arguments [ '<STR_LIT>' ] , <EOL> parsed_arguments [ '<STR_LIT:password>' ] , <EOL> logger , <EOL> parsed_arguments [ '<STR_LIT>' ] , <EOL> object_store_url = parsed_arguments [ <EOL> '<STR_LIT>' ] , <EOL> auth_version = parsed_arguments [ '<STR_LIT>' ] , <EOL> os_options = os_options ) <EOL> common_dimensions [ '<STR_LIT>' ] = socket . gethostname ( ) <EOL> common_dimensions [ '<STR_LIT>' ] = SERVICE_NAME <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> common_dimensions [ '<STR_LIT>' ] = parsed_arguments [ '<STR_LIT>' ] <EOL> while True : <EOL> conn . latency_reset ( ) <EOL> conn . metric_data_reset ( ) <EOL> if conn . user != "<STR_LIT:None>" : <EOL> conn . check_keystone_get_token ( ) <EOL> if conn . user != "<STR_LIT:None>" : <EOL> for proxy in range ( <NUM_LIT:0> , parsed_arguments [ '<STR_LIT>' ] ) : <EOL> service_state = conn . check_object_store ( ) <EOL> if service_state != component_states . ok : <EOL> break <EOL> for proxy in range ( <NUM_LIT:0> , parsed_arguments [ '<STR_LIT>' ] ) : <EOL> service_state = conn . check_object_store_health_check ( logger ) <EOL> if service_state != component_states . ok : <EOL> break <EOL> conn . latency_write_log ( ) <EOL> conn . dump_metric_data ( ) <EOL> time . sleep ( parsed_arguments [ '<STR_LIT>' ] ) <EOL> usage_message = """<STR_LIT>""" <EOL> def parse_args ( args ) : <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> usage = usage_message ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' ) <EOL> return parser . parse_args ( args ) <EOL> def validate_args ( config ) : <EOL> if not config . has_section ( '<STR_LIT>' ) : <EOL> raise UPtimeMonException ( <EOL> "<STR_LIT>" ) <EOL> if not config . has_section ( '<STR_LIT>' ) : <EOL> raise UPtimeMonException ( <EOL> "<STR_LIT>" ) <EOL> logger = get_logger ( dict ( config . items ( '<STR_LIT>' ) ) , name = '<STR_LIT>' ) <EOL> parsed_arguments = { } <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> msg = "<STR_LIT>" <EOL> logger . exception ( msg ) <EOL> raise UPtimeMonException ( msg ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = int ( <EOL> config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = <NUM_LIT> <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = int ( <EOL> config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = <NUM_LIT> <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT:password>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT:password>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT:password>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> parsed_arguments [ '<STR_LIT>' ] = getenv ( '<STR_LIT>' ) <EOL> try : <EOL> parsed_arguments [ '<STR_LIT>' ] = config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> except ConfigParser . NoOptionError : <EOL> msg = "<STR_LIT>" <EOL> logger . exception ( msg ) <EOL> raise UPtimeMonException ( msg ) <EOL> if parsed_arguments [ '<STR_LIT>' ] is None : <EOL> message = "<STR_LIT>" <EOL> logger . exception ( message ) <EOL> raise UPtimeMonException ( message ) <EOL> if parsed_arguments [ '<STR_LIT:password>' ] is None : <EOL> message = "<STR_LIT>" <EOL> logger . exception ( message ) <EOL> raise UPtimeMonException ( message ) <EOL> if parsed_arguments [ '<STR_LIT>' ] is None : <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> logger . exception ( message ) <EOL> raise UPtimeMonException ( message ) <EOL> if parsed_arguments [ '<STR_LIT>' ] is None and parsed_arguments [ '<STR_LIT>' ] is None : <EOL> message = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> logger . exception ( message ) <EOL> raise UPtimeMonException ( message ) <EOL> return parsed_arguments , logger <EOL> def main ( ) : <EOL> args = parse_args ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> if not path . isfile ( args . configFile ) : <EOL> message = "<STR_LIT>" <EOL> raise Exception ( message ) <EOL> config = ConfigParser . RawConfigParser ( ) <EOL> config . read ( args . configFile ) <EOL> parsed_arguments , logger = validate_args ( config ) <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> if parsed_arguments [ '<STR_LIT>' ] : <EOL> del parsed_arguments [ '<STR_LIT>' ] <EOL> main_loop ( parsed_arguments , logger ) <EOL> exit ( <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
