def get_sub_details(username, password, account_name, subNo): debug.p('FUNC:::: get_sub_details ::::::::::::') subNo = str ('/' + subNo) json_obj = str(account_name + subNo) json_data = extract_sub_json (username, password, json_obj) data = json_data return data
def modify_list_endpoints_all(username, password, accountRef): #json_data = open ('./templates/subs.json') #data = json.load (json_data) #json_data.close() """ FUNC: list_subs: This functon should accept an account name and return a list of endpoints from the account. Example of data returned. parent" : "/accounts/AGerry", "id" : "0019724025059", "uid" : null, "href" : "/accounts/AGerry/endpoints/0019724025059", "additionalInfo" : { } """ debug.p('FUNC:::: list_endpoints ::::::::::::' + 'Input Parameter is : ' + str(accountRef)) if accountRef[0] != '/': accountRef = '/' + accountRef if accountRef[:9] != '/accounts': accountRef = '/accounts' + accountRef ngin = cie_connect(username, password) json_obj = accountRef + '/endpoints' data = ngin.get_cie_object_all(json_obj) debug.p(data) if data == 100: return None elif data['results']: resultsOnly = data['results'] return resultsOnly else: return None
def get_cie_object_all(self,object): returncode = 100 h = httplib2.Http(".cache") h.add_credentials(self.username, self.password) t0 = datetime.datetime.now() debug.p ("http://" + self.server + self.url_prefix + object + '?items=100000' + " GET") resp, content = h.request("http://" + self.server + self.url_prefix + object + '?items=100000' , "GET") #debug.p(str(resp)) logger.log ( INFO, "getting " + str(object) + " tooks " + str(datetime.datetime.now() - t0) ) if int(resp["status"]) == 200: logger.log( INFO, "HTTP-200 successful request") returncode = json.loads(content) elif int(resp["status"]) == 404: logger.log( WARNING, "HTTP-404 object not found") else: logger.log( ERROR, resp["status"] + " unknown error") return returncode # cie errors try: cie_error = json.loads(content) if not cie_error.has_key("result") or cie_error["result"] != "CREATED" and cie_error["result"] != "UPDATED": #logger.log( ERROR, cie_error["errors"][0]["error"]) logger.log( ERROR, content) returncode = 99 logger.log( DEBUG, content) except: logger.log ( ERROR, "unexpected content received from CIE2 during provisioning of " + str(object) + " received content: " + str(content) ) logger.log ( DEBUG, " URl: http://" + str(self.server) + str(self.url_prefix) + str(object) ) logger.log ( DEBUG, str(json.dumps(data)) ) return returncode
def get_basic_translation(username, password, href): debug.p('FUNC:::: get_basic_translation ::::::::::::') subscription = get_sub_details(username, password, href) for index, element in enumerate(subscription['attributes']): if element['id'] =='basTransEpRef': return (element['id'], element['value']) return (element['id'], None)
def check_latency_stats(): """ The inputs for this function should be a duration in minutes which is a window for comparison of stats. """ debug.p('FUNC:check_db_alarm.check_latency_stats() ****') try: db, c = mysql.connectdb() check_date = getDate(11) query = 'SELECT date, round((sub50/TotalCalls *100),2) as s50, round((sub100/TotalCalls *100),2) as s100, ' \ 'round((sub200/TotalCalls *100),2) as s200 from StatLogSCP1 where date > \'{0}\''.format(check_date) c.execute(query) s50 = float(0) s100 = float(0) s200 = float(0) while (True): row = c.fetchone() if row == None: break else: s50 = s50 + float(row[1]) s100 += float(row[2]) s200 += float(row[3]) #return s50, s100, s200 except Exception, e: applog = logging_setup.getLog("NGIN LATENCY SNMP") applog.critical( 'An exception has occurred in check_db_alarm.check_latency_stats') s50 = float(0) s100 = float(0) s200 = float(0)
def get_basic_translation(username, password, account_name, subNo): #subscription = get_sub_details('1800131219') debug.p('FUNC:::: get_basic_translation ::::::::::::') subscription = get_sub_details(username, password, account_name , subNo) for index, element in enumerate(subscription['attributes']): if element['id'] =='basTransEpRef': return (subNo, element['value'])
def parse_accounts_list_make_account_info(username, password, accounts_list): """ This function should accept a list of accounts as input and should return a list of """ debug.p('FUNC:::: parse_accounts_list_make_account_info ::::::::::::') ngin = cie_connect(username, password) newlist = [] for row in accounts_list['results']: if row['id']: totalSize, sub_info , next_href = number_of_subs_10(ngin, row['href']) if totalSize: for line in sub_info: newdict = defaultdict(dict) newdict['id'] = row['id'] newdict['href'] = row['href'] newdict['parent'] = row['parent'] newdict['totalSize'] = totalSize newdict['Subscription'] = line['id'] newdict['subHref'] = line['href'] newdict['subType'] = subscription_get_subType(ngin, line['href']) newlist.append(newdict) #debug.p('NEWLIST IN LOOP::::::') #debug.p(newlist) #debug.p('NEWLIST ::::::::::') #debug.p(newlist) return newlist, next_href
def check_latency_stats(): """ The inputs for this function should be a duration in minutes which is a window for comparison of stats. """ debug.p('FUNC:check_db_alarm.check_latency_stats() ****') try: db, c = mysql.connectdb() check_date = getDate(11) query = 'SELECT date, round((sub50/TotalCalls *100),2) as s50, round((sub100/TotalCalls *100),2) as s100, ' \ 'round((sub200/TotalCalls *100),2) as s200 from StatLogSCP1 where date > \'{0}\''.format(check_date) c.execute(query) s50 = float(0) s100 = float(0) s200 = float(0) while(True): row = c.fetchone() if row == None: break else: s50 = s50 + float(row[1]) s100 += float(row[2]) s200 += float(row[3]) #return s50, s100, s200 except Exception, e: applog = logging_setup.getLog("NGIN LATENCY SNMP") applog.critical('An exception has occurred in check_db_alarm.check_latency_stats' ) s50 = float(0) s100 = float(0) s200 = float(0)
def modify_list_endpoints_all(username, password, accountRef): #json_data = open ('./templates/subs.json') #data = json.load (json_data) #json_data.close() """ FUNC: list_subs: This functon should accept an account name and return a list of endpoints from the account. Example of data returned. parent" : "/accounts/AGerry", "id" : "0019724025059", "uid" : null, "href" : "/accounts/AGerry/endpoints/0019724025059", "additionalInfo" : { } """ debug.p('FUNC:::: list_endpoints ::::::::::::' + 'Input Parameter is : ' + str(accountRef)) if accountRef[0] != '/': accountRef = '/'+ accountRef if accountRef[:9] != '/accounts': accountRef = '/accounts'+ accountRef ngin = cie_connect(username, password) json_obj = accountRef + '/endpoints' data = ngin.get_cie_object_all(json_obj) debug.p(data) if data == 100: return None elif data['results']: resultsOnly = data['results'] return resultsOnly else: return None
def get_basic_translation(username, password, href): debug.p('FUNC:::: get_basic_translation ::::::::::::') subscription = get_sub_details(username, password, href) for index, element in enumerate(subscription['attributes']): if element['id'] == 'basTransEpRef': return (element['id'], element['value']) return (element['id'], None)
def get_endpoint_info(username, password, endpoint): """ This function should accept an endpoint and return the json. """ debug.p('FUNC:::: get_endpoint_info ::::::::::::') ngin = cie_connect(username, password) data = ngin.get_cie_object(endpoint) return data
def parse_subs_list(subs_list): debug.p('FUNC:::: parse_subs_list ::::::::::::') pair = {} pairlist = [] for sub in subs_list: #sub_details = get_sub_details(sub) subNo,endpoint = get_basic_translation(sub) pass
def trapgenclearapp (): debug.p("Func: trapgenclear in trapgen.py") f_clear_fault = 1 com_path = ". ./send_trap.sh " + str(f_clear_fault) + " " + str('A2:latency') debug.p(str(com_path)) applog.info('A2:The system Call Latency SNMP Application has returned to accepted service levels' ) p = commands.getoutput (com_path) return
def endpoint(account, endpoint): #The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing #subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p('FUNC:::::: app.route.endpoint') endpoint_info = get_endpoint_info(session['username'], session['password'], request.path) if endpoint_info == None: return (' ERROR ERROR ERROR') else: return render_template('endpoint.html', endpoint = endpoint_info, basehref = session['accountRef'])
def endpoint(account, endpoint): # The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing # subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p("FUNC:::::: app.route.endpoint") endpoint_info = get_endpoint_info(session["username"], session["password"], request.path) if endpoint_info == None: return " ERROR ERROR ERROR" else: return render_template("endpoint.html", endpoint=endpoint_info, basehref=session["accountRef"])
def trapgensendapp(): debug.p("Func: trapgensend in trapgen.py") f_set_fault = 5 com_path = ". ./send_trap.sh " + str(f_set_fault) + " " + str('A2:latency') debug.p(str(com_path)) p = commands.getoutput (com_path) applog.critical('A2:The system Call Latency SNMP Application has failed according to the criteria.' ) return
def get_sub_details(username, password, account_name, subNo): debug.p('FUNC:::: get_sub_details ::::::::::::') subNo = str ('/' + subNo) json_obj = str(account_name + subNo) json_data = extract_sub_json (username, password, json_obj) #json_data = open('./templates/1800131219.json') data = json_data #data = json.load (json_data) #json_data.close() return data
def endpoints_list(account): #The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing #subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p('FUNC:::::: app.route.endpoints_list') endpoints_list, nextPage, lastPage, numberOfEndpoints = list_endpoints(session['username'], session['password'], session['accountRef']) if endpoints_list == None: return (' ERROR ERROR ERROR') else: return render_template('endpoints.html', endpoints = endpoints_list, nextPage= nextPage, lastPage=lastPage, basehref = session['accountRef'])
def trapgensend(): debug.p("Func: trapgensend in trapgen.py") f_set_fault = 5 com_path = ". ./send_trap.sh " + str(f_set_fault) + " " + str('A1:latency') debug.p(str(com_path)) p = commands.getoutput(com_path) applog.critical( 'A1:The system Call Latency has failed according to the criteria') return
def trapgenclear(): debug.p("Func: trapgenclear in trapgen.py") f_clear_fault = 1 com_path = ". ./send_trap.sh " + str(f_clear_fault) + " " + str( 'A1:latency') debug.p(str(com_path)) applog.info( 'A1:The system Call Latency has returned to accepted service levels') p = commands.getoutput(com_path) return
def accounts(): # accounts list will be a list of accounts under the HOME account # it contains parent, id, uid and href of the accounts debug.p("FUNC:::::: app.route.accounts") debug.p(session["accountRef"]) flash(u"You were logged in", "success") accounts_list = list_accounts(session["username"], session["password"], session["accountRef"]) # accounts_data_list will be a list of parent account, account and link to subs for accounts in accounts_list # it contains id, href and parent. accounts_data_list = accounts_list_make_account_info(session["username"], session["password"], accounts_list) return render_template("accounts.html", accounts_data_list=accounts_data_list, basehref=session["accountRef"])
def subscriptions(account): #The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing #subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p('FUNC:::::: app.route.subscriptions') subs_list = list_subs(session['username'], session['password'],account) subscription_data_list = parse_subs_list_make_sub_info (session['username'], session['password'], subs_list) debug.p(subscription_data_list) if subscription_data_list == None: return (' ERROR ERROR ERROR') else: return render_template('subscriptions1.html', subscription_list= subscription_data_list, basehref = session['accountRef'])
def accounts(): # accounts list will be a list of accounts under the HOME account # it contains parent, id, uid and href of the accounts debug.p('FUNC:::::: app.route.accounts') debug.p(session['accountRef']) flash(u'You were logged in', 'success') accounts_list = list_accounts(session['username'], session['password'], session['accountRef']) # accounts_data_list will be a list of parent account, account and link to subs for accounts in accounts_list # it contains id, href and parent. accounts_data_list = accounts_list_make_account_info (session['username'], session['password'], accounts_list) return render_template('accounts.html', accounts_data_list= accounts_data_list, basehref = session['accountRef'])
def subscription_get_subType(ngin, ref): """ This function expects a connection (ngin) and account/sub ref. This function should accept an account/sub reference and return an entry for the type of Subscription. Choice of Advanced Service, Basic Translation, Custom Plan, SelfCare template. """ debug.p('FUNC:::: subscription_get_subType ::::::::::::') data = ngin.get_cie_object(ref) for line in data['attributes']: if line['id'] == 'subType': subType = line['value'] return subType
def subscriptions(account): # The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing # subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p("FUNC:::::: app.route.subscriptions") subs_list = list_subs(session["username"], session["password"], account) subscription_data_list = parse_subs_list_make_sub_info(session["username"], session["password"], subs_list) debug.p(subscription_data_list) if subscription_data_list == None: return " ERROR ERROR ERROR" else: return render_template( "subscriptions1.html", subscription_list=subscription_data_list, basehref=session["accountRef"] )
def put_cie_endpoint(self, object, data): debug.p("FUNC: class cie_prov : put_cie_endpoint **********") h = httplib2.Http(".cache") h.add_credentials(self.username, self.password) object_prefix = "/subscriptions/" t0 = datetime.datetime.now() resp, content = h.request( "http://" + self.server + self.url_prefix + object_prefix + object, "PUT", json.dumps(data)) logger.log( INFO, "putting " + str(object) + " tooks " + str(datetime.datetime.now() - t0)) logger.log(INFO1, " RESP | " + str(resp)) logger.log(INFO1, " CONTENT | " + str(content)) returncode = 100 try: content_j = json.loads(content) except: #logger.log ( ERROR, str(content) ) logger.log(ERROR, str(json.dumps(data))) return 1 #if int(resp["status"]) == 200: # logger.log( INFO, "HTTP-200 update successfully") # returncode = 0 #elif int(resp["status"]) == 201: # logger.log( INFO, "HTTP-201 create successfully") # returncode = 0 #elif int(resp["status"]) == 414: # logger.log (WARNING, "HTTP-412 validation error" + content) # returncode = 1 #else: # logger.log( ERROR, resp["status"] + " unknown error") # returncode = 10 if content_j["result"] == "CREATED": logger.log(INFO, "Successfully created") returncode = 0 elif content_j["result"] == "UPDATED": logger.log(INFO, "Successfully updated") returncode = 0 elif content_j["result"] == "VALIDATION_ERROR": logger.log(ERROR, "VALIDATION_ERROR" + str(content)) returncode = 1 else: logger.log(ERROR, "unkown error" + str(resp) + " " + str(content)) #logger.log( DEBUG, resp) #logger.log( DEBUG, content) return returncode
def applyBasic(account, sub_no): debug.p("FUNC:::::: app.route.applyBasic") if request.method == "POST": endpoint = request.form["modsub"] account = "/accounts/" + account + "/subscriptions" if changeBasicEndpoint(session["username"], session["password"], account, sub_no, endpoint): # return render_template('accounts.html') message = "The Endpoint for subscription " + sub_no + "has been changed to : " + endpoint flash(message, "success") return redirect(url_for("accounts")) else: return "ERROR " # return "You asked for sub number %s in account : %s " %((endpoint), (endpoint)) else: return " ERROR ERROR ERROR"
def applyBasic(account, sub_no): debug.p('FUNC:::::: app.route.applyBasic') if request.method == 'POST': endpoint = request.form['modsub'] account = '/accounts/' + account + "/subscriptions" if (changeBasicEndpoint(session['username'], session['password'], account, sub_no, endpoint)): #return render_template('accounts.html') message = ("The Endpoint for subscription " + sub_no + "has been changed to : " + endpoint) flash(message, 'success') return redirect(url_for('accounts')) else: return ('ERROR ') #return "You asked for sub number %s in account : %s " %((endpoint), (endpoint)) else: return (' ERROR ERROR ERROR')
def login(): error = None if request.method == 'POST': debug.p ('Performing logon') session['username'] = request.form['username'] session['password'] = request.form['password'] return_code = perform_cie_logon(session['username'], session['password']) if return_code == 100: error = 'Invalid password' flash(u'Invalid password provided', 'error') else: session['logged_in'] = True session['accountRef'] = return_code['accountRef'] return redirect(url_for('accounts')) return render_template('mylogin.html', error=error)
def modify_basic_sub(account, sub_no): debug.p('FUNC:::::: app.route.subscriptions.modify_basic_sub') if request.method == 'POST': return "You asked for sub number %s in account : %s " %((value), (value)) else: href = request.path href = href[0:-7] print ('HREF ++ ') + str(href) #return "You asked for sub number %s in account : %s " %((sub_no), (account)) termNo = get_basic_translation(session['username'], session['password'], href) endpoints_list = modify_list_endpoints_all(session['username'], session['password'], session['accountRef']) if endpoints_list == None or termNo == None: return (' ERROR ERROR ERROR') else: return render_template('modifyBasic.html', subscription = sub_no, termNumber = termNo,endpoints = endpoints_list ,basehref = session['accountRef'])
def login(): error = None if request.method == "POST": debug.p("Performing logon") session["username"] = request.form["username"] session["password"] = request.form["password"] return_code = perform_cie_logon(session["username"], session["password"]) if return_code == 100: error = "Invalid password" flash(u"Invalid password provided", "error") else: session["logged_in"] = True session["accountRef"] = return_code["accountRef"] return redirect(url_for("accounts")) return render_template("mylogin.html", error=error)
def setSub(id_property = None, last_modified = None, created = None, allow_tags = None, attributes = None): """ This subscription should use the class classBasicSubscription to create the json for the modify basic subscription command. """ debug.p("FUNC::::: cie_commands_basicsub.setSub():::: input is subscription number") sub = BasicSubscription() sub.id = id_property sub.lastModified = last_modified sub.created = created sub.allowTags = allow_tags sub.attributes = [attributes] debug.p('#####################################################') json_string = (json.dumps(sub, default = jdefault)) return json_string
def put_cie_endpoint(self,object, data): debug.p("FUNC: class cie_prov : put_cie_endpoint **********") h = httplib2.Http(".cache") h.add_credentials(self.username, self.password) object_prefix = "/subscriptions/" t0 = datetime.datetime.now() resp, content = h.request("http://" + self.server + self.url_prefix + object_prefix + object, "PUT", json.dumps(data)) logger.log ( INFO, "putting " + str(object) + " tooks " + str(datetime.datetime.now() - t0) ) logger.log ( INFO1, " RESP | " + str(resp) ) logger.log ( INFO1, " CONTENT | " + str(content) ) returncode = 100 try: content_j = json.loads(content) except: #logger.log ( ERROR, str(content) ) logger.log ( ERROR, str(json.dumps(data))) return 1 #if int(resp["status"]) == 200: # logger.log( INFO, "HTTP-200 update successfully") # returncode = 0 #elif int(resp["status"]) == 201: # logger.log( INFO, "HTTP-201 create successfully") # returncode = 0 #elif int(resp["status"]) == 414: # logger.log (WARNING, "HTTP-412 validation error" + content) # returncode = 1 #else: # logger.log( ERROR, resp["status"] + " unknown error") # returncode = 10 if content_j["result"] == "CREATED": logger.log ( INFO, "Successfully created" ) returncode = 0 elif content_j["result"] == "UPDATED": logger.log ( INFO, "Successfully updated" ) returncode = 0 elif content_j["result"] == "VALIDATION_ERROR": logger.log ( ERROR, "VALIDATION_ERROR" + str(content) ) returncode = 1 else: logger.log ( ERROR, "unkown error" + str(resp) + " " + str(content) ) #logger.log( DEBUG, resp) #logger.log( DEBUG, content) return returncode
def performSearchRangeR(): session.permanent = True logger.debug(('FUNC:::::: app.route.performSearchRangeR {0}').format(request.method)) if request.method == 'POST': sub = str(request.form['sub']) if sub == "": return redirect(url_for('main.subscribers')) session['sub'] = sub # subscriber number in text c_sub = ims.registeredRangeSubscriber(sub) debug.p(session) result = c_sub.subscriberGet(session) logger.debug (result.status_code) logger.debug (result.text) if result.status_code == 500: #Successful EMA connection but there is an error. if result.text.find('Invalid Session') != -1: logger.debug(('** Leaving FUNC:::: app.route.performSearchrangeR: Invalid Session')) return redirect(url_for('auth.login', error='Invalid Session')) elif result.text.find('No such object') != -1: logger.debug(('** Leaving FUNC:::: app.route.performSearchrangeR: Subscriber not provisioned: redirecting to subscribers.html')) session['mesg'] = 'NotProvisioned' return redirect(url_for('main.subscribers')) else: pass if result.status_code == 200: subdetails = ema.prepareXmlToClass(result.text) if isinstance(subdetails['pubData'],list): session['count'] = subdetails['pubData'].__len__() session['subType'] = subdetails['pubData'][0]['publicIdState'] # Current Subscriber State in text session['details'] = subdetails # Current Subscriber SOAP XML structure else: session['count'] = 0 session['subType'] = subdetails['pubData']['publicIdState'] # Current Subscriber State in text session['details'] = subdetails # Current Subscriber SOAP XML structure del c_sub # Remove Subscriber Class instance logger.debug('**Leaving FUNC:::::: app.route.performSearchRangeR: Status = 200') return redirect(url_for('main.subscriberResult')) else: return redirect(url_for('auth.login', error='Unknown error Condition')) logger.error('Unexpected error occurred in app.route.performSearchRangeR ') logger.debug('** Leaving FUNC::::::: app.route.performSearchRangeR: End of Func error') return redirect(url_for('auth.login', error='Unknown error Condition'))
def accounts_list_make_account_info(username, password, accounts_list): """ This function should accept a list of accounts as input and should return a list of parent account, account and link to subs for account """ debug.p('FUNC:::: accounts_list_make_account_info ::::::::::::') ngin = cie_connect(username, password) newlist = [] for row in accounts_list['results']: totalSize, sub_info , next_href = number_of_subs_10(ngin, row['href']) newdict = defaultdict(dict) newdict['id'] = row['id'] newdict['href'] = row['href'] newdict['parent'] = row['parent'] newdict['totalSize'] = totalSize newlist.append(newdict) return newlist
def endpoints_list(account): # The following command can be used for landing pages and it takes a session AccountRef from NGIN # for the account ref landing # subs_list = list_subs(session['username'], session['password'],session['accountRef']) debug.p("FUNC:::::: app.route.endpoints_list") endpoints_list, nextPage, lastPage, numberOfEndpoints = list_endpoints( session["username"], session["password"], session["accountRef"] ) if endpoints_list == None: return " ERROR ERROR ERROR" else: return render_template( "endpoints.html", endpoints=endpoints_list, nextPage=nextPage, lastPage=lastPage, basehref=session["accountRef"], )
def dd(code, mysql_obj=None, threadName=None): now = datetime.datetime.now() # 周末退出 if now.weekday() == 5 or now.weekday() == 6: return 1 today = now.strftime("%Y-%m-%d") # today = '2018-07-06' while (True): df = ts.get_today_ticks(code) # df = ts.get_sina_dd(code, date='2018-07-06') # df = ts.get_sina_dd("000001", date='2018-07-05') # df = ts.get_sina_dd("000007", date=today) if df is not None and len(df) > 1: df['time'] = today + " " + df['time'] df.rename(columns={ 'code': 'sCode', 'time': 'tDateTime', 'price': 'iPrice', 'pchange': 'iPchange', 'change': 'iChange', 'volume': 'iVolume', 'amount': 'iAmount', 'type': 'sType' }, inplace=True) # df2 = df[['sCode', 'sName', 'tDateTime', 'iPrice', 'iVolume', 'iPreprice', 'sType']] # result = sql_model.loadData('stock_daily_big_order', df.keys, df.values, threadName) # result = sql_model.loadData('stock_daily_big_order', df2.keys(), df2.values, threadName) result = mysql_obj.loadData('stock_daily_big_order', df.keys(), df.values, threadName) print(result) # 过了15点10分就退出 if (now.hour >= 15 and now.minute >= 10) or (now.hour < 9 and now.minute >= 30): return 1 p("dsfds") # 等待60秒 print("%s wait 60s" % code) time.sleep(60)
def get_cie_object_all(self, object): returncode = 100 h = httplib2.Http(".cache") h.add_credentials(self.username, self.password) t0 = datetime.datetime.now() debug.p("http://" + self.server + self.url_prefix + object + '?items=100000' + " GET") resp, content = h.request( "http://" + self.server + self.url_prefix + object + '?items=100000', "GET") #debug.p(str(resp)) logger.log( INFO, "getting " + str(object) + " tooks " + str(datetime.datetime.now() - t0)) if int(resp["status"]) == 200: logger.log(INFO, "HTTP-200 successful request") returncode = json.loads(content) elif int(resp["status"]) == 404: logger.log(WARNING, "HTTP-404 object not found") else: logger.log(ERROR, resp["status"] + " unknown error") return returncode # cie errors try: cie_error = json.loads(content) if not cie_error.has_key("result") or cie_error[ "result"] != "CREATED" and cie_error["result"] != "UPDATED": #logger.log( ERROR, cie_error["errors"][0]["error"]) logger.log(ERROR, content) returncode = 99 logger.log(DEBUG, content) except: logger.log( ERROR, "unexpected content received from CIE2 during provisioning of " + str(object) + " received content: " + str(content)) logger.log( DEBUG, " URl: http://" + str(self.server) + str(self.url_prefix) + str(object)) logger.log(DEBUG, str(json.dumps(data))) return returncode
def get_https_logon_account(self, account): debug.p("FUNC: class cie_prov : get_https_logon_account **********") # h = httplib2.Http(".cache") h = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, '10.103.3.22', 8080)) h.add_credentials(self.username, self.password) object_prefix = "/accounts/system/security/users/" debug.p ("DEBUG: https://" + self.server + self.url_prefix + object_prefix + self.username + " GET") resp, content = h.request("https://" + self.server + self.url_prefix + object_prefix+ self.username, "GET") debug.p(str(resp)) debug.p(str(content)) return
def parse_subs_list_make_sub_info(username, password, subs_list): """This function creates a list of dictionaries """ debug.p('FUNC:::: parse_subs_list_make_sub_info ::::::::::::') newlist = [] if subs_list: for row in subs_list: if row['id']: newdict = defaultdict(dict) x = row['id'] subNo,endpoint = get_basic_translation(username, password, row['href']) newdict['id'] = x newdict['href'] = row['href'] newdict['parent'] = row['parent'] newdict['additionalInfo'] = row['additionalInfo'] newdict['endpoint'] = endpoint newlist.append(newdict) return newlist else: return None
def getDate(delta): """ This function returns the real time minus 3 minute in a format required for the program. """ debug.p("FUNC:check_db_alarm.getDate") db = connectToDB() debug.p('Get Max Date in DB') date_entry = db.query(func.max(StatLogSCP1.date)) debug.p(date_entry) #max_Date = c.fetchone() #This return a tuple, 0 item is a datetime.datetime object #maxDate = max_Date[0] deltaDate = date_entry - timedelta(minutes=delta) debug.p("**Leaving FUNC:check_db_alarm.getDate") return deltaDate
def getDate(delta): """ This function returns the real time minus 3 minute in a format required for the program. """ debug.p("FUNC:check_db_alarm.getDate") db = connectToDB() debug.p('Get Max Date in DB') date_entry = db.query(func.max(StatLogSCP1.date)) debug.p(date_entry) #max_Date = c.fetchone() #This return a tuple, 0 item is a datetime.datetime object #maxDate = max_Date[0] deltaDate = date_entry - timedelta(minutes= delta) debug.p("**Leaving FUNC:check_db_alarm.getDate") return deltaDate
def parse_subs_list_make_sub_info(username, password, subs_list): """This function creates a list of dictionaries """ debug.p('FUNC:::: parse_subs_list_make_sub_info ::::::::::::') newlist = [] if subs_list: for row in subs_list: if row['id']: account_name = get_account_name() newdict = defaultdict(dict) x = row['id'] subNo,endpoint = get_basic_translation(username, password, account_name , x) newdict['id'] = x newdict['href'] = row['href'] newdict['parent'] = row['parent'] newdict['additionalInfo'] = row['additionalInfo'] newdict['endpoint'] = endpoint newlist.append(newdict) return newlist else: return None
def list_subs(username, password, accountRef): """ FUNC: list_subs: This functon should accept an account name and return a list of subscriptions from the account. """ debug.p('FUNC:::: list_subs ::::::::::::') if accountRef[1] != '/': accountRef = '/'+ accountRef if accountRef[:9] != '/accounts': accountRef = '/accounts'+ accountRef ngin = cie_connect(username, password) json_obj = accountRef + '/subscriptions' data = ngin.get_cie_object(json_obj) if data == 100: return None elif data['results']: resultsOnly = data['results'] return resultsOnly else: return None
def get_cie_logon(self): returncode = 100 object_prefix = "/accounts/system/security/users/" h = httplib2.Http(".cache") h.add_credentials(self.username, self.password) t0 = datetime.datetime.now() debug.p("DEBUG: http://" + self.server + self.url_prefix + object_prefix + self.username + " GET") resp, content = h.request( "http://" + self.server + self.url_prefix + object_prefix + self.username, "GET") debug.p(str(resp)) debug.p(str(content)) logger.log( INFO, "getting " + str(self.username + object_prefix) + " tooks " + str(datetime.datetime.now() - t0)) if int(resp["status"]) == 200: logger.log(INFO, "HTTP-200 successful request") returncode = json.loads(content) elif int(resp["status"]) == 404: logger.log(WARNING, "HTTP-404 object not found") else: logger.log(ERROR, resp["status"] + " unknown error") return returncode
def modify_basic_sub(account, sub_no): debug.p("FUNC:::::: app.route.subscriptions.modify_basic_sub") if request.method == "POST": return "You asked for sub number %s in account : %s " % ((value), (value)) else: href = request.path href = href[0:-7] print("HREF ++ ") + str(href) # return "You asked for sub number %s in account : %s " %((sub_no), (account)) termNo = get_basic_translation(session["username"], session["password"], href) endpoints_list = modify_list_endpoints_all(session["username"], session["password"], session["accountRef"]) if endpoints_list == None or termNo == None: return " ERROR ERROR ERROR" else: return render_template( "modifyBasic.html", subscription=sub_no, termNumber=termNo, endpoints=endpoints_list, basehref=session["accountRef"], )
def get_https_logon_account(self, account): debug.p("FUNC: class cie_prov : get_https_logon_account **********") # h = httplib2.Http(".cache") h = httplib2.Http(proxy_info=httplib2.ProxyInfo( socks.PROXY_TYPE_HTTP, '10.103.3.22', 8080)) h.add_credentials(self.username, self.password) object_prefix = "/accounts/system/security/users/" debug.p("DEBUG: https://" + self.server + self.url_prefix + object_prefix + self.username + " GET") resp, content = h.request( "https://" + self.server + self.url_prefix + object_prefix + self.username, "GET") debug.p(str(resp)) debug.p(str(content)) return
def changeBasicEndpoint(username, password, account_name, subNo, endpoint): ngin = cie_connect(username,password) debug.p('FUNC:::: get_changeNasicEndpoint ::::::::::::') attrib = Attributes() attrib.id = "basTransEpRef" attrib.value = endpoint subData, href = get_sub_details(username, password, account_name, subNo) lastModified = subData['lastModified'] attributes = attrib created = subData['created'] allowTags = subData['allowTags'] id_property = subData['id'] json_string = setSub(id_property, lastModified, created, allowTags, attributes) exitCode = ngin.put_cie_json_object(href, json_string) if exitCode == 0: return True else: return None
def emaCreateRegisteredRangeSubscriber(sub, session): ''' This function will create an IMS subscriber/subscription on HSS and ENUM via EMA. The inputs for this subscription are the session and the subscriber information itself. ''' logger.debug('FUNC:: emaCreateRegisteredRangeSubscriber : ') debug.p(session['rangesize']) if session['rangesize'] == '10': debug.p('Entering 10') insert_xml = __readinxml__('./create_psi_ims_rangeNR_marc.xml').format(session['emaSession']['session_id'], sub.phoneNumber, sub.domain, sub.termProfileId, sub.chargingProfId, '{1}', sub.pubData.publicIdTelValue) #insert_xml = __readinxml__('./lmi_create_ims_rangeNR10_marc.xml').format(session['emaSession']['session_id'], sub.phoneNumber, sub.domain, sub.origProfileId, sub.termProfileId, sub.chargingProfId, sub.password) elif session['rangesize'] == '100': debug.p('Entering 100') insert_xml = __readinxml__('./create_psi_ims_rangeNR_marc.xml').format(session['emaSession']['session_id'], sub.phoneNumber, sub.domain, sub.termProfileId, sub.chargingProfId, '{2}', sub.pubData.publicIdTelValue) elif session['rangesize'] == '1000': debug.p('Entering 1000') insert_xml = __readinxml__('./create_psi_ims_rangeNR_marc.xml').format(session['emaSession']['session_id'], sub.phoneNumber, sub.domain, sub.termProfileId, sub.chargingProfId, '{3}', sub.pubData.publicIdTelValue) elif session['rangesize'] == '10000': debug.p('Entering 10000') insert_xml = __readinxml__('./create_psi_ims_rangeNR_marc.xml').format(session['emaSession']['session_id'], sub.phoneNumber, sub.domain, sub.termProfileId, sub.chargingProfId, '{4}', sub.pubData.publicIdTelValue) else: pass # go to error headers ={'content-type':'text/xml; charset=utf-8', 'SOAPAction':'CAI3G#Create'} logger.debug(insert_xml) r= requests.post('http://'+session['emaSession']['ema_host'] +':'+ session['emaSession']['ema_port'], data = insert_xml, headers = headers) if r.status_code != 200: logger.error ((' ERROR: An error has occurred trying to create the subscription::: {0} on the EMA platform.').format(sub.subscriberId)) logger.error (r.status_code) logger.error (r.text) else: logger.debug (' Subscription Created !!!!') logger.debug (r.text) logger.debug('**Leaving FUNC :::: ema_functions.emaCreateRegisteredRangeSubscriber') return (r)
def main(): s50 = float(0) s100 = float(0) s200 = float(0) alarm_sent = False app_alarm = False while True: if debug.mac(): try: sftp.sftpconnectgetlogfile(host='172.30.1.1') except: pass parselog.startparse() debug.p(datetime.now()) s50, s100, s200 = check_db_alarm.check_latency_stats() if (s50): if ( app_alarm ): # Check to see if App A2 Alarm has been sent and not cleared trap.trapgenclearapp() # Clear app_alarm = False # reset App Alarm Flag #Test for Alarm Criteria and send trap if True if (((s100 > 2) or (s200 > 0.5)) and alarm_sent == False): debug.p('send_alarm()') trap.trapgensend() alarm_sent = True #Test for Alarm Criteria and Clear if True elif (((s100 < 2) and (s200 < 0.5)) and alarm_sent == True): debug.p('cancel_alarm()') trap.trapgenclear() alarm_sent = False # Test for Alarm Criteria and re-send trap if True elif (((s100 > 2) or (s200 > 0.5)) and alarm_sent == True): debug.p('Alarm still active') trap.trapgensend() else: pass else: if app_alarm == False: trap.trapgensendapp() app_alarm = True sleep(10)
def number_of_subs_10(ngin, ref): """ This function should accept an account reference (an account) and return a list of the account, the subscriptions under the account and the number of subscriptions in that account. """ debug.p('FUNC:::: number_of_subs_10 ::::::::::::') number_of_subs = ngin.get_cie_object(ref) json_obj = ref + '/subscriptions' subscriptions = ngin.get_cie_object(json_obj) size = None size = subscriptions['totalSize'] subsInfo = subscriptions['results'] next_href = subscriptions['nextPageHref'] debug.p('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$') debug.p(next_href) return size, subsInfo, next_href