Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
tas_monitor
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bb59a6d5
authored
Feb 25, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新短信报警
parent
839edf84
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletions
utils/robots.py
utils/robots.py
View file @
bb59a6d5
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
import
hashlib
import
time
import
time
import
requests
import
requests
import
re
dd_robot_api
=
' https://oapi.dingtalk.com/robot/send?access_token='
dd_robot_api
=
' https://oapi.dingtalk.com/robot/send?access_token='
tom
=
'c19beeab837f5c6e019e7fc602d470704d634ae33510f40fb0e903cde215fb24'
tom
=
'c19beeab837f5c6e019e7fc602d470704d634ae33510f40fb0e903cde215fb24'
filter_plat_kw
=
[
'pc'
,
'bkc'
]
wrong_ratio_pat
=
re
.
compile
(
r'\d\d\.\d\d'
)
msgapi_url
=
'http://api.ichunt.com/msg/sendMessageByAuto'
def
parse_msg
(
msg
):
lines
=
msg
.
split
(
'
\n
'
)
msgs
=
[]
for
line
in
lines
:
if
'错误率'
in
line
and
float
(
wrong_ratio_pat
.
findall
(
line
)[
0
])
>=
80
:
msgs
.
append
(
line
)
return
msgs
def
dd_send_msg
(
msg
,
robot
=
tom
):
def
dd_send_msg
(
msg
,
robot
=
tom
):
...
@@ -17,6 +31,25 @@ def dd_send_msg(msg, robot=tom):
...
@@ -17,6 +31,25 @@ def dd_send_msg(msg, robot=tom):
requests
.
post
(
dd_robot_api
+
robot
,
json
=
data
)
requests
.
post
(
dd_robot_api
+
robot
,
json
=
data
)
time
.
sleep
(
5
)
time
.
sleep
(
5
)
phone_msgs
=
parse_msg
(
msg
)
if
not
phone_msgs
:
return
content
=
'
\\
n'
.
join
(
phone_msgs
)
cur_time
=
int
(
time
.
time
())
m
=
hashlib
.
md5
()
d
=
hashlib
.
md5
()
m
.
update
(
str
(
cur_time
)
.
encode
())
d
.
update
((
m
.
hexdigest
()
+
'fh6y5t4rr351d2c3bryi'
)
.
encode
())
data
=
{
'data'
:
"{
\"
content
\"
:
\"
%
s
\"
}"
%
(
content
),
'touser'
:
"[
\"
15113123231
\"
,
\"
18594239421
\"
]"
,
'keyword'
:
'monitoring-py'
,
'fromuser'
:
''
,
'wechat_data'
:
''
,
'is_oversea'
:
''
,
'channel_type'
:
''
,
'is_ignore'
:
''
,
'ex_int'
:
''
,
'ex_str'
:
''
,
'k2'
:
d
.
hexdigest
(),
'k1'
:
str
(
cur_time
)}
requests
.
post
(
msgapi_url
,
data
=
data
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
dd_send_msg
(
'喂喂 你发的太多了!'
)
dd_send_msg
(
'''TAS任务监控预警 过去90分钟内:
任务:muguf 未知 平均错误率为64.30
%
任务:pc 平台比价 平均错误率为97.99
%
任务:bkc buerklin新品采集 平均错误率为72.97
%
'''
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment