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
26da3f35
Verified
Commit
26da3f35
authored
1 year ago
by
Jan Pavlíček
Committed by
Jan Pavlíček
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: run_probes outputs in check_mk format with metrics to graphs
parent
9d4fa777
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!53
feat: run_probes outputs in check_mk format with metrics to graphs
Pipeline
#388384
passed
1 year ago
Stage: .pre
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
perun/proxy/utils/run_probes.py
+34
-2
34 additions, 2 deletions
perun/proxy/utils/run_probes.py
with
34 additions
and
2 deletions
perun/proxy/utils/run_probes.py
+
34
−
2
View file @
26da3f35
...
@@ -19,16 +19,48 @@ def open_file(filepath):
...
@@ -19,16 +19,48 @@ def open_file(filepath):
sys
.
exit
(
2
)
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
):
def
run_probe
(
probe_name
,
command
):
"""
Runs nagios monitoring probe and prints output in following format:
return_code metrics output
metrics output format:
metric1=val;|metric2=val2|metric3=val3;val3;;;|metric4=val4
"""
result
=
subprocess
.
run
(
result
=
subprocess
.
run
(
command
,
text
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
command
,
text
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
)
output
=
re
.
sub
(
"
[
\t\n
]+
"
,
"
"
,
result
.
stdout
)
output
=
re
.
sub
(
"
[
\t\n
]+
"
,
"
"
,
result
.
stdout
)
search
=
re
.
search
(
r
"
- .*
"
,
output
)
search
=
re
.
search
(
r
"
- .*
"
,
output
)
if
search
:
if
search
:
print
(
f
"
{
result
.
returncode
}
{
probe_name
}{
search
.
group
()
}
"
)
output
=
re
.
sub
(
r
"
^ -
"
,
""
,
search
.
group
())
metrics
,
new_output
=
get_metrics_and_new_output
(
output
)
if
metrics
:
print
(
f
"
{
result
.
returncode
}
{
probe_name
}
{
metrics
}
{
new_output
}
"
)
else
:
else
:
print
(
f
"
{
result
.
returncode
}
{
probe_name
}
-
{
output
}
"
)
print
(
f
"
{
result
.
returncode
}
{
probe_name
}
{
output
}
"
)
return
result
.
returncode
return
result
.
returncode
...
...
This diff is collapsed.
Click to expand it.
Perun-GitLab Service Account
@9045464
mentioned in commit
b887adfa
·
1 year ago
mentioned in commit
b887adfa
mentioned in commit b887adfa2a27a8719fc88d67e8772d0b2e0863ed
Toggle commit list
Jiří Prokop
@525248
mentioned in commit
00bdae83
·
1 year ago
mentioned in commit
00bdae83
mentioned in commit 00bdae8368f0dcff794c01915aece0a466bf5225
Toggle commit list
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