@ -7,11 +7,13 @@ from datetime import datetime, timedelta
import calendar
import calendar
import codecs
import codecs
from esUtil import EsUtil
from esUtil import EsUtil
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 , jobnum_region_dict
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 ext_logging import logger_trace
from appsUtils import env
from ext_logging import logger_trace , APPFOLDERNAME
size = 9999 #根据实际情况调整
size = 9999 #根据实际情况调整
@ -23,18 +25,14 @@ DATA_TYPE = {
}
}
## IP维度
## IP维度
def get_ip_group_data ( index , startTime , endTime ) :
def get_ip_group_data ( index , startTime , endTime , diplist ) :
query_body = {
query_body = {
" size " : 0 ,
" size " : 0 ,
" query " : {
" query " : {
" bool " : {
" bool " : {
" filter " : [
" filter " : [
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " bool " : {
{ " terms " : { " dip " : diplist } }
" must_not " : [
{ " match_phrase " : { " account " : " " } }
]
} }
]
]
}
}
} ,
} ,
@ -72,18 +70,14 @@ def get_ip_group_data(index,startTime,endTime):
return datas
return datas
## 账号维度
## 账号维度
def get_account_group_data ( index , startTime , endTime ) :
def get_account_group_data ( index , startTime , endTime , diplist ) :
query_body = {
query_body = {
" size " : 0 ,
" size " : 0 ,
" query " : {
" query " : {
" bool " : {
" bool " : {
" filter " : [
" filter " : [
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " bool " : {
{ " terms " : { " dip " : diplist } }
" must_not " : [
{ " match_phrase " : { " account " : " " } }
]
} }
]
]
}
}
} ,
} ,
@ -124,18 +118,14 @@ def get_account_group_data(index,startTime,endTime):
return datas
return datas
## 接口维度
## 接口维度
def get_interface_group_data ( index , startTime , endTime ) :
def get_interface_group_data ( index , startTime , endTime , diplist ) :
query_body = {
query_body = {
" size " : 0 ,
" size " : 0 ,
" query " : {
" query " : {
" bool " : {
" bool " : {
" filter " : [
" filter " : [
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " bool " : {
{ " terms " : { " dip " : diplist } }
" must_not " : [
{ " match_phrase " : { " account " : " " } }
]
} }
]
]
}
}
} ,
} ,
@ -180,18 +170,14 @@ def get_interface_group_data(index,startTime,endTime):
return datas
return datas
## 菜单维度
## 菜单维度
def get_menu_group_data ( index , startTime , endTime ) :
def get_menu_group_data ( index , startTime , endTime , diplist ) :
query_body = {
query_body = {
" size " : 0 ,
" size " : 0 ,
" query " : {
" query " : {
" bool " : {
" bool " : {
" filter " : [
" filter " : [
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " range " : { " timestamp " : { " gt " : startTime , " lte " : endTime } } } ,
{ " bool " : {
{ " terms " : { " dip " : diplist } }
" must_not " : [
{ " match_phrase " : { " account " : " " } }
]
} }
]
]
}
}
} ,
} ,
@ -237,10 +223,18 @@ 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 clean_data ( read_index , start , end , jobid ) :
def clean_data ( read_index , start , end , jobid ) :
data_ip = get_ip_group_data ( read_index , start , end )
data_account = get_account_group_data ( read_index , start , end )
APPHOME = env . get_isop_root ( ) + " /apps/ " + APPFOLDERNAME
data_interface = get_interface_group_data ( read_index , start , end )
config_path = os . path . normpath ( APPHOME + " /conf/sys_config.json " )
data_menu = get_menu_group_data ( read_index , start , end )
rule_data = read_json_config ( config_path )
dips = rule_data [ " dip " ]
logger_cron . info ( " JOB:dip " + json . dumps ( dips ) )
data_ip = get_ip_group_data ( read_index , start , end , dips )
data_account = get_account_group_data ( read_index , start , end , dips )
data_interface = get_interface_group_data ( read_index , start , end , dips )
data_menu = get_menu_group_data ( read_index , start , end , dips )
if len ( data_ip ) == 0 and len ( data_account ) == 0 and len ( data_interface ) == 0 and len ( data_menu ) == 0 :
if len ( data_ip ) == 0 and len ( data_account ) == 0 and len ( data_interface ) == 0 and len ( data_menu ) == 0 :
logger_cron . info ( " JOB: " + jobid + " ,es中未获取到数据,无需做数据合并 " )
logger_cron . info ( " JOB: " + jobid + " ,es中未获取到数据,无需做数据合并 " )