Skip to content
GitLab
Explore
Sign in
Register
shore
My Nagios Plugin Wrapper
Compare revisions
21ff987e2f127616b2397bcfab25c4edc9ddb30e to 5cf1c500de16916871c93aac4ab7af34b6b88e79
Commits on Source (2)
Notifcation retries.
· e4d9bd1e
nimrod
authored
Aug 17, 2021
e4d9bd1e
Change the notification format.
· 5cf1c500
nimrod
authored
Aug 17, 2021
I find this format to be better.
5cf1c500
Hide whitespace changes
Inline
Side-by-side
mnpw/__init__.py
View file @
5cf1c500
...
...
@@ -16,11 +16,16 @@ HOSTNAME = socket.gethostname()
def
notify
(
message
):
"""
Send a notification.
"""
r
=
requests
.
post
(
# pylint: disable=invalid-name
"
https://notify.shore.co.il/send
"
,
params
=
{
"
message
"
:
message
}
)
if
not
r
.
ok
:
logging
.
error
(
f
"
Failed to send notification:
{
r
.
reason
}
.
"
)
for
_
in
range
(
3
):
r
=
requests
.
post
(
# pylint: disable=invalid-name
"
https://notify.shore.co.il/send
"
,
params
=
{
"
message
"
:
message
}
)
if
r
.
ok
:
return
logging
.
warning
(
f
"
Failed to send notification:
{
r
.
reason
}
, will retry.
"
)
logging
.
error
(
"
Failed to send notification.
"
)
def
main
():
# noqa: MC0001
...
...
@@ -107,15 +112,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
"
{
check
.
Output
}
on
{
HOSTNAME
}
.
"
)
notify
(
f
"
(
{
HOSTNAME
}
{
check
.
Output
}
"
)
elif
check
.
ExitCode
==
nagios
.
NagiosCode
.
CRITICAL
:
logging
.
info
(
"
Check status is CRITICAL.
"
)
if
not
args
.
dry_run
:
notify
(
f
"
{
check
.
Output
}
on
{
HOSTNAME
}
.
"
)
notify
(
f
"
(
{
HOSTNAME
}
{
check
.
Output
}
"
)
elif
check
.
ExitCode
==
nagios
.
NagiosCode
.
UNKNOWN
:
logging
.
info
(
"
Check status is UNKNOWN.
"
)
if
args
.
unknown
and
not
args
.
dry_run
:
notify
(
f
"
{
check
.
Output
}
on
{
HOSTNAME
}
.
"
)
notify
(
f
"
(
{
HOSTNAME
}
{
check
.
Output
}
"
)
else
:
logging
.
info
(
f
"
Check status is invalid for a Nagios plugin (
{
check
.
ExitCode
}
).
"
...
...