Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
perun-proxy-utils
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Perun
Perun ProxyIdP
perun-proxy-utils
Commits
99503bef
Verified
Commit
99503bef
authored
8 months ago
by
Jan Pavlíček
Committed by
Jan Pavlíček
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: script for psql test before migration
parent
9c2c7455
No related branches found
No related tags found
No related merge requests found
Pipeline
#531235
failed
7 months ago
Stage: .pre
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
perun/proxy/utils/run_probes_jpmu_test.py
+113
-0
113 additions, 0 deletions
perun/proxy/utils/run_probes_jpmu_test.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
114 additions
and
0 deletions
perun/proxy/utils/run_probes_jpmu_test.py
0 → 100644
+
113
−
0
View file @
99503bef
#!/usr/bin/python3
import
re
import
subprocess
import
sys
import
time
from
datetime
import
datetime
from
threading
import
Thread
import
yaml
def
open_file
(
filepath
):
try
:
with
open
(
filepath
)
as
f
:
return
f
.
read
()
except
OSError
as
e
:
print
(
f
"
Cannot open config with path:
{
filepath
}
, error:
{
e
.
strerror
}
"
,
file
=
sys
.
stderr
,
)
sys
.
exit
(
2
)
def
get_metrics_and_new_output
(
output
):
"""
Parses metrics from output, metrics must be in one of (or combination of)
the following formats:
1) |metric1=val;val;;;|metric2=val (delimiter |)
2) |metric1=val;metric2=val2; (delimiter ;)
3) |metric1=val metric2=val2 (delimiter
'
'
)
Values must be int or float
"""
metrics_pattern
=
r
"
(\s\|\s|\|)(\w+=[\d.;]+(;|\s|$))+
"
match
=
re
.
search
(
metrics_pattern
,
output
)
if
match
:
output
=
re
.
sub
(
metrics_pattern
,
"
"
,
output
)
metrics
=
re
.
sub
(
r
"
\s
"
,
""
,
match
.
group
())
metrics
=
re
.
sub
(
r
"
^\|
"
,
""
,
metrics
)
metrics
=
re
.
sub
(
r
"
(\d;?)([a-zA-Z])
"
,
r
"
\1|\2
"
,
metrics
)
return
metrics
.
strip
(),
output
.
strip
()
return
None
,
output
def
run_probe
(
probe_name
,
command
,
timeout
,
identifier
):
"""
Runs nagios monitoring probe and prints output in following formats:
1) return_code probe_name metrics output
2) return_code probe_name - output
metrics output format:
metric1=val;|metric2=val2|metric3=val3;val3;;;|metric4=val4
"""
exec_time
=
datetime
.
now
()
try
:
result
=
subprocess
.
run
(
command
,
text
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
timeout
=
timeout
,
)
except
subprocess
.
TimeoutExpired
:
print
(
f
"
exectime:
{
exec_time
}
- 3
{
probe_name
}
- probe TIMED OUT after
{
timeout
}
s
"
)
return
3
output
=
re
.
sub
(
"
[
\t\n
]+
"
,
"
"
,
result
.
stdout
)
search
=
re
.
search
(
r
"
- .*
"
,
output
)
if
search
:
output
=
re
.
sub
(
r
"
^ -
"
,
""
,
search
.
group
())
metrics
,
new_output
=
get_metrics_and_new_output
(
output
)
if
metrics
:
print
(
f
"
exectime:
{
exec_time
}
-
{
result
.
returncode
}
{
probe_name
}
{
metrics
}
{
new_output
}
"
)
else
:
print
(
f
"
exectime:
{
exec_time
}
-
{
result
.
returncode
}
{
probe_name
}
-
{
output
}
"
)
return
result
.
returncode
def
main
():
config_filepath
=
"
/etc/run_probes_cfg.yaml
"
config
=
yaml
.
safe_load
(
open_file
(
config_filepath
))
if
not
config
:
return
global_timeout
=
config
[
"
default_timeout
"
]
for
_
,
options
in
config
[
"
checks
"
].
items
():
module
=
options
[
"
module
"
]
for
i
in
range
(
30
):
for
name
,
args
in
options
.
get
(
"
runs
"
).
items
():
command
=
[
"
python3
"
,
"
-m
"
,
module
]
timeout
=
global_timeout
if
args
is
not
None
:
for
arg_name
,
arg_val
in
args
.
items
():
if
arg_name
==
"
timeout
"
:
timeout
=
arg_val
continue
if
len
(
arg_name
)
==
1
:
arg_name
=
"
-
"
+
arg_name
else
:
arg_name
=
"
--
"
+
arg_name
if
arg_val
is
True
:
arg_val
=
"
true
"
elif
arg_val
is
False
:
arg_val
=
"
false
"
command
.
append
(
arg_name
)
if
arg_val
is
not
None
:
command
.
append
(
str
(
arg_val
))
Thread
(
target
=
run_probe
,
args
=
[
name
,
command
,
timeout
,
i
]).
start
()
time
.
sleep
(
5
)
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
99503bef
...
...
@@ -38,6 +38,7 @@ setuptools.setup(
entry_points
=
{
"
console_scripts
"
:
[
"
run_probes=perun.proxy.utils.run_probes:main
"
,
"
run_probes_jpmu_test=perun.proxy.utils.run_probes_jpmu_test:main
"
,
"
check_custom_command=perun.proxy.utils.nagios.check_custom_command:main
"
,
"
check_dockers=perun.proxy.utils.nagios.check_dockers:main
"
,
"
check_exabgp_propagation=
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment