Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
My Nagios Plugin Wrapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shore
My Nagios Plugin Wrapper
Commits
e655f672
Commit
e655f672
authored
3 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Parse output.
The tests aren't the greatest and binary is broken but I think the parsing works.
parent
8f482983
No related branches found
No related tags found
No related merge requests found
Pipeline
#1968
failed
3 years ago
Stage: .pre
Stage: build
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mnpw/nagios.py
+32
-4
32 additions, 4 deletions
mnpw/nagios.py
tests/test_nagios.py
+2
-1
2 additions, 1 deletion
tests/test_nagios.py
with
34 additions
and
5 deletions
mnpw/nagios.py
+
32
−
4
View file @
e655f672
...
@@ -93,8 +93,7 @@ class Check:
...
@@ -93,8 +93,7 @@ class Check:
ExitCode
=
None
ExitCode
=
None
Output
=
None
Output
=
None
PerfData
=
[]
PerfData
=
[]
LongOutput
=
None
AdditionalOutput
=
[]
AdditionalOutput
=
None
stderr
=
None
stderr
=
None
_stdout
=
None
_stdout
=
None
...
@@ -107,11 +106,40 @@ class Check:
...
@@ -107,11 +106,40 @@ class Check:
def
_parse_output
(
self
):
def
_parse_output
(
self
):
"""
Parses the plugin output to get the output, perf data and long
"""
Parses the plugin output to get the output, perf data and long
output. Can be run after the plugin has run and finished
output.
successfully.
"""
Can only be run after the plugin has run and finished successfully.
"""
if
self
.
ExitCode
is
None
:
if
self
.
ExitCode
is
None
:
raise
RuntimeError
(
"
Check hasn
'
t run yet.
"
)
raise
RuntimeError
(
"
Check hasn
'
t run yet.
"
)
lines
=
self
.
_stdout
.
splitlines
()
if
not
lines
:
logging
.
info
(
"
Emptry stdout.
"
)
return
if
"
|
"
in
lines
[
0
]:
p1
,
p2
=
lines
[
0
].
split
(
"
|
"
)
self
.
Output
=
p1
.
strip
()
self
.
PerfData
.
append
(
PerfData
(
p2
))
else
:
self
.
Output
=
lines
[
0
].
strip
()
if
len
(
lines
)
==
1
:
return
processing_perfdata
=
False
for
line
in
lines
[
1
:]:
if
processing_perfdata
:
self
.
PerfData
.
append
(
PerfData
(
line
))
else
:
if
"
|
"
in
line
:
self
.
AdditionalOutput
.
append
(
line
.
split
(
"
|
"
)[
0
].
strip
())
processing_perfdata
=
True
self
.
PerfData
.
append
(
PerfData
(
line
.
split
(
"
|
"
)[
1
]))
else
:
self
.
AdditionalOutput
.
append
(
line
)
def
run
(
self
,
timeout
=
DEFAULT_TIMEOUT
):
def
run
(
self
,
timeout
=
DEFAULT_TIMEOUT
):
"""
Run the check (if it
'
s hasn
'
t run yet).
"""
"""
Run the check (if it
'
s hasn
'
t run yet).
"""
if
self
.
ExitCode
is
not
None
:
if
self
.
ExitCode
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_nagios.py
+
2
−
1
View file @
e655f672
...
@@ -107,7 +107,8 @@ def test_output_parsing(output):
...
@@ -107,7 +107,8 @@ def test_output_parsing(output):
)
)
with
_mock_run
(
return_value
=
proc
):
with
_mock_run
(
return_value
=
proc
):
check
.
run
()
check
.
run
()
# TODO: validate something.
assert
isinstance
(
check
.
Output
,
str
)
assert
len
(
check
.
Output
.
splitlines
())
==
1
@pytest.mark.parametrize
(
"
line
"
,
PERF_DATA
)
@pytest.mark.parametrize
(
"
line
"
,
PERF_DATA
)
...
...
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