#! /usr/bin/python # -*- coding: utf-8 -*- import os import sys sep = os.path.sep proj_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__)).split('sbin')[0]) if proj_dir not in sys.path: sys.path.insert(0, proj_dir) from com.ericsson.xn.commons.CommonUtil import pre_check pre_check(['Linux', 'Darwin', 'Windows'], False, True) from com.ericsson.xn.dbcommons.MysqlCommons import DbInstance from com.ericsson.xn.commons.PyProperties import Properties def insert_a_ne(db_instance): ne_dir = os.path.normpath(proj_dir + sep + 'config' + sep + 'mysql_conf' + sep + 'nes') f_list = os.listdir(ne_dir) ne_file = os.path.normpath(ne_dir + sep + 'ne') ne_dict = Properties(ne_file, True).get_map() id = db_instance.get_max_nes_id() + 1 db_instance.insert_ne(ne_dict, id) def init_connect(): db_file = os.path.normpath(proj_dir + sep + 'config' + sep + 'mysql_conf' + sep + 'db') db = Properties(db_file, True).get_map() i = DbInstance(db['host'], db['username'], db['password'], int(db['port']), db['database'])
dir_cur = os.path.normpath(os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]) sep = os.path.sep if dir_cur not in sys.path: sys.path.insert(0, dir_cur) log_dir = os.path.normpath(dir_cur + sep + 'logs' + sep + 'alarm_time_delta') if not os.path.exists(log_dir): os.makedirs(log_dir) log_fil = os.path.normpath(log_dir + sep + 'alarm_time_delta.log') log_cfg_fil = os.path.normpath(dir_cur + sep + 'config' + sep + 'alarm_time_delta' + sep + 'logging.cfg') logging.config.fileConfig(log_cfg_fil, defaults={'log_file': log_fil}) from com.ericsson.xn.commons.CommonUtil import pre_check pre_check() from com.ericsson.xn.commons.PyProperties import Properties, ListFromFile from com.ericsson.xn.spm import alarm_time_delta logging.debug('Start to log message of alarm_time_delta...') def timedelta_milliseconds(td): return td.days*86400000 + td.seconds*1000 + td.microseconds/1000 if __name__ == '__main__': oid_file = os.path.normpath(dir_cur + sep + 'config' + sep + 'snmp_trap' + sep + 'oids' + sep + 'alarmid_oids') pgw_oids = os.path.normpath(dir_cur + sep + 'config' + sep + 'alarm_time_delta' + sep + 'pgw_oids')