Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos.toolbox
Commits
e82f122c
Commit
e82f122c
authored
Dec 30, 2019
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise: Cleanup check_surykatka_json
parent
ded34b9c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
27 deletions
+42
-27
slapos/promise/plugin/check_surykatka_json.py
slapos/promise/plugin/check_surykatka_json.py
+42
-27
No files found.
slapos/promise/plugin/check_surykatka_json.py
View file @
e82f122c
...
@@ -15,12 +15,28 @@ class RunPromise(GenericPromise):
...
@@ -15,12 +15,28 @@ class RunPromise(GenericPromise):
super
(
RunPromise
,
self
).
__init__
(
config
)
super
(
RunPromise
,
self
).
__init__
(
config
)
# Set frequency compatible to default surykatka interval - 2 minutes
# Set frequency compatible to default surykatka interval - 2 minutes
self
.
setPeriodicity
(
float
(
self
.
getConfig
(
'frequency'
,
2
)))
self
.
setPeriodicity
(
float
(
self
.
getConfig
(
'frequency'
,
2
)))
self
.
error_list
=
[]
self
.
info_list
=
[]
def
appendError
(
self
,
message
):
self
.
error_list
.
append
(
message
)
def
appendInfo
(
self
,
message
):
self
.
info_list
.
append
(
message
)
def
emitLog
(
self
):
if
len
(
self
.
error_list
)
>
0
:
emit
=
self
.
logger
.
error
else
:
emit
=
self
.
logger
.
info
emit
(
' '
.
join
(
self
.
error_list
+
self
.
info_list
))
def
senseBotStatus
(
self
):
def
senseBotStatus
(
self
):
key
=
'bot_status'
key
=
'bot_status'
def
logError
(
msg
,
*
args
):
def
logError
(
msg
,
*
args
):
self
.
logger
.
error
(
key
+
': '
+
msg
,
*
args
)
self
.
appendError
(
key
+
': '
+
msg
%
args
)
if
key
not
in
self
.
surykatka_json
:
if
key
not
in
self
.
surykatka_json
:
logError
(
"%r not in %r"
,
key
,
self
.
json_file
)
logError
(
"%r not in %r"
,
key
,
self
.
json_file
)
...
@@ -46,15 +62,15 @@ class RunPromise(GenericPromise):
...
@@ -46,15 +62,15 @@ class RunPromise(GenericPromise):
last_bot_datetime
,
self
.
utcnow
)
last_bot_datetime
,
self
.
utcnow
)
return
return
self
.
logger
.
i
nfo
(
self
.
appendI
nfo
(
'%s: Last bot status from %s ok, UTC now is %s'
,
'%s: Last bot status from %s ok, UTC now is %s'
%
key
,
last_bot_datetime
,
self
.
utcnow
)
(
key
,
last_bot_datetime
,
self
.
utcnow
)
)
def
senseHttpQuery
(
self
):
def
senseHttpQuery
(
self
):
key
=
'http_query'
key
=
'http_query'
def
logError
(
msg
,
*
args
):
def
logError
(
msg
,
*
args
):
self
.
logger
.
error
(
key
+
': '
+
msg
,
*
args
)
self
.
appendError
(
key
+
': '
+
msg
%
args
)
if
key
not
in
self
.
surykatka_json
:
if
key
not
in
self
.
surykatka_json
:
logError
(
"%r not in %r"
,
key
,
self
.
json_file
)
logError
(
"%r not in %r"
,
key
,
self
.
json_file
)
...
@@ -84,13 +100,13 @@ class RunPromise(GenericPromise):
...
@@ -84,13 +100,13 @@ class RunPromise(GenericPromise):
logError
(
'Problem with %s: '
%
(
url
,)
+
', '
.
join
(
error_list
))
logError
(
'Problem with %s: '
%
(
url
,)
+
', '
.
join
(
error_list
))
return
return
if
len
(
ip_list
)
>
0
:
if
len
(
ip_list
)
>
0
:
self
.
logger
.
i
nfo
(
self
.
appendI
nfo
(
'%s: %s replied correctly with status code %s on ip list %s'
,
'%s: %s replied correctly with status code %s on ip list %s'
%
key
,
url
,
status_code
,
' '
.
join
(
ip_list
))
(
key
,
url
,
status_code
,
' '
.
join
(
ip_list
)
))
else
:
else
:
self
.
logger
.
i
nfo
(
self
.
appendI
nfo
(
'%s: %s replied correctly with status code %s'
,
'%s: %s replied correctly with status code %s'
%
key
,
url
,
status_code
)
(
key
,
url
,
status_code
)
)
def
sense
(
self
):
def
sense
(
self
):
"""
"""
...
@@ -105,23 +121,22 @@ class RunPromise(GenericPromise):
...
@@ -105,23 +121,22 @@ class RunPromise(GenericPromise):
self
.
json_file
=
self
.
getConfig
(
'json-file'
,
''
)
self
.
json_file
=
self
.
getConfig
(
'json-file'
,
''
)
if
not
os
.
path
.
exists
(
self
.
json_file
):
if
not
os
.
path
.
exists
(
self
.
json_file
):
self
.
logger
.
error
(
'File %r does not exists'
,
self
.
json_file
)
self
.
appendError
(
'File %r does not exists'
%
self
.
json_file
)
return
with
open
(
self
.
json_file
)
as
fh
:
try
:
self
.
surykatka_json
=
json
.
load
(
fh
)
except
Exception
:
self
.
logger
.
error
(
"Problem loading JSON from %r"
,
self
.
json_file
)
return
report
=
self
.
getConfig
(
'report'
)
if
report
==
'bot_status'
:
return
self
.
senseBotStatus
()
elif
report
==
'http_query'
:
return
self
.
senseHttpQuery
()
else
:
else
:
self
.
logger
.
error
(
"Report %r is not supported"
,
report
)
with
open
(
self
.
json_file
)
as
fh
:
return
try
:
self
.
surykatka_json
=
json
.
load
(
fh
)
except
Exception
:
self
.
appendError
(
"Problem loading JSON from %r"
%
self
.
json_file
)
else
:
report
=
self
.
getConfig
(
'report'
)
if
report
==
'bot_status'
:
self
.
senseBotStatus
()
elif
report
==
'http_query'
:
self
.
senseHttpQuery
()
else
:
self
.
appendError
(
"Report %r is not supported"
%
report
)
self
.
emitLog
()
def
anomaly
(
self
):
def
anomaly
(
self
):
return
self
.
_test
(
result_count
=
3
,
failure_amount
=
3
)
return
self
.
_test
(
result_count
=
3
,
failure_amount
=
3
)
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