You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
926 B
25 lines
926 B
3 years ago
|
#!/usr/bin/python3
|
||
|
import requests,json
|
||
3 years ago
|
consul_token = 'xxxxxxxxxx' #Consul SecretID
|
||
3 years ago
|
consul_url = 'http://x.x.x.x:8500/v1'
|
||
|
|
||
3 years ago
|
with open('blackbox-instance.list', 'r') as file:
|
||
3 years ago
|
lines = file.readlines()
|
||
|
for line in lines:
|
||
3 years ago
|
if line.startswith('#'):
|
||
|
continue
|
||
3 years ago
|
module,company,project,env,name,instance = line.split()
|
||
|
headers = {'X-Consul-Token': consul_token}
|
||
|
data = {
|
||
|
"id": f"{module}/{company}/{project}/{env}@{name}",
|
||
|
"name": 'blackbox_exporter',
|
||
|
"tags": [module],
|
||
|
"Meta": {'module':module,'company':company,'project':project,'env':env,'name':name,'instance':instance}
|
||
|
}
|
||
|
|
||
|
reg = requests.put(f"{consul_url}/agent/service/register", headers=headers, data=json.dumps(data))
|
||
|
if reg.status_code == 200:
|
||
|
print({"code": 20000,"data": "增加成功!"})
|
||
|
else:
|
||
|
print({"code": 50000,"data": f'{reg.status_code}:{reg.text}'})
|