Skip to content

Commit

Permalink
Releases 0.12.0,fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
starsliao committed Dec 11, 2022
1 parent 2d18a54 commit 542be82
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 35 deletions.
14 changes: 11 additions & 3 deletions flask-consul/units/blackbox_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests,json,consul_kv
import requests,json,consul_kv,re
from config import consul_token,consul_url
from units.config_log import *

headers = {'X-Consul-Token': consul_token}
init_module_list = ['http_2xx','http_4xx','tcp_connect','icmp','http200igssl','httpNoRedirect4ssl','http_5xx','http_post_2xx','ssh_banner']
Expand All @@ -24,6 +25,7 @@ def get_all_list(module,company,project,env):
return {'code': 20000,'all_list':all_list,'module_list':module_list,
'company_list':company_list,'project_list':project_list,'env_list':env_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def get_service():
Expand All @@ -42,10 +44,12 @@ def get_service():
return {'code': 20000,'all_list':all_list,'module_list':module_list,
'company_list':company_list,'project_list':project_list,'env_list':env_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def add_service(module,company,project,env,name,instance):
sid = f"{module}/{company}/{project}/{env}@{name}"
sid = f"{module}/{company}/{project}/{env}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)
if '//' in sid or sid.startswith('/') or sid.endswith('/'):
return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"}
data = {
Expand All @@ -58,14 +62,18 @@ def add_service(module,company,project,env,name,instance):
if reg.status_code == 200:
return {"code": 20000, "data": f"【{sid}】增加成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def del_service(module,company,project,env,name):
sid = f"{module}/{company}/{project}/{env}@{name}"
sid = f"{module}/{company}/{project}/{env}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
if reg.status_code == 200:
logger.debug(f"【{sid}】删除成功!")
return {"code": 20000, "data": f"【{sid}】删除成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def get_rules():
Expand Down
21 changes: 13 additions & 8 deletions flask-consul/units/consul_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import requests,json
import sys
sys.path.append("..")
import requests,json,re
from config import consul_token,consul_url
from units.config_log import *

Expand All @@ -22,6 +20,7 @@ def get_hosts():
'free':f'{round(info["Disk"]["free"]/1024**3)}GB','used':f'{round(info["Disk"]["used"]/1024**3)}GB','usedPercent':f'{pdisk}%'}
return {'code': 20000,'host':host,'cpu':cpu,'memory':memory,'disk':disk, 'pmem':pmem, 'pdisk':pdisk}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
def get_services():
url = f'{consul_url}/internal/ui/services'
Expand All @@ -40,6 +39,7 @@ def get_services_nameonly():
info.pop('consul')
return {'code': 20000,'services_name':list(info.keys())}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}
def get_instances(service_name):
url = f'{consul_url}/health/service/{service_name}'
Expand Down Expand Up @@ -68,17 +68,21 @@ def get_instances(service_name):
instances_list.append(instance_dict)
return {'code': 20000,'instances':instances_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def del_instance(service_id):
reg = requests.put(f'{consul_url}/agent/service/deregister/{service_id}', headers=headers)
def del_instance(sid):
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
if reg.status_code == 200:
return {"code": 20000, "data": f"【{service_id}】删除成功!"}
logger.debug(f"【{sid}】删除成功!")
return {"code": 20000, "data": f"【{sid}】删除成功!"}
else:
return {"code": 50000, "data": f"{reg.status_code}{service_id}{reg.text}"}
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def add_instance(instance_dict):
sid = instance_dict['ID']
sid = instance_dict['ID'].strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)
if '//' in sid or sid.startswith('/') or sid.endswith('/'):
return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"}
isMeta = instance_dict['metaInfo']['isMeta']
Expand Down Expand Up @@ -119,5 +123,6 @@ def add_instance(instance_dict):
if reg.status_code == 200:
return {"code": 20000, "data": f"【{sid}】增加成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

18 changes: 12 additions & 6 deletions flask-consul/units/selfnode_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests,json
import sys
sys.path.append("..")
import requests,json,re
#import sys
#sys.path.append("..")
from config import consul_token,consul_url
from units.config_log import *

Expand All @@ -23,6 +23,7 @@ def get_all_list(vendor,account,region,group):
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def get_service():
Expand All @@ -37,12 +38,14 @@ def get_service():
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def add_service(vendor,account,region,group,name,ip,port,os):
if port is None or name is None:
return {"code": 50000, "data": f"名称或IP不能为空!"}
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)
instance = f'{ip}:{port}'
if '//' in sid or sid.startswith('/') or sid.endswith('/'):
return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"}
Expand All @@ -60,14 +63,17 @@ def add_service(vendor,account,region,group,name,ip,port,os):
if reg.status_code == 200:
return {"code": 20000, "data": f"【{sid}】增加成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def del_service(vendor,account,region,group,name):
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
if reg.status_code == 200:
logger.debug(f"【{sid}】删除成功!")
return {"code": 20000, "data": f"【{sid}】删除成功!"}
else:
logger.info(f"{reg.status_code}{sid}{reg.text}")
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

19 changes: 12 additions & 7 deletions flask-consul/units/selfrds_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import requests,json
import sys
sys.path.append("..")
import requests,json,re
from config import consul_token,consul_url
from units.config_log import *
headers = {'X-Consul-Token': consul_token}
Expand All @@ -22,6 +20,7 @@ def get_all_list(vendor,account,region,group):
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def get_service():
Expand All @@ -36,14 +35,17 @@ def get_service():
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def add_service(vendor,account,region,group,name,ip,port,os):
if port is None or name is None:
return {"code": 50000, "data": f"名称或IP不能为空!"}
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
#sid = eval(repr(sid).replace('\\t','').replace('\\n',''))
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@rds'
instance = f'{ip}:{port}'
if '//' in sid or sid.startswith('/') or sid.endswith('/'):
if '//' in sid or sid.startswith('/'):
return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"}
data = {
"id": sid,
Expand All @@ -59,14 +61,17 @@ def add_service(vendor,account,region,group,name,ip,port,os):
if reg.status_code == 200:
return {"code": 20000, "data": f"【{sid}】增加成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def del_service(vendor,account,region,group,name):
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@rds'
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
if reg.status_code == 200:
logger.debug(f"【{sid}】删除成功!")
return {"code": 20000, "data": f"【{sid}】删除成功!"}
else:
logger.info(f"{reg.status_code}{sid}{reg.text}")
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

18 changes: 11 additions & 7 deletions flask-consul/units/selfredis_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import requests,json
import sys
sys.path.append("..")
import requests,json,re
from config import consul_token,consul_url
from units.config_log import *
headers = {'X-Consul-Token': consul_token}
Expand All @@ -22,6 +20,7 @@ def get_all_list(vendor,account,region,group):
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def get_service():
Expand All @@ -36,14 +35,16 @@ def get_service():
return {'code': 20000,'all_list':all_list,'vendor_list':vendor_list,
'account_list':account_list,'region_list':region_list,'group_list':group_list}
else:
logger.error(f"{response.status_code}{response.text}")
return {'code': 50000, 'data': f'{response.status_code}:{response.text}'}

def add_service(vendor,account,region,group,name,ip,port,os):
if port is None or name is None:
return {"code": 50000, "data": f"名称或IP不能为空!"}
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@redis'
instance = f'{ip}:{port}'
if '//' in sid or sid.startswith('/') or sid.endswith('/'):
if '//' in sid or sid.startswith('/'):
return {"code": 50000, "data": f"服务ID【{sid}】首尾不能包含'/',并且不能包含两个连续的'/'"}
data = {
"id": sid,
Expand All @@ -59,13 +60,16 @@ def add_service(vendor,account,region,group,name,ip,port,os):
if reg.status_code == 200:
return {"code": 20000, "data": f"【{sid}】增加成功!"}
else:
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}

def del_service(vendor,account,region,group,name):
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}".strip()
sid = re.sub('[[ \]`~!\\\#$^&*=|"{}\':;?\t\n]','_',sid)+'@redis'
reg = requests.put(f'{consul_url}/agent/service/deregister/{sid}', headers=headers)
if reg.status_code == 200:
logger.debug(f"【{sid}】删除成功!")
return {"code": 20000, "data": f"【{sid}】删除成功!"}
else:
logger.info(f"{reg.status_code}{sid}{reg.text}")
logger.error(f"{reg.status_code}{sid}{reg.text}")
return {"code": 50000, "data": f"{reg.status_code}{sid}{reg.text}"}
6 changes: 3 additions & 3 deletions flask-consul/units/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def importconsul(row,imptype):
elif imptype == 'selfrds':
vendor,account,region,group,name,instance,os = row
logger.info(row)
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}@rds"
ip = instance.split(':')[0]
port = instance.split(':')[1]
data = {
Expand All @@ -51,7 +51,7 @@ def importconsul(row,imptype):
elif imptype == 'selfredis':
vendor,account,region,group,name,instance,os = row
logger.info(row)
sid = f"{vendor}/{account}/{region}/{group}@{name}"
sid = f"{vendor}/{account}/{region}/{group}@{name}@redis"
ip = instance.split(':')[0]
port = instance.split(':')[1]
data = {
Expand Down Expand Up @@ -96,7 +96,7 @@ def read_execl(file_contents,imptype):
j = i.strip()
j = '_' if j == '' else j
if i != row[5]:
j = re.sub('[[ \]`~!\\\#$^/&*=|"{}\':;?]','_',j)
j = re.sub('[[ \]`~!\\\#$^/&*=|"{}\':;?\t\n]','_',j)
nrow.append(j)
imp = importconsul(nrow,imptype)
if imp['code'] == 50000:
Expand Down
2 changes: 1 addition & 1 deletion vue-consul/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => {
})

Vue.config.productionTip = false
Vue.prototype.VER = 'v0.11.2'
Vue.prototype.VER = 'v0.12.0'

new Vue({
el: '#app',
Expand Down
21 changes: 21 additions & 0 deletions vue-consul/src/views/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
<el-link :underline="false" type="primary" href="https://github.com/starsliao/ConsulManager" target="_blank" class="dashboard-text">🚀StarsL.cn</el-link>
</el-badge>
<el-timeline>
<el-timeline-item timestamp="2022/12/12" placement="top">
<el-card>
<h4>v0.12.0</h4>
<p><el-button type="primary" size="mini" icon="el-icon-star-off" circle />修复:自建ECS/RDS/Redis:增加同SID(前5个字段相同)的实例导致,之前增加的同SID实例被替换掉的问题。</p>
<p><el-button type="primary" size="mini" icon="el-icon-star-off" circle />修复:站点与接口监控、自建ECS/RDS/Redis:实例字段中有特殊字符会无法删除的问题。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>以上2个改动可能会引起上述菜单功能兼容性问题:如果出现更新或删除自定义实例失败,请执行以下操作:</strong></p>
<ul>
<li>在相应的实例管理页面,使用导出功能导出实例列表。</li>
<li>进入<strong>Consul管理-实例管理</strong>菜单,选择相应的服务组,全选删除所有的实例。</li>
<li>再返回相应的实例管理页面,重新执行导入操作。</li>
</ul>
<p><el-button type="success" size="mini" icon="el-icon-star-off" circle />优化:<el-link :underline="false" type="primary" href="https://grafana.com/grafana/dashboards/17320-1-mysqld-exporter-dashboard/" target="_blank">Mysqld Exporter Grafana Dashboard</el-link>,兼容自建MySQL与云RDS,都能正常展示CPU、内存、磁盘等部分Mysqld_Exporter不提供的指标:</p>
<ul>
<li>自建Mysql:从node-exporter中获取以上信息,通过instance的IP部分进行关联。</li>
<li>云DRS:从ConsulManager-MySQL中获取,会根据实例ID进行关联。(数据来自云监控,从ConsulManager的Prometheus配置生成菜单中可生成配置。)</li>
</ul>
</el-card>
</el-timeline-item>
<el-timeline-item timestamp="2022/11/28" placement="top">
<el-card>
<h4>v0.11.1</h4>
Expand Down Expand Up @@ -237,4 +255,7 @@ export default {
line-height: 46px;
}
}
li {
margin: 20px 0;
}
</style>

0 comments on commit 542be82

Please sign in to comment.