Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Monitor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
Monitor
Commits
fecade06
Commit
fecade06
authored
Dec 19, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add address to MonitorItem.
parent
191dd3a8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
Lib.hs
src/Lib.hs
+18
-12
No files found.
src/Lib.hs
View file @
fecade06
{-# LANGUAGE LambdaCase #-}
module
Lib
(
someFunc
,
checkServerConn
...
...
@@ -19,21 +21,23 @@ webHook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f209b18-4e9b-48
type
WebHook
=
String
type
Msg
=
String
type
ServerAddr
=
String
data
MonitorItem
=
MI
{
url
::
String
,
status
::
Bool
,
lasttime
::
UTCTime
}
lasttime
::
UTCTime
,
server
::
String
}
hour
::
NominalDiffTime
hour
=
3600
defaultMI
::
WebHook
->
MonitorItem
defaultMI
wh
=
MI
wh
True
(
UTCTime
(
fromOrdinalDate
0
0
)
0
)
defaultMI
::
WebHook
->
ServerAddr
->
MonitorItem
defaultMI
wh
addr
=
MI
wh
True
(
UTCTime
(
fromOrdinalDate
0
0
)
0
)
addr
monitorUrls
::
[
MonitorItem
]
monitorUrls
=
[
defaultMI
"http://69.234.216.199:5001/ppt2newdraft"
defaultMI
"http://69.234.216.199:5001/ppt2newdraft"
"69.234.216.199"
]
cmdFactory
::
WebHook
->
Msg
->
String
...
...
@@ -48,11 +52,13 @@ cmdFactory wh msg =
"}"
++
"}'"
checkServerConn
::
IO
Bool
checkServerConn
=
system
"ping -q -c 1 -w 10 69.234.216.199"
>>=
\
c
ode
->
case
code
of
ExitSuccess
->
return
True
checkServerConn
::
ServerAddr
->
IO
Bool
checkServerConn
addr
=
system
(
"ping -q -c 1 -w "
++
addr
)
>>=
\
c
ase
{
ExitSuccess
->
return
True
;
_
->
return
False
}
onFailure
::
MonitorItem
->
IO
MonitorItem
onFailure
mi
=
do
...
...
@@ -72,14 +78,14 @@ onFailure mi = do
doNotify
::
IO
MonitorItem
doNotify
=
do
connected
<-
checkServerConn
connected
<-
checkServerConn
$
server
mi
let
cmd
=
if
connected
then
cmdFactory
webHook
(
"Fail to access api "
++
url
mi
)
else
cmdFactory
webHook
"Server (69.234.216.199) down"
current
<-
getCurrentTime
-- FIXME: system may failed need to check it's return code
system
cmd
>>
return
(
MI
(
url
mi
)
False
current
)
system
cmd
>>
return
(
MI
(
url
mi
)
False
current
(
server
mi
)
)
onSuccess
::
MonitorItem
->
IO
MonitorItem
onSuccess
mi
=
do
...
...
@@ -87,7 +93,7 @@ onSuccess mi = do
if
not
$
status
mi
then
do
let
cmd
=
cmdFactory
webHook
(
"Api has recovered: "
++
url
mi
)
system
cmd
>>
return
(
MI
(
url
mi
)
True
current
)
system
cmd
>>
return
(
MI
(
url
mi
)
True
current
(
server
mi
)
)
else
return
mi
checkUrl
::
MonitorItem
->
IO
MonitorItem
...
...
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