def main(): '''Gather inception services''' parse = argparse.ArgumentParser() parse.add_argument('-d','--dc', help=': name of an inception datacenter', metavar='') parse.add_argument('-e','--env', help=': environment in a datacenter', metavar='') parse.add_argument('-l','--listenv', help=': datacenter name to get available environments', metavar='') parse_arguments = parse.parse_args() if parse_arguments.listenv: inception_request = InceptionTools(parse_arguments.listenv) for content in inception_request.environment(): print(content) sys.exit() if parse_arguments.dc: if bool(parse_arguments.dc) ^ bool(parse_arguments.env): inception_request = Service(parse_arguments.dc) for content in inception_request.all_service(): print(content) else: inception_request = Service(parse_arguments.dc, parse_arguments.env) for content in inception_request.specific_service(): print(content) else: print('''SyntaxError: Insuficient arguments Check --help option to know more''')
def server_check(): if request.method == 'POST': datacenter = request.form['Datacenter'] environment = request.form['Environment'] inception_service = request.form['Service'] if inception_service: service_data = inception_service.split(',') inception_request = Service(datacenter, environment) all_service = inception_request.specific_service() for content in service_data: if content not in all_service: return render_template( 'server-exception.html', data= f'''FileNotFound Exception: Service {content} not found in {environment} environment. Please re-check service name''') sys.exit() inception_request = Server(datacenter, environment, service_data) return render_template('service-check-result.html', data=inception_request.specific_service()) if datacenter: if bool(datacenter) ^ bool(environment): inception_request = Server(datacenter) return render_template('service-check-result.html', data=inception_request.all_server()) else: inception_request = Server(datacenter, environment) return render_template('service-check-result.html', data=inception_request.specific_server())
def main(): '''Gather inception server details''' parse = argparse.ArgumentParser() parse.add_argument('-d', '--dc', help='name of an inception datacenter', metavar='') parse.add_argument('-e', '--env', help='environment in a datacenter', metavar='') parse.add_argument('-l', '--listenv', help='datacenter name to get available environments', metavar='') parse.add_argument('-s', '--service', nargs='+', type=str, help='service to query for its servers', metavar='') parse_arguments = parse.parse_args() if parse_arguments.listenv: inception_request = InceptionTools(parse_arguments.listenv) for content in inception_request.environment(): print(content) sys.exit() if parse_arguments.service: service_data = parse_arguments.service[0].split(',') inception_request = Service(parse_arguments.dc, parse_arguments.env) all_service = inception_request.specific_service() for content in service_data: if content not in all_service: print( f'''FileNotFound Exception: Service {content} not found in {parse_arguments.env} environment. Please re-check service name or use service option [--help]''') sys.exit() inception_request = Server(parse_arguments.dc, parse_arguments.env, service_data) for content in inception_request.specific_service(): print(content) sys.exit() if parse_arguments.dc: if bool(parse_arguments.dc) ^ bool(parse_arguments.env): inception_request = Server(parse_arguments.dc) for content in inception_request.all_server(): print(content) else: inception_request = Server(parse_arguments.dc, parse_arguments.env) for content in inception_request.specific_server(): print(content) else: print('''SyntaxError: Insuficient arguments Check --help option to know more''')
def service(): if request.method == 'POST': datacenter = request.form['Datacenter'] environment = request.form['Environment'] if datacenter: if bool(datacenter) ^ bool(environment): inception_request = Service(datacenter) return render_template('service-check-result.html', data=inception_request.all_service()) else: inception_request = Service(datacenter, environment) return render_template('service-check-result.html', data=inception_request.specific_service())
def health_check(): if request.method == 'POST': datacenter = request.form['Datacenter'] environment = request.form['Environment'] inception_service = request.form['Service'] inception_request = InceptionTools(datacenter) dc_data = inception_request.dc_data() service_data = inception_service.split(',') if inception_service: inception_request = Service(datacenter, environment) all_service = inception_request.specific_service() for service in service_data: if service not in all_service: return render_template('output.html', data=f'''Service {service} is not available in environment {environment}. Use Inception service program to find the list of services\n''') sys.exit() if not bool(datacenter) ^ bool(inception_service): os.remove(spaceFile) for service in service_data: inception_request = ServicePrint(service, dc_data, environment) service_url = inception_request.service_url() with open(spaceFile, 'a+') as contents: contents.write('\n-----------------------SERVICE NAME:\t'+service+'-----------------------\n') contents.write("\n") for url in service_url: instance_name = url[7:-12] contents.write('-------INSTANCE NAME:\t'+instance_name+'\n') ssh_to = RemoteConnect(instance_name) common_url = url[:-6] contents.write('/INFO FOR:\t'+service+'\n') data = inception_request.endpoint_check(common_url, 'info') if data: try: contents.write('Service Name\t\t:\t'+data['app']['name']+'\n') contents.write('Build Number\t\t:\t'+data['build']['number']+'\n') contents.write('Build Time\t\t\t\t\t:\t'+data['build']['time']+'\n') except KeyError: pass contents.write('/CHECK FOR:\t'+service+'\n') data = inception_request.endpoint_check(common_url, 'check') if data: try: contents.write('Service Status\t\t:\t'+data['status']+'\n') except (KeyError, TypeError): for word in ERROR_WORDS: if word not in str(data): continue else: contents.write('Service Status\t\t:\tNOT READY'+'\n') return if 'UP' or 'RUNNING' in str(data): contents.write('Service Status\t\t:\tUP'+'\n') else: contents.write(data+'\n') contents.write('/HEALTH FOR:\t'+service+'\n') data = inception_request.endpoint_check(common_url, 'health') if data: try: contents.write('Service Status\t\t:\t'+data['status']+'\n') except (TypeError, KeyError): for word in ERROR_WORDS: if word not in str(data): continue else: contents.write('Service Status\t\t:\tNOT READY'+'\n') return if 'UP' or 'RUNNING' in str(data): contents.write('Service Status\t\t:\tUP'+'\n') else: contents.write(data+'\n') contents.write('CONTAINER STATUS:'+'\n') container = ssh_to.run_command(DOCKER_COMMAND +'| grep '+service) if not container: contents.write('RunTimeException: Container {} is not running'.format(service)) else: contents.write(container.decode('utf8').strip('\n')) contents.write('\n') contents.write("\n") with open(spaceFile, 'r') as contents: output = contents.read() output = output.replace('\n', '<br>') output = output.replace('\t', ' ') return render_template('output-health.html', data=output)