From 4aa50624c7a1b7f45ceb6c640fab4b38a9d39546 Mon Sep 17 00:00:00 2001 From: "StarsL.cn" Date: Tue, 5 Jul 2022 06:56:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E5=88=B0=E6=9C=9FEC?= =?UTF-8?q?S=E6=94=AF=E6=8C=81=E6=98=BE=E7=A4=BA=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flask-consul/requirements.txt | 6 +++--- flask-consul/units/cloud/alicloud.py | 9 ++++++--- flask-consul/views/exp.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flask-consul/requirements.txt b/flask-consul/requirements.txt index 8674e67..0053822 100644 --- a/flask-consul/requirements.txt +++ b/flask-consul/requirements.txt @@ -10,9 +10,9 @@ xlrd==1.2.0 #pyDes==2.0.1 pycryptodome==3.14.1 beautifulsoup4==4.11.1 -huaweicloudsdkcore==3.0.78 -huaweicloudsdkecs==3.0.78 -huaweicloudsdkeps==3.0.78 +huaweicloudsdkcore==3.0.95 +huaweicloudsdkecs==3.0.95 +huaweicloudsdkeps==3.0.95 huaweicloudsdkbss==3.0.95 alibabacloud_resourcemanager20200331==2.1.0 alibabacloud_ecs20140526==2.1.0 diff --git a/flask-consul/units/cloud/alicloud.py b/flask-consul/units/cloud/alicloud.py index 352af47..cfb9b69 100644 --- a/flask-consul/units/cloud/alicloud.py +++ b/flask-consul/units/cloud/alicloud.py @@ -10,7 +10,7 @@ from alibabacloud_tea_util import models as util_models from alibabacloud_tea_util.client import Client as UtilClient import sys,datetime,hashlib -from units import consul_kv +from units import consul_kv,consul_svc from units.cloud import sync_ecs from units.cloud import notify @@ -39,8 +39,10 @@ def exp(account,collect_days,notify_days,notify_amount): notify_id = hashlib.md5(str(i).encode(encoding='UTF-8')).hexdigest() endtime = datetime.datetime.strptime(i['EndTime'],'%Y-%m-%dT%H:%M:%SZ') + datetime.timedelta(hours=8) endtime_str = endtime.strftime('%Y-%m-%d') + iname = consul_svc.get_sid(i['InstanceID'])['instance']['Meta']['name'] if i['ProductCode'] == 'ecs' else 'Null' exp_dict[i['InstanceID']] = {'Region':i.get('Region','Null'),'Product':i['ProductCode'], - 'EndTime':endtime_str,'Ptype':i.get('ProductType',i['ProductCode']),'notify_id':notify_id} + 'Name':iname,'EndTime':endtime_str,'notify_id':notify_id, + 'Ptype':i.get('ProductType',i['ProductCode'])} if (endtime - datetime.datetime.now()).days < notify_days and notify_id not in isnotify_list: notify_dict[i['InstanceID']] = exp_dict[i['InstanceID']] consul_kv.put_kv(f'ConsulManager/exp/lists/alicloud/{account}/exp', exp_dict) @@ -55,7 +57,8 @@ def exp(account,collect_days,notify_days,notify_amount): if notify_dict != {}: msg = [f'### 阿里云账号 {account}:\n### 以下资源到期日小于 {notify_days} 天:'] for k,v in notify_dict.items(): - msg.append(f"- {v['Region']}:{v['Product']}:{k}:{v['EndTime']}") + iname = k if v['Name'] == 'Null' else v['Name'] + msg.append(f"- {v['Region']}:{v['Product']}:{iname}:{v['EndTime']}") content = '\n'.join(msg) if exp_config['switch'] and exp_config.get('wecom',False): notify.wecom(wecomwh,content) diff --git a/flask-consul/views/exp.py b/flask-consul/views/exp.py index a349292..c5bcc6b 100644 --- a/flask-consul/views/exp.py +++ b/flask-consul/views/exp.py @@ -14,7 +14,7 @@ parser.add_argument('exp_config_dict',type=dict) parser.add_argument('isnotify_dict',type=dict) class Exp(Resource): - #decorators = [token_auth.auth.login_required] + decorators = [token_auth.auth.login_required] def get(self,stype): if stype == 'list': switch = consul_kv.get_value(f'ConsulManager/exp/config').get('switch',False)