diff --git a/flask-consul/units/cloud/alicloud.py b/flask-consul/units/cloud/alicloud.py
index 6a00340..5043525 100644
--- a/flask-consul/units/cloud/alicloud.py
+++ b/flask-consul/units/cloud/alicloud.py
@@ -124,7 +124,7 @@ def group(account):
data = {'count':'无','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/alicloud/{account}/group', data)
-def ecs(account,region):
+def ecs(account,region,isextip=False):
ak,sk = consul_kv.get_aksk('alicloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')
group_dict = consul_kv.get_value(f'ConsulManager/assets/alicloud/group/{account}')
@@ -145,11 +145,17 @@ def ecs(account,region):
ecs = client.describe_instances(describe_instances_request)
ecs_list = ecs.body.instances.to_map()['Instance']
ecs_dict_temp = {i['InstanceId']:{
- 'name':i['InstanceName'],'group':group_dict.get(i['ResourceGroupId'],'无'),'ostype':i['OSType'].lower(),
- 'status':i['Status'],'region':region,
- 'ip':i["InnerIpAddress"]["IpAddress"] if len(i["InnerIpAddress"]["IpAddress"]) != 0 else i['NetworkInterfaces']['NetworkInterface'][0]['PrimaryIpAddress'],
+ 'name':i['InstanceName'],'group':group_dict.get(i['ResourceGroupId'],'无'),'ostype':i['OSType'].lower(),'status':i['Status'],'region':region,
+ 'ip':i["InnerIpAddress"]["IpAddress"][0] if i["InnerIpAddress"]["IpAddress"] else i['NetworkInterfaces']['NetworkInterface'][0]['PrimaryIpAddress'],
'cpu':f"{i['Cpu']}核",'mem':f"{str(round(i['Memory']/1024,1)).rstrip('.0')}GB",'exp':i['ExpiredTime'].split('T')[0],'ecstag': i.get('Tags',{}).get('Tag',[])
}for i in ecs_list}
+
+ if isextip:
+ for i in ecs_list:
+ try:
+ ecs_dict_temp[i['InstanceId']]['ip'] = i['PublicIpAddress']['IpAddress'][0] if i['PublicIpAddress']['IpAddress'] else i["EipAddress"]["IpAddress"]
+ except:
+ pass
ecs_dict.update(ecs_dict_temp)
next_token = ecs.body.next_token
diff --git a/flask-consul/units/cloud/huaweicloud.py b/flask-consul/units/cloud/huaweicloud.py
index 12091eb..2d8a35a 100644
--- a/flask-consul/units/cloud/huaweicloud.py
+++ b/flask-consul/units/cloud/huaweicloud.py
@@ -126,7 +126,7 @@ def group(account):
data = {'count':'无','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/huaweicloud/{account}/group', data)
-def ecs(account,region):
+def ecs(account,region,isextip=False):
ak,sk = consul_kv.get_aksk('huaweicloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')
group_dict = consul_kv.get_value(f'ConsulManager/assets/huaweicloud/group/{account}')
diff --git a/flask-consul/units/cloud/tencent_cloud.py b/flask-consul/units/cloud/tencent_cloud.py
index 450c185..277712e 100644
--- a/flask-consul/units/cloud/tencent_cloud.py
+++ b/flask-consul/units/cloud/tencent_cloud.py
@@ -114,7 +114,7 @@ def group(account):
data = {'count':'无','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/group', data)
-def ecs(account,region):
+def ecs(account,region,isextip=False):
from tencentcloud.cvm.v20170312 import cvm_client, models
ak,sk = consul_kv.get_aksk('tencent_cloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')
diff --git a/flask-consul/views/edit_cloud.py b/flask-consul/views/edit_cloud.py
index f5cc7f8..9c5f66b 100644
--- a/flask-consul/views/edit_cloud.py
+++ b/flask-consul/views/edit_cloud.py
@@ -3,7 +3,7 @@ from flask_restful import reqparse, Resource, Api
from flask_apscheduler import APScheduler
from config import vendors,regions
from units import token_auth,consul_kv
-from .jobs import deljob,addjob,runjob,modjob_interval
+from .jobs import deljob,addjob,runjob,modjob_interval,modjob_args
import json
blueprint = Blueprint('edit_cloud',__name__)
api = Api(blueprint)
@@ -34,16 +34,18 @@ class Edit(Resource):
region = args['region']
restype = ['group']
interval = {'proj_interval': 60, 'ecs_interval': 5, 'rds_interval': 5}
+ isextip = False
for i in self.job_list:
if f'{vendor}/{account}/group' == i['id']:
interval['proj_interval'] = i['minutes']
elif f'{vendor}/{account}/ecs/{region}' == i['id']:
restype.append('ecs')
interval['ecs_interval'] = i['minutes']
+ isextip = i["args"][-1] if len(i["args"]) == 3 else False
elif f'{vendor}/{account}/rds/{region}' == i['id']:
restype.append('rds')
interval['rds_interval'] = i['minutes']
- return {'code': 20000, 'restype': restype, 'interval': interval}
+ return {'code': 20000, 'restype': restype, 'interval': interval, 'isextip': isextip}
def post(self,stype):
if stype == 'commit':
args = parser.parse_args()
@@ -52,6 +54,7 @@ class Edit(Resource):
account = editjob_dict['account']
region = editjob_dict['region']
restype = editjob_dict['restype']
+ isextip = editjob_dict['isextip']
proj_interval = int(editjob_dict['proj_interval'])
ecs_interval = int(editjob_dict['ecs_interval'])
rds_interval = int(editjob_dict['rds_interval'])
@@ -74,11 +77,17 @@ class Edit(Resource):
isecs = [x for x in self.job_list if x['id'] == f'{vendor}/{account}/ecs/{region}']
if len(isecs) == 1:
if ecs_interval != isecs[0]['minutes']:
+ isecs[0]['minutes'] = ecs_interval
consul_kv.put_kv(f'ConsulManager/jobs/{ecs_jobid}',isecs[0])
modjob_interval(ecs_jobid,ecs_interval)
+
+ if len(isecs[0]['args']) != 3 or isextip != isecs[0]['args'][2]:
+ isecs[0]['args'][2] = isextip
+ consul_kv.put_kv(f'ConsulManager/jobs/{ecs_jobid}',isecs[0])
+ modjob_args(ecs_jobid,isecs[0]['args'])
else:
job_func = f"__main__:{vendor}.ecs"
- job_args = [account,region]
+ job_args = [account,region,isextip]
job_interval = ecs_interval
addjob(ecs_jobid, job_func, job_args, job_interval)
job_dict = {'id':ecs_jobid,'func':job_func,'args':job_args,'minutes':job_interval,
@@ -95,6 +104,7 @@ class Edit(Resource):
isrds = [x for x in self.job_list if x['id'] == f'{vendor}/{account}/rds/{region}']
if len(isrds) == 1:
if rds_interval != isrds[0]['minutes']:
+ isrds[0]['minutes'] = rds_interval
consul_kv.put_kv(f'ConsulManager/jobs/{rds_jobid}',isrds[0])
modjob_interval(rds_jobid,rds_interval)
else:
diff --git a/flask-consul/views/jobs.py b/flask-consul/views/jobs.py
index 5d696d2..43748c2 100644
--- a/flask-consul/views/jobs.py
+++ b/flask-consul/views/jobs.py
@@ -23,6 +23,9 @@ def deljob(jobid):
def modjob_interval(jobid,job_interval):
Scheduler.modify_job(jobid,trigger='interval',minutes=job_interval)
+def modjob_args(jobid,args):
+ Scheduler.modify_job(jobid,args=args)
+
def addjob(job_id,job_func,job_args,job_interval):
Scheduler.add_job(id=job_id, func=job_func, args=job_args, trigger='interval',
minutes=job_interval, replace_existing=True)
@@ -97,7 +100,10 @@ class Jobs(Resource):
for reg in job_dict['region']:
res_job_id = f"{job_dict['vendor']}/{job_dict['account']}/{res}/{reg}"
res_job_func = f"__main__:{job_dict['vendor']}.{res}"
- res_job_args = [job_dict['account'],reg]
+ if reg == 'ecs':
+ res_job_args = [job_dict['account'],reg,job_dict['isextip']]
+ else:
+ res_job_args = [job_dict['account'],reg]
res_job_interval = int(job_dict[f'{res}_interval'])
Scheduler.add_job(id=res_job_id, func=res_job_func, args=res_job_args, trigger='interval',
minutes=res_job_interval, replace_existing=True)
diff --git a/vue-consul/src/main.js b/vue-consul/src/main.js
index 1489bcd..90b5f27 100644
--- a/vue-consul/src/main.js
+++ b/vue-consul/src/main.js
@@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => {
})
Vue.config.productionTip = false
-Vue.prototype.VER = 'v0.10.1'
+Vue.prototype.VER = 'v0.10.2'
new Vue({
el: '#app',
diff --git a/vue-consul/src/views/node-exporter/jobs.vue b/vue-consul/src/views/node-exporter/jobs.vue
index 530c7c2..0e33260 100644
--- a/vue-consul/src/views/node-exporter/jobs.vue
+++ b/vue-consul/src/views/node-exporter/jobs.vue
@@ -92,6 +92,8 @@
+
需要开通企业项目(更多-企业-项目管理)
+ 已支持采集ECS标签
@@ -123,7 +125,9 @@
MySQL
-
+
+ (仅支持阿里云ECS)
+
@@ -170,7 +174,7 @@
-
+
@@ -192,7 +196,9 @@
MySQL
-
+
+ (仅支持阿里云ECS)
+
@@ -377,6 +383,7 @@ export default {
this.listLoading = true
findGroup(vendor, account, region).then(response => {
this.editJob.restype = response.restype
+ this.editJob.isextip = response.isextip
this.editJob.proj_interval = response.interval.proj_interval
this.editJob.ecs_interval = response.interval.ecs_interval
this.editJob.rds_interval = response.interval.rds_interval
@@ -384,14 +391,14 @@ export default {
})
},
handleEdit() {
- this.editJob = { vendor: '', akskswitch: false, ak: '', sk: '', region: '', account: '', restype: ['group'], proj_interval: 60, ecs_interval: 10, rds_interval: 20 }
+ this.editJob = { vendor: '', akskswitch: false, ak: '', sk: '', region: '', account: '', restype: ['group'], proj_interval: 60, ecs_interval: 10, rds_interval: 20, isextip: false }
getCloud().then(response => {
this.cloud_dict = response.cloud_dict
})
this.editFormVisible = true
},
handleCreate() {
- this.ecsJob = { vendor: '', ak: '', sk: '', region: [], account: '', proj_interval: 60, ecs_interval: 10, rds_interval: 20 }
+ this.ecsJob = { vendor: '', ak: '', sk: '', region: [], account: '', proj_interval: 60, ecs_interval: 10, rds_interval: 20, isextip: false }
this.ecsJob.account = this.query.account
this.newFormVisible = true
},