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
bd477469
Commit
bd477469
authored
Dec 16, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check server network status via icmp once api down.
parent
b6424823
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
Lib.hs
src/Lib.hs
+16
-3
stack.yaml
stack.yaml
+3
-1
Spec.hs
test/Spec.hs
+5
-1
No files found.
src/Lib.hs
View file @
bd477469
module
Lib
(
someFunc
(
someFunc
,
checkServerConn
)
where
import
Data.Time.Clock
...
...
@@ -7,6 +8,7 @@ import Data.Time.Clock
import
Data.Time.Calendar.OrdinalDate
import
Network.HTTP
import
System.Process
import
System.Exit
(
ExitCode
(
ExitSuccess
))
import
Control.Monad
import
Control.Exception
import
Control.Concurrent
(
threadDelay
)
...
...
@@ -46,6 +48,12 @@ buildCMD wh msg =
"}"
++
"}'"
checkServerConn
::
IO
Bool
checkServerConn
=
system
"ping -q -c 1 -w 10 69.234.216.199"
>>=
\
code
->
case
code
of
ExitSuccess
->
return
True
_
->
return
False
onFailure
::
MonitorItem
->
IO
MonitorItem
onFailure
mi
=
do
needNotify
<-
notifyRequire
...
...
@@ -63,9 +71,14 @@ onFailure mi = do
doNotify
::
IO
MonitorItem
doNotify
=
do
let
cmd
=
buildCMD
webHook
(
"Fail to access api "
++
url
mi
)
connected
<-
checkServerConn
let
cmd
=
if
connected
then
buildCMD
webHook
(
"Fail to access api "
++
url
mi
)
else
buildCMD
webHook
"Server (69.234.216.199) down"
current
<-
getCurrentTime
-- FIXME: system may failed need to check it's return code
-- FIXME: system may failed need to check it's return code
system
cmd
>>
return
(
MI
(
url
mi
)
False
current
)
onSuccess
::
MonitorItem
->
IO
MonitorItem
...
...
stack.yaml
View file @
bd477469
...
...
@@ -31,6 +31,7 @@ resolver:
# - wai
packages
:
-
.
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
...
...
@@ -40,7 +41,8 @@ packages:
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
extra-deps
:
[
"
Cabal-syntax-3.8.1.0@sha256:4936765e9a7a8ecbf8fdbe9067f6d972bc0299220063abb2632a9950af64b966,7619"
]
extra-deps
:
-
Cabal-syntax-3.8.1.0@sha256:4936765e9a7a8ecbf8fdbe9067f6d972bc0299220063abb2632a9950af64b966,7619
# Override default flag values for local packages and extra-deps
# flags: {}
...
...
test/Spec.hs
View file @
bd477469
import
Lib
main
::
IO
()
main
=
putStrLn
"Test suite not yet implemented"
main
=
do
connected
<-
checkServerConn
print
connected
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