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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shore
My Nagios Plugin Wrapper
Commits
4c067d4c
Commit
4c067d4c
authored
3 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Handle notifications without command output.
parent
a70e63a4
No related branches found
No related tags found
No related merge requests found
Pipeline
#2660
passed
3 years ago
Stage: .pre
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mnpw/__init__.py
+18
-3
18 additions, 3 deletions
mnpw/__init__.py
with
18 additions
and
3 deletions
mnpw/__init__.py
+
18
−
3
View file @
4c067d4c
...
...
@@ -4,6 +4,7 @@ __version__ = "0.1.5"
import
argparse
import
logging
import
os.path
import
socket
import
sys
...
...
@@ -28,6 +29,20 @@ def notify(message):
logging
.
error
(
"
Failed to send notification.
"
)
def
notify_wrapper
(
check
):
"""
mnpw specific notifications.
The above notify function is generic, this function is more specific to the
notifications mnpw sends.
"""
if
check
.
Output
is
None
or
check
.
Output
.
strip
()
==
""
:
notify
(
f
"
[
{
HOSTNAME
}
]
{
os
.
path
.
basename
(
check
.
Command
)
}
returned
{
check
.
ExitCode
}
.
"
# noqa: E501
)
else
:
notify
(
f
"
[
{
HOSTNAME
}
]
{
check
.
Output
}
"
)
def
main
():
# noqa: MC0001
"""
Main entrypoint.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
...
...
@@ -112,15 +127,15 @@ def main(): # noqa: MC0001
elif
check
.
ExitCode
==
nagios
.
NagiosCode
.
WARNING
:
logging
.
info
(
"
Check status is WARNING.
"
)
if
args
.
warn
and
not
args
.
dry_run
:
notify
(
f
"
[
{
HOSTNAME
}
]
{
check
.
Output
}
"
)
notify
_wrapper
(
check
)
elif
check
.
ExitCode
==
nagios
.
NagiosCode
.
CRITICAL
:
logging
.
info
(
"
Check status is CRITICAL.
"
)
if
not
args
.
dry_run
:
notify
(
f
"
[
{
HOSTNAME
}
]
{
check
.
Output
}
"
)
notify
_wrapper
(
check
)
elif
check
.
ExitCode
==
nagios
.
NagiosCode
.
UNKNOWN
:
logging
.
info
(
"
Check status is UNKNOWN.
"
)
if
args
.
unknown
and
not
args
.
dry_run
:
notify
(
f
"
[
{
HOSTNAME
}
]
{
check
.
Output
}
"
)
notify
_wrapper
(
check
)
else
:
logging
.
info
(
f
"
Check status is invalid for a Nagios plugin (
{
check
.
ExitCode
}
).
"
...
...
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