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
Iliya Manolov
slapos.toolbox
Commits
43fc2f2e
Commit
43fc2f2e
authored
Mar 21, 2017
by
Rafael Monnerat
👻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
c41bd8a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
slapos/promise/check_error_on_apache_log/__init__.py
slapos/promise/check_error_on_apache_log/__init__.py
+72
-0
slapos/promise/is_icmp_packet_lost/__init__.py
slapos/promise/is_icmp_packet_lost/__init__.py
+0
-0
slapos/test/promise/__init__.py
slapos/test/promise/__init__.py
+0
-0
No files found.
slapos/promise/check_error_on_apache_log/__init__.py
0 → 100644
View file @
43fc2f2e
import
re
import
time
import
sys
import
gzip
r
=
re
.
compile
(
"^(
\
[[^
\
]]+
\
]) (
\
[[^
\
]]+
\
]) (.*)$"
)
log_file
=
sys
.
argv
[
1
]
MAXIMUM_DELAY
=
0
VERBOSE
=
0
BLOCK_SIZE
=
4096
error_amount
=
0
no_route_error
=
0
network_is_unreacheable
=
0
timeout
=
0
def
test
(
log_file
,
maximum_delay
):
with
open
(
log_file
)
as
f
:
f
.
seek
(
0
,
2
)
block_end_byte
=
f
.
tell
()
if
not
BLOCK_SIZE
:
BLOCK_SIZE
=
block_end_byte
f
.
seek
(
-
min
(
block_end_byte
,
BLOCK_SIZE
),
1
)
data
=
f
.
read
()
for
line
in
reversed
(
data
.
splitlines
()):
m
=
r
.
match
(
line
)
if
m
is
None
:
continue
dt
,
level
,
msg
=
m
.
groups
()
t
=
time
.
strptime
(
dt
[
1
:
-
1
],
"%a %b %d %H:%M:%S %Y"
)
if
maximum_delay
and
(
time
.
time
()
-
time
.
mktime
(
t
))
>
maximum_delay
:
# no result in the latest hour
break
if
level
!=
"[error]"
:
continue
# Classify the types of errors
if
"(113)No route to host"
in
msg
:
no_route_error
+=
1
elif
"(101)Network is unreachable"
in
msg
:
network_is_unreacheable
+=
1
elif
"(110)Connection timed out"
in
msg
:
timeout
+=
1
error_amount
+=
1
if
error_amount
:
return
"ERROR=%s (NOTROUTE=%s, UNREACHEABLENET=%s, TIMEOUT=%s)"
%
(
error_amount
,
no_route_error
,
network_is_unreacheable
,
timeout
)
return
"OK"
def
main
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-l"
,
"--log-file"
,
metavar
=
"LOG_FILE"
)
parser
.
add_argument
(
"-d"
,
"--maximun-delay"
,
metavar
=
"MAXIMUM_DELAY"
,
default
=
0
)
args
=
parser
.
parse_args
()
log_file
=
args
.
log_file
result
=
test
(
args
.
log_file
,
args
.
maximum_delay
)
print
result
if
result
!=
"OK"
:
sys
.
exit
(
1
)
slapos/promise/is_icmp_packet_lost/__init__.py
0 → 100644
View file @
43fc2f2e
slapos/test/promise/__init__.py
0 → 100644
View file @
43fc2f2e
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