mirror of https://github.com/openspug/spug
A 监控中心新增支持企业微信告警
parent
fcfc87603d
commit
028fd2532b
|
@ -13,6 +13,7 @@ class Alarm(models.Model, ModelMixin):
|
|||
('2', '短信'),
|
||||
('3', '钉钉'),
|
||||
('4', '邮件'),
|
||||
('5', '企业微信'),
|
||||
)
|
||||
STATUS = (
|
||||
('1', '报警发生'),
|
||||
|
@ -67,6 +68,7 @@ class Contact(models.Model, ModelMixin):
|
|||
email = models.CharField(max_length=255, null=True)
|
||||
ding = models.CharField(max_length=255, null=True)
|
||||
wx_token = models.CharField(max_length=255, null=True)
|
||||
qy_wx = models.CharField(max_length=255, null=True)
|
||||
|
||||
created_at = models.CharField(max_length=20, default=human_datetime)
|
||||
created_by = models.ForeignKey(User, models.PROTECT, related_name='+')
|
||||
|
|
|
@ -60,6 +60,7 @@ class ContactView(View):
|
|||
Argument('email', required=False),
|
||||
Argument('ding', required=False),
|
||||
Argument('wx_token', required=False),
|
||||
Argument('qy_wx', required=False),
|
||||
).parse(request.body)
|
||||
if error is None:
|
||||
if form.id:
|
||||
|
|
|
@ -53,6 +53,8 @@ class Scheduler:
|
|||
spug.notify_by_dd(event, obj)
|
||||
elif mode == '4':
|
||||
spug.notify_by_email(event, obj)
|
||||
elif mode == '5':
|
||||
spug.notify_by_qy_wx(event, obj)
|
||||
|
||||
def _handle_notify(self, obj, is_notified, out):
|
||||
if obj.latest_status == 0:
|
||||
|
|
|
@ -89,3 +89,28 @@ def notify_by_dd(event, obj):
|
|||
requests.post(url, json=data)
|
||||
else:
|
||||
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未找到可用的通知对象,请确保设置了相关报警联系人的钉钉。')
|
||||
|
||||
|
||||
def notify_by_qy_wx(event, obj):
|
||||
_, u_ids = _parse_args(obj.grp)
|
||||
users = set(x.qy_wx for x in Contact.objects.filter(id__in=u_ids, qy_wx__isnull=False))
|
||||
if users:
|
||||
color, title = ('warning', '监控告警通知') if event == '1' else ('info', '告警恢复通知')
|
||||
texts = [
|
||||
f'## {title}',
|
||||
f'**告警名称:** <font color="{color}">{obj.name}</font> ',
|
||||
f'**告警时间:** {human_datetime()} ',
|
||||
f'**告警描述:** {obj.out} ',
|
||||
]
|
||||
if event == '2':
|
||||
texts.append(f'**持续时间:** {obj.duration} ')
|
||||
data = {
|
||||
'msgtype': 'markdown',
|
||||
'markdown': {
|
||||
'content': '\n'.join(texts) + '\n> 来自 Spug运维平台'
|
||||
}
|
||||
}
|
||||
for url in users:
|
||||
requests.post(url, json=data)
|
||||
else:
|
||||
Notify.make_notify(notify_source, '1', '发送报警信息失败', '未找到可用的通知对象,请确保设置了相关报警联系人的企业微信。')
|
||||
|
|
|
@ -65,7 +65,12 @@ class ComForm extends React.Component {
|
|||
</Form.Item>
|
||||
<Form.Item label="钉钉">
|
||||
{getFieldDecorator('ding', {initialValue: info['ding']})(
|
||||
<Input placeholder="请输入钉钉机器人地址"/>
|
||||
<Input placeholder="请输入钉钉机器人完整地址"/>
|
||||
)}
|
||||
</Form.Item>
|
||||
<Form.Item label="企业微信">
|
||||
{getFieldDecorator('qy_wx', {initialValue: info['qy_wx']})(
|
||||
<Input placeholder="请输入企业微信机器人完整地址"/>
|
||||
)}
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
|
|
@ -36,6 +36,10 @@ class ComTable extends React.Component {
|
|||
title: '钉钉',
|
||||
dataIndex: 'ding',
|
||||
ellipsis: true
|
||||
}, {
|
||||
title: '企业微信',
|
||||
dataIndex: 'qy_wx',
|
||||
ellipsis: true
|
||||
}, {
|
||||
title: '操作',
|
||||
render: info => (
|
||||
|
|
|
@ -29,7 +29,9 @@ class ComForm extends React.Component {
|
|||
{label: '微信', 'value': '1'},
|
||||
{label: '短信', 'value': '2', disabled: true},
|
||||
{label: '钉钉', 'value': '3'},
|
||||
{label: '邮件', 'value': '4'}]
|
||||
{label: '邮件', 'value': '4'},
|
||||
{label: '企业微信', 'value': '5'},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +167,8 @@ class ComForm extends React.Component {
|
|||
</Form.Item>
|
||||
<Form.Item required label="脚本内容" style={this.getStyle('4')}
|
||||
extra={<LinkButton onClick={() => this.setState({showTmp: true})}>从模板添加</LinkButton>}>
|
||||
<ACEditor mode="sh" value={extra['4']} height="200px" onChange={e => this.handleExtra('4', cleanCommand(e))}/>
|
||||
<ACEditor mode="sh" value={extra['4']} height="200px"
|
||||
onChange={e => this.handleExtra('4', cleanCommand(e))}/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注信息">
|
||||
{getFieldDecorator('desc', {initialValue: info['desc']})(
|
||||
|
|
Loading…
Reference in New Issue