Skip to content

Active Check for remaining validity of Certificate Revocation Lists#331

Closed
OguzhanCicek wants to merge 4 commits into
Checkmk:masterfrom
OguzhanCicek:check_crl
Closed

Active Check for remaining validity of Certificate Revocation Lists#331
OguzhanCicek wants to merge 4 commits into
Checkmk:masterfrom
OguzhanCicek:check_crl

Conversation

@OguzhanCicek
Copy link
Copy Markdown
Contributor

This PR adds a active check to monitor the remaining hours of validity of a given CRL. To check this the following nagios plugin is being used:
https://raymii.org/s/software/Nagios_plugin_to_check_CRL_expiry.html

@OguzhanCicek
Copy link
Copy Markdown
Contributor Author

One of the unit tests fail because it cant find the manpage for this check. Im not sure why its not being found.

@jherbel
Copy link
Copy Markdown
Contributor

jherbel commented Mar 3, 2021

Hi,
thank you for this PR. I am not sure if this PR is actually needed. Checkmk has the capability to use Nagios plugins, see
https://docs.checkmk.com/master/en/active_checks.html (2.3. Integrating other Nagios-compatible plug-ins). Please check if this already fits your needs. I also took a brief look at the description of the Nagios plugin, you can provide WARN and CRIT levels via the command line.
Best
Jörg

@jherbel
Copy link
Copy Markdown
Contributor

jherbel commented Mar 3, 2021

We just had an internal discussion about this and it turned out that we should definitely consider merging this. I will take a closer look at the code itself soon.

@jherbel
Copy link
Copy Markdown
Contributor

jherbel commented Mar 3, 2021

One thing: I think the version of the plugin itself which you uploaded here is not the latest one, this one seems to be newer: https://github.com/RaymiiOrg/nagios/blob/master/check_crl/check_crl.py
Could you check this please?

…cts the

 remaining time in minutes. Had to add a addition try-except block in line 59 to make it work.
-now works with remaining minutes and not hours.
Comment thread checks/check_crl Outdated


def check_crl_arguments(params):
return "-u {} -w {} -c {}".format(params.get("url"), params.get("minutes")[0], params.get("minutes")[1])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is incorrect: if "minutes" is not in params, you will end up with the expression None[0], which will of course crash. This should never happen, since the valuespec below has no optional keys, so please use params["url"] etc.

Comment thread cmk/gui/plugins/wato/active_checks.py Outdated
help=_("These levels make the check go warning or critical whenever the "
"remaining validity of the monitored CRL is too low."),
elements=[
Integer(title=_("warning at"), unit=u"Minutes", default_value=2880),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the valuespec Age here. In checks/check_crl, the actual value will then be seconds, so you have to transform there to what the Nagios plugin expects.

try:
inform = 'DER'
crlfile = open(tmpcrl, "r")
try:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why and when this is necessary? Probably, this PR is related:
RaymiiOrg/nagios#6
I am not saying that you should include this PR here, I am just trying to understand under what conditions this will fail and if this could be avoided by using for example open(..., mode="rb") or something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we still need some clarification

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we still need some clarification

Comment thread checks/check_crl
@@ -0,0 +1,141 @@
#!/usr/bin/python3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our fileheader please

Comment thread omd/packages/nagios/skel/local/lib/nagios/plugins/check_crl

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hu:w:c:", ["help", "url=", "warning=", "critical="])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please transform this to argparse

import tempfile
import urllib.request, urllib.parse, urllib.error

def check_crl(url, warn, crit):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add typization

minutes = (eol - today) / 60
if abs(minutes) < 4 * 60:
expires = minutes
unit = "minutes"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at cmk.utils.render.Age for this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check cmk.utils.render.Age

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check cmk.utils.render.Age

Copy link
Copy Markdown
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Nagios plugin still needs some work. First of all, please move it to active_checks/check_crl. Next, we need to bring it to a maintainable state. I know that you did not write the plugin, however, since we port it into our codebase, we will have to maintain it in the future.

@OguzhanCicek
Copy link
Copy Markdown
Contributor Author

The Nagios plugin still needs some work. First of all, please move it to active_checks/check_crl. Next, we need to bring it to a maintainable state. I know that you did not write the plugin, however, since we port it into our codebase, we will have to maintain it in the future.

ok. I will try to update this PR within the coming week. Please dont close this for inactivity.

-uses valuespec Age now
-uses now checkmk file headers
-changes the main() call
-uses argpase now
Copy link
Copy Markdown
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already much better. Please also add a unit test similar to tests/unit/checks/test_check_sftp.py


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--url", "-u", required=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type=str here for clarity

import urllib.request, urllib.parse, urllib.error

def output_check_result(rc, s):
stxt = ['OK', 'WARN', 'CRIT', 'UNKNOWN'][rc]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need stxt, since in Checkmk, you anyway see the check result in a separate column, so there is no need to add it here as a text.

@@ -0,0 +1,140 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2013 - Remy van Elst
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust file header please

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust file header please

output = '%s - %s' % (stxt, s)
sys.stdout.write('%s\n' % output)

def check_crl(url: str, warn: int, crit: int):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add return type

minutes = (eol - today) / 60
if abs(minutes) < 4 * 60:
expires = minutes
unit = "minutes"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check cmk.utils.render.Age

Comment thread checks/check_crl Outdated


def check_crl_description(params):
return "CRL: {}".format(params["url"])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an f-string here

Comment thread checks/check_crl Outdated


def check_crl_arguments(params):
return "-u {} -w {} -c {}".format(params["url"], params["time"][0], params["time"][1])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an f-string here

Comment thread checks/check_crl Outdated
return "CRL: {}".format(params["url"])


active_check_info["check_crl"] = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active_check_info["crl"]

Comment thread cmk/gui/plugins/wato/active_checks.py Outdated
HostRulespec(
group=RulespecGroupActiveChecks,
match_type="all",
name="active_checks:check_crl",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name="active_checks:crl",

Comment thread cmk/gui/plugins/wato/active_checks.py Outdated
))


def _valuespec_active_checks_crl():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typization (return type)

-renames the active check from check_crl to crl
Copy link
Copy Markdown
Contributor

@jherbel jherbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some issues + the new unit tests of course needs to pass.

@@ -0,0 +1,140 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2013 - Remy van Elst
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust file header please

try:
inform = 'DER'
crlfile = open(tmpcrl, "r")
try:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we still need some clarification

minutes = (eol - today) / 60
if abs(minutes) < 4 * 60:
expires = minutes
unit = "minutes"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check cmk.utils.render.Age



@pytest.mark.parametrize("params,expected_args", [
(("foo", 222, 111, "bar", {}), ["--url=foo", "--warn=222", "--crit=111"]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the valuespec, you expect a dict here, not a tuple. Accordingly, this test failed in the last travis run.

@jherbel
Copy link
Copy Markdown
Contributor

jherbel commented May 18, 2021

Closed this due to inactivity.

@jherbel jherbel closed this May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants