parent
82707f82cb
commit
6abd55f9e1
|
@ -9,7 +9,7 @@ from alibabacloud_bssopenapi20171214 import models as bss_open_api_20171214_mode
|
|||
from alibabacloud_tea_util import models as util_models
|
||||
from alibabacloud_tea_util.client import Client as UtilClient
|
||||
|
||||
import sys,datetime
|
||||
import sys,datetime,hashlib
|
||||
from units import consul_kv
|
||||
from units.cloud import sync_ecs
|
||||
from units.cloud import notify
|
||||
|
@ -31,14 +31,17 @@ def exp(account,collect_days,notify_days,notify_amount):
|
|||
exp = client.query_available_instances_with_options(query_available_instances_request, runtime)
|
||||
exp_list = exp.body.to_map()['Data']['InstanceList']
|
||||
exp_dict = {}
|
||||
isnotify_list = consul_kv.get_keys_list(f'ConsulManager/exp/isnotify/alicloud/{account}')
|
||||
isnotify_list = [i.split('/')[-1] for i in isnotify_list]
|
||||
notify_dict = {}
|
||||
amount_dict = {}
|
||||
for i in exp_list:
|
||||
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')
|
||||
exp_dict[i['InstanceID']] = {'Region':i['Region'],'Product':i['ProductCode'],
|
||||
'EndTime':endtime_str,'Ptype':i.get('ProductType',i['ProductCode'])}
|
||||
if (endtime - datetime.datetime.now()).days < notify_days:
|
||||
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}
|
||||
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)
|
||||
amount = float(amount_response.body.data.available_amount.replace(',',''))
|
||||
|
|
|
@ -6,7 +6,7 @@ from huaweicloudsdkeps.v1 import *
|
|||
from huaweicloudsdkecs.v2.region.ecs_region import EcsRegion
|
||||
from huaweicloudsdkecs.v2 import *
|
||||
from huaweicloudsdkbss.v2 import *
|
||||
import sys,datetime
|
||||
import sys,datetime,hashlib
|
||||
from units import consul_kv
|
||||
from units.cloud import sync_ecs
|
||||
from units.cloud import notify
|
||||
|
@ -31,6 +31,8 @@ def exp(account,collect_days,notify_days,notify_amount):
|
|||
)
|
||||
exp_list = client.list_pay_per_use_customer_resources(request).to_dict()['data']
|
||||
exp_dict = {}
|
||||
isnotify_list = consul_kv.get_keys_list(f'ConsulManager/exp/isnotify/huaweicloud/{account}')
|
||||
isnotify_list = [i.split('/')[-1] for i in isnotify_list]
|
||||
notify_dict = {}
|
||||
amount_dict = {}
|
||||
for i in exp_list:
|
||||
|
@ -38,9 +40,10 @@ def exp(account,collect_days,notify_days,notify_amount):
|
|||
endtime_str = endtime.strftime('%Y-%m-%d')
|
||||
i['service_type_code'].replace('hws.service.type.','')
|
||||
if i['expire_policy'] not in [1,3,4]:
|
||||
notify_id = hashlib.md5(str(i).encode(encoding='UTF-8')).hexdigest()
|
||||
exp_dict[i['resource_id']] = {'Region':i['region_code'],'Product':i['resource_spec_code'],
|
||||
'EndTime':endtime_str,'Name':i['resource_name'],'Ptype':i['resource_type_code']}
|
||||
if (endtime - datetime.datetime.now()).days < notify_days:
|
||||
'EndTime':endtime_str,'Name':i['resource_name'],'Ptype':i['resource_type_code'],'notify_id':notify_id}
|
||||
if (endtime - datetime.datetime.now()).days < notify_days and notify_id not in isnotify_list:
|
||||
notify_dict[i['resource_id']] = exp_dict[i['resource_id']]
|
||||
|
||||
consul_kv.put_kv(f'ConsulManager/exp/lists/huaweicloud/{account}/exp', exp_dict)
|
||||
|
|
|
@ -4,7 +4,7 @@ from tencentcloud.common.profile.client_profile import ClientProfile
|
|||
from tencentcloud.common.profile.http_profile import HttpProfile
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
|
||||
|
||||
import sys,datetime
|
||||
import sys,datetime,hashlib
|
||||
#sys.path.append("..")
|
||||
#import consul_kv,sync_ecs
|
||||
from units import consul_kv
|
||||
|
@ -14,6 +14,8 @@ def exp(account,collect_days,notify_days,notify_amount):
|
|||
from tencentcloud.billing.v20180709 import billing_client, models
|
||||
ak,sk = consul_kv.get_aksk('tencent_cloud',account)
|
||||
exp_dict = {}
|
||||
isnotify_list = consul_kv.get_keys_list(f'ConsulManager/exp/isnotify/tencent_cloud/{account}')
|
||||
isnotify_list = [i.split('/')[-1] for i in isnotify_list]
|
||||
notify_dict = {}
|
||||
amount_dict = {}
|
||||
try:
|
||||
|
@ -22,9 +24,10 @@ def exp(account,collect_days,notify_days,notify_amount):
|
|||
for i in ecs_list:
|
||||
exp_day = datetime.datetime.strptime(i['exp'], '%Y-%m-%d')
|
||||
if (exp_day - now).days <= collect_days:
|
||||
notify_id = hashlib.md5(str(i).encode(encoding='UTF-8')).hexdigest()
|
||||
exp_dict[i['iid']] = {'Region':i['region'],'Product':i['os'],'Name':i['name'],
|
||||
'EndTime':i['exp'],'Ptype':i['cpu']+i['mem'],'Group':i['group']}
|
||||
if (exp_day - now).days <= notify_days:
|
||||
'EndTime':i['exp'],'Ptype':i['cpu']+i['mem'],'Group':i['group'],'notify_id':notify_id}
|
||||
if (exp_day - now).days <= notify_days and notify_id not in isnotify_list:
|
||||
notify_dict[i['iid']] = exp_dict[i['iid']]
|
||||
consul_kv.put_kv(f'ConsulManager/exp/lists/tencent_cloud/{account}/exp', exp_dict)
|
||||
|
||||
|
|
|
@ -2,25 +2,70 @@ from flask import Blueprint
|
|||
from flask_restful import reqparse, Resource, Api
|
||||
from flask_apscheduler import APScheduler
|
||||
from units import token_auth,consul_kv
|
||||
from config import vendors
|
||||
import json
|
||||
from .jobs import deljob,addjob,runjob
|
||||
blueprint = Blueprint('exp',__name__)
|
||||
api = Api(blueprint)
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('query_dict',type=str)
|
||||
parser.add_argument('exp_config_dict',type=dict)
|
||||
|
||||
parser.add_argument('isnotify_dict',type=dict)
|
||||
|
||||
class Exp(Resource):
|
||||
#decorators = [token_auth.auth.login_required]
|
||||
def get(self,stype):
|
||||
if stype == 'list':
|
||||
exp_dict = consul_kv.get_kv_dict('ConsulManager/exp/list')
|
||||
exp_list = list(exp_dict.values())
|
||||
return {'code': 20000, 'exp_list': exp_list}
|
||||
switch = consul_kv.get_value(f'ConsulManager/exp/config').get('switch',False)
|
||||
if not switch:
|
||||
return({'code': 20000,'exp_list':[],'vendor_list':[],'account_list':[],'amount_list':[]})
|
||||
args = parser.parse_args()
|
||||
query_dict = json.loads(args['query_dict'])
|
||||
if query_dict['vendor'] != '':
|
||||
query_dict['vendor'] = {v : k for k, v in vendors.items()}[query_dict['vendor']]
|
||||
query_set = set({k:v for k,v in query_dict.items() if v != ''}.items())
|
||||
cloud_job_list = consul_kv.get_keys_list('ConsulManager/jobs')
|
||||
cloud_list = [i for i in cloud_job_list if i.endswith('/group')]
|
||||
exp_dict = consul_kv.get_kv_dict(f'ConsulManager/exp/lists')
|
||||
exp_list = []
|
||||
amount_list = []
|
||||
for i in cloud_list:
|
||||
vendor,account = i.split('/')[2:4]
|
||||
cloud_info_dict = {'vendor':vendor,'account':account}
|
||||
if query_set.issubset(cloud_info_dict.items()):
|
||||
pass
|
||||
else:
|
||||
continue
|
||||
amount = consul_kv.get_value(f'ConsulManager/exp/lists/{vendor}/{account}/amount')['amount']
|
||||
amount_list.append({'vendor':vendors[vendor],'account':account,'amount':amount})
|
||||
exp_dict = consul_kv.get_value(f'ConsulManager/exp/lists/{vendor}/{account}/exp')
|
||||
for k,v in exp_dict.items():
|
||||
isnotify = consul_kv.get_value(f"ConsulManager/exp/isnotify/{vendor}/{account}/{v['notify_id']}").get('isnotify',True)
|
||||
exp_list.append({'vendor':vendors[vendor],'account':account,'id':k,'Region':v['Region'],
|
||||
'Product':v['Product'],'Name':v.get('Name','Null'),'EndTime':v['EndTime'],
|
||||
'Ptype':v['Ptype'].replace('hws.resource.type.',''),
|
||||
'notify_id': v['notify_id'],'isnotify':isnotify})
|
||||
vendor_list = sorted(list(set([i['vendor'] for i in exp_list])))
|
||||
account_list = sorted(list(set([i['account'] for i in exp_list])))
|
||||
return {'code': 20000,'exp_list':exp_list,'vendor_list':vendor_list,'account_list':account_list,'amount_list':amount_list}
|
||||
if stype == 'config':
|
||||
exp_config = consul_kv.get_value('ConsulManager/exp/switch')
|
||||
exp_config = consul_kv.get_value('ConsulManager/exp/config')
|
||||
return {'code': 20000, 'exp_config': exp_config}
|
||||
def post(self,stype):
|
||||
if stype == 'isnotify':
|
||||
args = parser.parse_args()
|
||||
isnotify_dict = args['isnotify_dict']
|
||||
vendor = {v : k for k, v in vendors.items()}[isnotify_dict['vendor']]
|
||||
account = isnotify_dict['account']
|
||||
notify_id = isnotify_dict['notify_id']
|
||||
isnotify = isnotify_dict['isnotify']
|
||||
if not isnotify:
|
||||
consul_kv.put_kv(f'ConsulManager/exp/isnotify/{vendor}/{account}/{notify_id}',{'isnotify':isnotify})
|
||||
return {'code': 20000, 'data': '此条资源告警关闭!', 'type': 'warning'}
|
||||
else:
|
||||
consul_kv.del_key(f'ConsulManager/exp/isnotify/{vendor}/{account}/{notify_id}')
|
||||
return {'code': 20000, 'data': '此条资源告警开启!', 'type': 'success'}
|
||||
if stype == 'config':
|
||||
args = parser.parse_args()
|
||||
exp_config_dict = args['exp_config_dict']
|
||||
|
@ -50,12 +95,4 @@ class Exp(Resource):
|
|||
consul_kv.del_key_all('ConsulManager/exp/jobs/')
|
||||
consul_kv.del_key_all('ConsulManager/exp/lists/')
|
||||
return {'code': 20000, 'data': '到期日与余额采集功能关闭!'}
|
||||
if stype == 'run':
|
||||
exp_config_dict = consul_kv.get_value('ConsulManager/exp/switch')
|
||||
if exp_config_dict['switch']:
|
||||
consul_kv.del_key('ConsulManager/exp/list/0')
|
||||
runjob('exp_list')
|
||||
return {'code': 20000, 'data': '漏洞采集通知执行成功!'}
|
||||
else:
|
||||
return {'code': 50000, 'data': '漏洞采集功能未开启!'}
|
||||
api.add_resource(Exp, '/api/exp/<stype>')
|
||||
|
|
|
@ -100,6 +100,21 @@ class Jobs(Resource):
|
|||
else:
|
||||
Scheduler.remove_job(proj_job_id)
|
||||
Scheduler.remove_job(ecs_job_id)
|
||||
exp = consul_kv.get_value(f'ConsulManager/exp/config')
|
||||
switch = exp.get('switch',False)
|
||||
if switch:
|
||||
vendor = job_dict['vendor']
|
||||
account = job_dict['account']
|
||||
exp_job_id = f'{vendor}/{account}/exp'
|
||||
exp_job_func = f'__main__:{vendor}.exp'
|
||||
exp_job_args = [account,exp['collect_days'],exp['notify_days'],exp['notify_amount']]
|
||||
exp_job_interval = 60
|
||||
Scheduler.add_job(id=exp_job_id, func=exp_job_func, args=exp_job_args, trigger='interval',
|
||||
minutes=exp_job_interval, replace_existing=True)
|
||||
exp_job_dict = {'id':exp_job_id,'func':exp_job_func,'args':exp_job_args,
|
||||
'minutes':exp_job_interval,'trigger': 'interval','replace_existing': True}
|
||||
consul_kv.put_kv(f'ConsulManager/exp/jobs/{vendor}/{account}',exp_job_dict)
|
||||
runjob(exp_job_id)
|
||||
return {'code': record_dict['status'], 'data': f"{record_dict['update']}:{record_dict['msg']}"}
|
||||
elif job_status == 'update':
|
||||
jobid = job_dict['jobid']
|
||||
|
@ -119,6 +134,11 @@ class Jobs(Resource):
|
|||
job_id = args['job_id']
|
||||
Scheduler.remove_job(job_id)
|
||||
del_job = consul_kv.del_key(f'ConsulManager/jobs/{job_id}')
|
||||
if '/group' in job_id and consul_kv.get_value(f'ConsulManager/exp/config').get('switch',False):
|
||||
job_id = job_id.replace('/group','/exp')
|
||||
Scheduler.remove_job(job_id)
|
||||
del_job = consul_kv.del_key(f"ConsulManager/exp/jobs/{job_id.replace('/exp','')}")
|
||||
consul_kv.del_key_all(f"ConsulManager/exp/lists/{job_id.replace('/exp','')}")
|
||||
return {'code': 20000, 'data': '删除成功!'}
|
||||
|
||||
api.add_resource(Jobs, '/api/jobs')
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import request from '@/utils/request-ops'
|
||||
|
||||
export function getExpList(query_dict) {
|
||||
return request({
|
||||
url: '/api/exp/list',
|
||||
method: 'get',
|
||||
params: { query_dict }
|
||||
})
|
||||
}
|
||||
export function getExpConfig() {
|
||||
return request({
|
||||
url: '/api/exp/config',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
export function postExpJob(exp_config_dict) {
|
||||
return request({
|
||||
url: '/api/exp/config',
|
||||
method: 'post',
|
||||
data: { exp_config_dict }
|
||||
})
|
||||
}
|
||||
|
||||
export function postExpIsnotify(isnotify_dict) {
|
||||
return request({
|
||||
url: '/api/exp/isnotify',
|
||||
method: 'post',
|
||||
data: { isnotify_dict }
|
||||
})
|
||||
}
|
|
@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => {
|
|||
})
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.VER = 'v0.6.5'
|
||||
Vue.prototype.VER = 'v0.7.0'
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
|
|
|
@ -86,8 +86,8 @@ export const constantRoutes = [
|
|||
path: '/nodes',
|
||||
component: Layout,
|
||||
redirect: '/nodes/jobs',
|
||||
name: 'Node 主机监控',
|
||||
meta: { title: 'Node 主机监控', icon: 'example' },
|
||||
name: '云资源监控',
|
||||
meta: { title: '云资源监控', icon: 'example' },
|
||||
children: [
|
||||
{
|
||||
path: 'jobs',
|
||||
|
@ -95,6 +95,12 @@ export const constantRoutes = [
|
|||
component: () => import('@/views/node-exporter/jobs'),
|
||||
meta: { title: '接入数据源', icon: 'el-icon-school' }
|
||||
},
|
||||
{
|
||||
path: 'exp',
|
||||
name: '余额与到期通知',
|
||||
component: () => import('@/views/node-exporter/exp'),
|
||||
meta: { title: '余额与到期通知', icon: 'el-icon-alarm-clock' }
|
||||
},
|
||||
{
|
||||
path: 'lists',
|
||||
name: '云主机列表',
|
||||
|
@ -131,8 +137,8 @@ export const constantRoutes = [
|
|||
path: '/blackbox',
|
||||
component: Layout,
|
||||
redirect: '/blackbox/index',
|
||||
name: 'Blackbox 站点监控',
|
||||
meta: { title: 'Blackbox 站点监控', icon: 'tree' },
|
||||
name: '站点与接口监控',
|
||||
meta: { title: '站点与接口监控', icon: 'tree' },
|
||||
children: [
|
||||
{
|
||||
path: 'index',
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
<el-link :underline="false" type="primary" icon="el-icon-star-on" href="https://github.com/starsliao/ConsulManager" target="_blank" class="dashboard-text">StarsL.cn</el-link>
|
||||
</el-badge>
|
||||
<el-timeline>
|
||||
<el-timeline-item timestamp="2022/7/3" placement="top">
|
||||
<el-card>
|
||||
<h4>v0.7.0</h4>
|
||||
<p><el-button type="warning" size="mini" icon="el-icon-star-off" circle />新增阿里云、华为云、腾讯云账户余额和资源到期前通知!</p>
|
||||
<p>可自定义到期前时长与通知余额。</p>
|
||||
<p>支持钉钉、企业微信、飞书通知。</p>
|
||||
</el-card>
|
||||
</el-timeline-item>
|
||||
<el-timeline-item timestamp="2022/6/23" placement="top">
|
||||
<el-card>
|
||||
<h4>v0.6.5</h4>
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-alert title="菜单只显示有到期资源的账户,余额可查询所有账户;单个资源的通知可独立关闭。【自动续费、到期转按需、到期不续费的资源不会采集】【腾讯云仅采集主机到期列表(未找到整体到期接口)】" type="error" close-text="朕知道了" />
|
||||
<el-select v-model="query.vendor" placeholder="云厂商" clearable style="width: 150px" class="filter-item" @change="fetchData(query)">
|
||||
<el-option v-for="item in vendor_list" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
<el-select v-model="query.account" placeholder="账户" clearable style="width: 150px" class="filter-item" @change="fetchData(query)">
|
||||
<el-option v-for="item in account_list" :key="item" :label="item" :value="item" />
|
||||
</el-select>
|
||||
<el-tooltip class="item" effect="light" content="查询所有" placement="top">
|
||||
<el-button class="filter-item" style="margin-left: 10px;" type="success" icon="el-icon-magic-stick" circle @click="resetData" />
|
||||
</el-tooltip>
|
||||
<el-button class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">配置余额与到期通知</el-button>
|
||||
<el-tooltip class="item" effect="light" content="根据菜单选择查询对应账户余额,菜单为空时,查询所有账户。" placement="top">
|
||||
<el-button class="filter-item" type="warning" icon="el-icon-data-line" @click="handleamount">查看余额</el-button>
|
||||
</el-tooltip>
|
||||
<el-dialog title="配置余额与到期通知" :visible.sync="dialogFormVisible" width="45%">
|
||||
<el-form ref="dataForm" :model="exp_config" label-position="right" label-width="auto" style="width: 90%; margin-left: 20px;">
|
||||
<el-form-item label="采集开关">
|
||||
<el-switch v-model="exp_config.switch" /><br>
|
||||
<font size="3px" color="#ff0000">
|
||||
<li>开启采集:每小时会自动采集一次余额与到期资源信息。</li>
|
||||
<li>开启通知:当余额或到期资源低于设定时,会立刻推送通知。</li>
|
||||
</font>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="自动采集">
|
||||
<el-input v-model="exp_config.collect_days" style="width: 220px;" type="number">
|
||||
<template slot="append">天内到期的资源</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="自动通知">
|
||||
<el-input v-model="exp_config.notify_days" style="width: 220px;" type="number">
|
||||
<template slot="append">天内到期的资源</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="余额低于">
|
||||
<el-input v-model="exp_config.notify_amount" style="width: 220px;" type="number">
|
||||
<template slot="append">元自动通知</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="钉钉通知">
|
||||
<el-switch v-model="exp_config.dingding" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch && exp_config.dingding" required label="机器人Webhook地址">
|
||||
<el-input v-model="exp_config.dingdingwh" type="textarea" autosize /><font size="3px" color="#ff0000">机器人安全设置的自定义关键词请设置为:<strong>资源告警</strong></font>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="企业微信通知">
|
||||
<el-switch v-model="exp_config.wecom" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch && exp_config.wecom" required label="机器人Webhook地址">
|
||||
<el-input v-model="exp_config.wecomwh" type="textarea" autosize />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch" label="飞书通知">
|
||||
<el-switch v-model="exp_config.feishu" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="exp_config.switch && exp_config.feishu" required label="机器人Webhook地址">
|
||||
<el-input v-model="exp_config.feishuwh" type="textarea" autosize /><font size="3px" color="#ff0000">机器人安全设置的自定义关键词请设置为:<strong>资源告警</strong></font>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogFormVisible = false">
|
||||
取消
|
||||
</el-button>
|
||||
<el-button type="primary" @click="createData">
|
||||
确认
|
||||
</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<el-table v-loading="listLoading" :data="exp_list" :default-sort="{ prop: 'EndTime', order: 'ascending' }" border fit highlight-current-row style="width: 100%;">
|
||||
<el-table-column type="index" align="center" />
|
||||
<el-table-column prop="vendor" label="云厂商" sortable align="center" width="90" />
|
||||
<el-table-column prop="account" label="账号" sortable align="center" width="100" />
|
||||
<el-table-column prop="Region" label="区域" sortable align="center" width="100" show-overflow-tooltip />
|
||||
<el-table-column prop="Ptype" label="类型" sortable align="center" width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="Product" label="产品" sortable align="center" width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="Name" label="名称" sortable align="center" show-overflow-tooltip />
|
||||
<el-table-column prop="id" label="实例ID" sortable align="center" show-overflow-tooltip />
|
||||
<el-table-column prop="EndTime" label="到期日" sortable align="center" width="100" />
|
||||
<el-table-column label="通知" align="center" width="60" class-name="small-padding fixed-width">
|
||||
<template slot-scope="{row}">
|
||||
<el-switch v-model="row.isnotify" active-color="#13ce66" @change="fetchNotify(row.vendor, row.account, row.notify_id, row.isnotify)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-dialog title="查询余额" :visible.sync="amountFormVisible" width="60%">
|
||||
<el-table v-loading="listLoading" :data="amount_list" height="540" :default-sort="{ prop: 'amount', order: 'ascending' }" border fit highlight-current-row style="width: 100%;">
|
||||
<el-table-column prop="vendor" label="云厂商" sortable align="center" />
|
||||
<el-table-column prop="account" label="账户" sortable align="center" />
|
||||
<el-table-column prop="amount" label="余额(元)" sortable align="center" />
|
||||
</el-table>
|
||||
</el-dialog>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getExpList, getExpConfig, postExpJob, postExpIsnotify } from '@/api/exp'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
listLoading: false,
|
||||
dialogFormVisible: false,
|
||||
query: { vendor: '', account: '' },
|
||||
exp_config: { switch: false, collect_days: 15, notify_days: 7, notify_amount: 1000, wecom: false, dingding: false, feishu: false, wecomwh: '', dingdingwh: '', feishuwh: '' },
|
||||
exp_list: [],
|
||||
vendor_list: [],
|
||||
account_list: [],
|
||||
amount_list: [],
|
||||
isnotify_dict: {},
|
||||
amountFormVisible: false
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.fetchData()
|
||||
},
|
||||
methods: {
|
||||
fetchNotify(vendor, account, notify_id, isnotify) {
|
||||
this.isnotify_dict = { vendor: vendor, account: account, notify_id: notify_id, isnotify: isnotify }
|
||||
postExpIsnotify(this.isnotify_dict).then(response => {
|
||||
this.$message({
|
||||
message: response.data,
|
||||
type: response.type
|
||||
})
|
||||
})
|
||||
},
|
||||
handleCreate() {
|
||||
this.listLoading = true
|
||||
getExpConfig().then(response => {
|
||||
if (Object.keys(response.exp_config).length !== 0) {
|
||||
this.exp_config = response.exp_config
|
||||
}
|
||||
this.listLoading = false
|
||||
this.dialogFormVisible = true
|
||||
})
|
||||
},
|
||||
resetData() {
|
||||
this.query = { vendor: '', account: '' }
|
||||
this.fetchData()
|
||||
},
|
||||
fetchData() {
|
||||
this.listLoading = true
|
||||
getExpList(this.query).then(response => {
|
||||
this.vendor_list = response.vendor_list
|
||||
this.account_list = response.account_list
|
||||
this.exp_list = response.exp_list
|
||||
this.amount_list = response.amount_list
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
createData() {
|
||||
this.$confirm('此操作将开启定时任务,并执行首次所有账号的余额与到期资源信息采集,根据设定进行通知,是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.dialogFormVisible = false
|
||||
this.listLoading = true
|
||||
this.exp_config.collect_days = this.exp_config.collect_days * 1
|
||||
this.exp_config.notify_days = this.exp_config.notify_days * 1
|
||||
this.exp_config.notify_amount = this.exp_config.notify_amount * 1
|
||||
postExpJob(this.exp_config).then(response => {
|
||||
this.fetchData()
|
||||
this.$message({
|
||||
message: response.data,
|
||||
type: 'success'
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch(() => {
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: '操作已取消'
|
||||
})
|
||||
})
|
||||
},
|
||||
handleamount() {
|
||||
this.amountFormVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue