|
|
@ -9,7 +9,7 @@ import codecs |
|
|
|
from esUtil import EsUtil |
|
|
|
from esUtil import EsUtil |
|
|
|
from config import read_json_config |
|
|
|
from config import read_json_config |
|
|
|
from file_helper import write_large_file,get_file_content,TRACE_PATH |
|
|
|
from file_helper import write_large_file,get_file_content,TRACE_PATH |
|
|
|
from dashboard_data_conversion import find_region_by_code,jobnum_region_dict |
|
|
|
from dashboard_data_conversion import find_region_by_code |
|
|
|
from uebaMetricsAnalysis.utils.ext_logging import logger,logger_cron,get_clean_file_path |
|
|
|
from uebaMetricsAnalysis.utils.ext_logging import logger,logger_cron,get_clean_file_path |
|
|
|
from collections import defaultdict |
|
|
|
from collections import defaultdict |
|
|
|
from appsUtils import env |
|
|
|
from appsUtils import env |
|
|
@ -222,13 +222,20 @@ def get_menu_group_data(index,startTime,endTime,diplist): |
|
|
|
def datetime_to_timestamp(dt): |
|
|
|
def datetime_to_timestamp(dt): |
|
|
|
dtstr=dt.strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
dtstr=dt.strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
return int(time.mktime(time.strptime(dtstr,"%Y-%m-%d %H:%M:%S"))*1000) |
|
|
|
return int(time.mktime(time.strptime(dtstr,"%Y-%m-%d %H:%M:%S"))*1000) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#获取扩展名称 |
|
|
|
|
|
|
|
def get_file_extension(filename): |
|
|
|
|
|
|
|
base_name, extension = os.path.splitext(filename) |
|
|
|
|
|
|
|
return extension |
|
|
|
|
|
|
|
|
|
|
|
def clean_data(read_index,start,end,jobid): |
|
|
|
def clean_data(read_index,start,end,jobid): |
|
|
|
|
|
|
|
|
|
|
|
APPHOME = env.get_isop_root() + "/apps/" + APPFOLDERNAME |
|
|
|
APPHOME = env.get_isop_root() + "/apps/" + APPFOLDERNAME |
|
|
|
config_path = os.path.normpath(APPHOME + "/conf/sys_config.json") |
|
|
|
config_path = os.path.normpath(APPHOME + "/conf/sys_config.json") |
|
|
|
rule_data = read_json_config(config_path) |
|
|
|
rule_data = read_json_config(config_path) |
|
|
|
dips=rule_data["dip"] |
|
|
|
dips=rule_data["dip"] |
|
|
|
|
|
|
|
static_ext = rule_data["static_ext"] |
|
|
|
|
|
|
|
region_dict = rule_data["region_dict"] |
|
|
|
logger_cron.info("JOB:dip "+json.dumps(dips)) |
|
|
|
logger_cron.info("JOB:dip "+json.dumps(dips)) |
|
|
|
|
|
|
|
|
|
|
|
data_ip = get_ip_group_data(read_index,start,end,dips) |
|
|
|
data_ip = get_ip_group_data(read_index,start,end,dips) |
|
|
@ -244,11 +251,20 @@ def clean_data(read_index,start,end,jobid): |
|
|
|
logger_cron.info("JOB:"+jobid+",账号维度获取到 "+str(len(data_account))+" 条数据") |
|
|
|
logger_cron.info("JOB:"+jobid+",账号维度获取到 "+str(len(data_account))+" 条数据") |
|
|
|
logger_cron.info("JOB:"+jobid+",接口维度获取到 "+str(len(data_interface))+" 条数据") |
|
|
|
logger_cron.info("JOB:"+jobid+",接口维度获取到 "+str(len(data_interface))+" 条数据") |
|
|
|
logger_cron.info("JOB:"+jobid+",菜单维度获取到 "+str(len(data_menu))+" 条数据") |
|
|
|
logger_cron.info("JOB:"+jobid+",菜单维度获取到 "+str(len(data_menu))+" 条数据") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_interface_date=[] |
|
|
|
|
|
|
|
logger_cron.info("JOB:"+jobid+","+json.dumps(static_ext)) |
|
|
|
|
|
|
|
for item in data_interface: |
|
|
|
|
|
|
|
if get_file_extension(item.get('interface', '')) in static_ext: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
new_interface_date.append(item) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger_cron.info("JOB:"+jobid+",接口维度实际数据量 "+str(len(new_interface_date))+" 条数据") |
|
|
|
#todo 读取上一次5分钟的文件,与这5分钟的文件合并 |
|
|
|
#todo 读取上一次5分钟的文件,与这5分钟的文件合并 |
|
|
|
#合并完成后 写文件 |
|
|
|
#合并完成后 写文件 |
|
|
|
group_and_write_to_file(data_ip, data_account, data_interface, data_menu, start,jobid) |
|
|
|
group_and_write_to_file(data_ip, data_account, new_interface_date, data_menu, start,jobid,region_dict) |
|
|
|
|
|
|
|
|
|
|
|
def group_and_write_to_file(data_ip, data_account, data_interface, data_menu, start,jobid): |
|
|
|
def group_and_write_to_file(data_ip, data_account, data_interface, data_menu, start,jobid,region_dict): |
|
|
|
# 获取当前工作目录 |
|
|
|
# 获取当前工作目录 |
|
|
|
base_path = get_clean_file_path() |
|
|
|
base_path = get_clean_file_path() |
|
|
|
logger_cron.info("JOB: "+jobid+",写入文件base路径"+base_path) |
|
|
|
logger_cron.info("JOB: "+jobid+",写入文件base路径"+base_path) |
|
|
@ -263,16 +279,19 @@ def group_and_write_to_file(data_ip, data_account, data_interface, data_menu, st |
|
|
|
logger_cron.info("JOB:"+jobid+", tmpfilepath"+tmp_file_path) |
|
|
|
logger_cron.info("JOB:"+jobid+", tmpfilepath"+tmp_file_path) |
|
|
|
|
|
|
|
|
|
|
|
#(datatype,menu,ip,account,jobnum,interface) count |
|
|
|
#(datatype,menu,ip,account,jobnum,interface) count |
|
|
|
|
|
|
|
jobnum_max_length = 20 |
|
|
|
records = {} |
|
|
|
records = {} |
|
|
|
for item in data_ip: |
|
|
|
for item in data_ip: |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
|
|
|
|
if jobnum == "" or len(jobnum) >jobnum_max_length: |
|
|
|
|
|
|
|
continue |
|
|
|
count = item.get('count', 0) |
|
|
|
count = item.get('count', 0) |
|
|
|
datatype = DATA_TYPE.get("IP",1) |
|
|
|
datatype = DATA_TYPE.get("IP",1) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
company = find_region_by_code(jobnum,jobnum_region_dict) |
|
|
|
company = find_region_by_code(jobnum,region_dict) |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
#日志追踪 |
|
|
|
#日志追踪 |
|
|
|
if not os.path.exists(TRACE_PATH): |
|
|
|
if not os.path.exists(TRACE_PATH): |
|
|
@ -283,30 +302,36 @@ def group_and_write_to_file(data_ip, data_account, data_interface, data_menu, st |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
|
|
|
|
if jobnum == "" or len(jobnum) >jobnum_max_length: |
|
|
|
|
|
|
|
continue |
|
|
|
count = item.get('count', 0) |
|
|
|
count = item.get('count', 0) |
|
|
|
datatype = DATA_TYPE.get("ACCOUNT",2) |
|
|
|
datatype = DATA_TYPE.get("ACCOUNT",2) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
company = find_region_by_code(jobnum,jobnum_region_dict) |
|
|
|
company = find_region_by_code(jobnum,region_dict) |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
for item in data_interface: |
|
|
|
for item in data_interface: |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
|
|
|
|
if jobnum == "" or len(jobnum) >jobnum_max_length: |
|
|
|
|
|
|
|
continue |
|
|
|
count = item.get('count', 0) |
|
|
|
count = item.get('count', 0) |
|
|
|
datatype = DATA_TYPE.get("INTERFACE",3) |
|
|
|
datatype = DATA_TYPE.get("INTERFACE",3) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
company = find_region_by_code(jobnum,jobnum_region_dict) |
|
|
|
company = find_region_by_code(jobnum,region_dict) |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
for item in data_menu: |
|
|
|
for item in data_menu: |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
menu = remove_commas(item.get('menu', '')) |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
ip = item.get('ip', '0.0.0.0') |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
account = remove_commas(item.get('account', '')) |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
jobnum = item.get('jobnum', '') |
|
|
|
|
|
|
|
if menu == "" or len(jobnum) >jobnum_max_length: |
|
|
|
|
|
|
|
continue |
|
|
|
count = item.get('count', 0) |
|
|
|
count = item.get('count', 0) |
|
|
|
datatype = DATA_TYPE.get("MENU",4) |
|
|
|
datatype = DATA_TYPE.get("MENU",4) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
interface = remove_commas(item.get('interface', '')) |
|
|
|
company = find_region_by_code(jobnum,jobnum_region_dict) |
|
|
|
company = find_region_by_code(jobnum,region_dict) |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
records[",".join([str(datatype), menu, ip,account,jobnum,interface,company])]=count |
|
|
|
|
|
|
|
|
|
|
|
json_data = json.dumps(records) |
|
|
|
json_data = json.dumps(records) |
|
|
|