-
Notifications
You must be signed in to change notification settings - Fork 0
/
360yun2local.py
125 lines (75 loc) · 3.63 KB
/
360yun2local.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# coding=utf-8
from tracker import generic_url, dns
from monitorCenter import monitorCenter
from config import config
import requests
from tracker import generic_url
import time
es = monitorCenter.MonitorDB(host=config.eshost,index="monitor")
def inser2monitoItem():
publicUrls = generic_url.geturlsfrom360()
objects = generic_url.getobjectsfrom360()
if len(objects) != 0:
for i in objects:
privateUrls = getlocalUrls(i["object"])
#判断是否有负载均衡
if len(privateUrls) != 0:
ip = generic_url.getUrlDomain(i["object"])
product = ''
try:
a = i["name"].split('-')[0]
product = a[1:len(a)-1].lower()
except Exception as e:
ex_str = traceback.format_exc()
print(ex_str)
try:
for privateurl in privateUrls:
if "https" in privateurl:
privateurl = privateurl.replace("https","http")
urls = es.getmonitorItembyUrl(privateurl)
if privateurl not in urls:
es.insertMonitorItem(id=config.randomId(),scope='intranet',product=product,monitor_type=1,name= i["name"] ,description=''
,objects= privateurl ,cluster_ids=[],alarm_group_id=122339
,template_id=1,alarm_clusters=2,occur_times=2,max_alarm_count=1,time_threshold=10000,ip=ip,opsignal=0)
except Exception as e:
print(e)
#公网url转换为私网url
def getlocalUrls(publicUrl):
#获取域名
domainName = generic_url.getUrlDomain(publicUrl)
#如果做了负载均衡
realServeripList = getrealServerUrls(domainName)
privateUrls = []
if len(realServeripList) != 0:
for i in realServeripList:
privateUrls.append(publicUrl.replace(domainName,i))
return privateUrls
def getrealServerUrls(domainName):
a = monitorCenter.MonitorDB(host=config.eshost, index="monitor")
res = es.getdomainMapping(domainName)
if len(res) != 0:
return res["_source"]["realServer"]
else:
return []
if __name__ == "__main__":
# getlocalUrls("http://proc-appguide-mediad.gridsumdissector.com/api/healthcheck/heartbeat")
r = requests.get(url='http://10.201.80.35',headers={'host':'rc.gridsumdissector.com'})
# r = requests.get(url='http://10.201.40.179/track.ashx?gsadid=gad_128_RQ749CYW',headers={'host':'click.gridsumdissector.com'})
# r = requests.get(url='http://10.200.50.217/zabbix')
# r = requests.get(url='http://10.200.200.166:8015/')
# begintime = time.time()
# r = requests.get("http://10.201.50.120:8907/api/dsync/brandsecurity/snapshot/heartbeat/isalive")
# endtime = time.time()
# begintime = time.time()
# r = requests.get("http://10.200.50.217/zabbix")
# endtime = time.time()
# res = requests.get("http://10.200.40.91/client/clientbin/webdissectorclient.xap" ,headers= {'host':'www.webdissector.cn'})
# print(res)
# r = requests.get("https://10.201.40.190/",headers = {'host':'beta-ad.gridsumdissector.com'})
# r = requests.get("http://10.201.50.109:9091/api/dsync/jobscheduler/heartbeat/isalive", auth=('','') ,headers={})
# rtext = res.text
print(r.status_code)
# print(r.elapsed.seconds+r.elapsed.microseconds)
# print(r.headers)
#
# inser2monitoItem()