def fetch_current_session_node_data(): token=get_catchpoint_token(token_url,client_key,client_secret) if token: node_details=fetch_catchpoint_node_deatils(get_nodes_url,token) else: info_logger.info(" invalid token") return node_details
def compare_node_status(previous_session_data, current_session_data, lookup_field): try: info_logger.info(" Comparing Node Details ") previous_session_node_details = json.loads(previous_session_data) def compare(current_session_data_dataObj): for node_index in range(0, len(previous_session_node_details)): if current_session_data_dataObj[ 'id'] == previous_session_node_details[node_index][ 'id']: keys = lookup_field.split('.') previous_run_data = get_value_for_lookUp_fields( previous_session_node_details[node_index], keys) current_run_data = get_value_for_lookUp_fields( current_session_data_dataObj, keys) return previous_run_data != current_run_data return True unique_result = list(filter(compare, current_session_data)) if not unique_result: info_logger.info(" no change ") else: write_node_data_to_file(current_session_data, current_session_data_file) return unique_result except Exception as e: error_logger.exception(str(e))
async def post(self): """ 'Add New Ticket' Post: title: Ticket title ... Exceptions: MissingArgumentError: if any of the mandatory arguments are missing Error Codes: ... Returns: response(json): json response """ self._handler = "upload" postData = {} postData["title"] = self.get_argument("title") postData["jiraID"] = self.get_argument("jiraID") dateStr = self.get_argument("date") postData["date"] = self.getMongoDate(dateStr) postData["dateStr"] = self.getParsedDateFormat(dateStr, "%Y-%m-%d") postData["status"] = self.get_argument("status") postData["module"] = self.get_argument("module") postData["team"] = self.get_argument("team") for field_name, files in self.request.files.items(): for info in files: filename, content_type = info["filename"], info["content_type"] body = info["body"] with open("uploads/" + filename, 'wb') as fp: fp.write(body) ilog.info('POST "{}" "{}" {} bytes'.format(filename, content_type, len(body))) qp = self.parse(filename) if not qp: self._res_code = "UPLOAD_PARSE_EMPTY_02" payload = [{"msg": "Upload file parsed an empty result"}] else: now = datetime.now() for p in qp: doc = {"about": postData, "log": p, "last_updated_on": now} result = await self.db.slow_queries.insert_one(doc) ilog.info("{}".format(result.inserted_id)) payload = [{"msg": "OK"}] self._res_code = "UPLOAD_01" self.send_response(payload)
def read_previous_session_node_data(): previous_session_node_details=[] try: info_logger.info(" reading previous session node details ") if os.path.exists(os.path.join(sub_path,current_session_data_file)): previous_session_file = open(os.path.join(sub_path,current_session_data_file),'r') previous_session_node_details = previous_session_file.read() return previous_session_node_details except Exception as e: error_logger.exception(str(e))
def write_changes_in_node_result(node_data,comparator): info_logger.info(" writing result ") try: changed_data= json.dumps(node_data) if not os.path.isdir(path): os.mkdir(path) opened_result_file = open(os.path.join(path, "changes_in_"+comparator+".json"),'w') opened_result_file.write(str(changed_data)) opened_result_file.close() except Exception as e: error_logger.exception(str(e))
def write_node_data_to_file(node_data, file): try: node_dump_data= json.dumps(node_data) if not os.path.isdir(path): os.makedirs(sub_path) else: if not os.path.isdir(sub_path): os.mkdir(sub_path) info_logger.info(" writing Node Details for "+ file +" ") previous_session_file = open(os.path.join(sub_path,file),'w') previous_session_file.write(str(node_dump_data)) previous_session_file.close() except Exception as e: error_logger.exception(str(e))
def fetch_catchpoint_node_deatils(url, token): info_logger.info("fetching Node Details") try: headers = {'content-length': '0', 'accept': 'application/json', 'authorization': 'Bearer {}'.format(token) } response = requests.get( url,headers=headers) if response: data = response.json() return data['items'] except Exception as e: error_logger.exception(str(e))
def get_catchpoint_token(token_Url,client_key, client_secret): info_logger.info("geting token ") values = {'grant_type': 'client_credentials', 'client_id': client_key, 'client_secret': client_secret} data = urllib.parse.urlencode(values) data = data.encode('utf-8') req = urllib.request.Request(token_Url, data) req.add_header('accept', 'application/json') token_value = '' response = urllib.request.urlopen(req) result = response.read().decode('utf-8') json_result = json.loads(result) token_value = json_result['access_token'] if token_value: info_logger.info("received token") return token_value else: info_logger.info(" invalid token ") return None
from logger import error_logger as elog, info_logger as ilog from config import * import motor.motor_tornado import tornado from tornado.options import define, options define("port", default=default_settings["web_port"], help="run on the given port", type=int) define("debug", default=True, help="debug mode") handler = default_settings['tornado_log'] tornado.options.options.log_file_prefix = handler tornado.options.parse_command_line() ilog.info("Starting db..") _mongo_user = db_settings['mongo_user'] if db_settings['mongo_user'] else '' _mongo_pswd = db_settings['mongo_pswd'] if db_settings['mongo_pswd'] else '' _mongo_host = db_settings['mongo_host'] if db_settings['mongo_host'] else 'localhost' _mongo_port = db_settings['mongo_port'] if db_settings['mongo_port'] else 27017 _mongo_connect_params = db_settings['mongo_connect_params'] if db_settings['mongo_connect_params'] else '' _conn_uri = db_settings['mongo_uri_connect'] if db_settings['mongo_uri_connect'] else '' try: if _conn_uri: _client = motor.motor_tornado.MotorClient(_conn_uri) else: _client = motor.motor_tornado.MotorClient(_mongo_host, _mongo_port)