-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandleMonitorItem.py
79 lines (56 loc) · 1.93 KB
/
handleMonitorItem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# coding=utf-8
__author__ = 'T440P'
from monitorCenter import monitorCenter
from config import config
import time
a = monitorCenter.MonitorDB(host=config.eshost,index="monitor")
#根据查询进行局部删除
def deleteMonitor(docType,query):
a.deleteByQuery(type=docType, query=query)
#根据查询进行局部更新
def updateMonitorItem():
doc ={
"doc": {
"strategy":
{
"threshold":20000
}
}
}
query = {"query":{"match_all":{}}}
a.updateByQuery(type="monitorItem",query=query,doc=doc)
def insertMonitorItemFromFile_intranet():
f = open("profileTracker.txt")
for l in f.readlines():
url = l
print(url)
product = 'wd'
name = "[%s]-[%s]"%(product,url)
alarm_group_id = 122339
if product.lower() == 'ad':
alarm_group_id = 122339
elif product.lower() == 'vd':
alarm_group_id = 122343
elif product.lower() == 'wd':
alarm_group_id = 122341
a.insertMonitorItem(id=config.randomId(),scope='intranet',product=product,monitor_type=1,name=name,description=''
,objects=url,cluster_ids=[],alarm_group_id=alarm_group_id,
template_id=1,alarm_clusters=2,occur_times=2,max_alarm_count=1,
time_threshold=20000,ip="",opsignal=0,user="guyajun",password='gs@123456')
if __name__ == "__main__":
# insertMonitorItemFromFile_intranet()
# updateMonitorItem()
######## delete history###########
begin = time.time()
query = {}
try:
deleteMonitor(docType='event',query=query)
except Exception as e:
pass
# try:
deleteMonitor(docType='history',query=query)
# except Exception as e:
# pass
end = time.time()
print(end-begin)
####################################