MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / run

Function run

script/cron_log_analysis.py:16–53  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

14
15
16def run(path) -> list:
17 from log_analysis import log_analysis
18 log_analysis = log_analysis()
19 get = public.dict_obj()
20 get.action = 'log_analysis'
21 get.path = path
22 res = log_analysis.log_analysis(get)
23 if res['status'] is False:
24 return [res["msg"]]
25 get.action = 'speed_log'
26 start_time = time.time()
27 while True:
28 time.sleep(1)
29 data = log_analysis.speed_log(get)
30 if int(data['msg']) == 100 or data['status'] == False:
31 break
32 if time.time() - start_time > 100:
33 break
34
35 get.action = 'get_result'
36 res = log_analysis.get_result(get)
37 data = res['data'][0]
38 msg_list = []
39 if data['is_status']:
40 all_num = data['php'] + data['san'] + data['sql'] + data['xss']
41 if all_num > 0:
42 msg_list.append('【异常】,共发现{}条异常日志。'.format(all_num))
43 if data['php'] > 0:
44 msg_list.append('PHP攻击{}条。'.format(data['php']))
45 if data['san'] > 0:
46 msg_list.append('恶意扫描{}条。'.format(data['san']))
47 if data['sql'] > 0:
48 msg_list.append('SQL注入攻击{}条。'.format(data['sql']))
49 if data['xss'] > 0:
50 msg_list.append('XSS攻击{}条。'.format(data['xss']))
51 else:
52 msg_list.append('【安全】,未发现异常日志。')
53 return msg_list
54
55
56def send_notification(title, msg, channels):

Callers 1

Calls 7

log_analysisClass · 0.90
timeMethod · 0.80
log_analysisMethod · 0.45
speed_logMethod · 0.45
get_resultMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected