Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

None passed as range defaults to "0:" #15

Open
mpounsett opened this issue Jul 13, 2016 · 3 comments
Open

None passed as range defaults to "0:" #15

mpounsett opened this issue Jul 13, 2016 · 3 comments
Labels
feature New feature or request minor
Milestone

Comments

@mpounsett
Copy link
Owner

Original report by Gabriel Hege (Bitbucket: datensuppe, ).


When passing None as a warning or critical range to the Context or ScalarContext constructor, it uses "0:" for evaluation. This results in a warning or critical status to be written, when the value of the Metric is negative. This is very counterintuitive, because one would expect no warning or critical alert to be generated, especially since the range string does not show in the performance data.

Here is a minimal example:

#!python

import nagiosplugin

class Sensors(nagiosplugin.Resource):
    def probe(self):
        return nagiosplugin.Metric('sens1', -3)

check = nagiosplugin.Check(Sensors(), nagiosplugin.ScalarContext('sens1', warning="-10:10"))
check.main()

which generates the following output:
SENSORS CRITICAL - sens1 is -3 (outside range 0:) | sens1=-3;-10:10

@mpounsett
Copy link
Owner Author

Original comment by mrvinti (Bitbucket: mrvinti, GitHub: mrvinti).


You can get around this by specifying a -inf:inf ("~:") range for your critical threshold. This won't result in a CRITICAL status and will evaluate to OK when within the warning range:

#!python
import nagiosplugin

class Sensors(nagiosplugin.Resource):
    def probe(self):
        return nagiosplugin.Metric('sens1', -3)

check = nagiosplugin.Check(Sensors(), nagiosplugin.ScalarContext('sens1', warning="-10:10", critical="~:"))
check.main()

>>> SENSORS OK - sens1 is -3 | sens1=-3;-10:10;~:

I've created a pull request #6 which addresses this issue replacing the default.

@mpounsett
Copy link
Owner Author

Original comment by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


I think that changing the interpretation of an empty string in Range() should be ok. The specs state that if a Range does not state an explicit value for start, start should be assumed as 0. However, there is no saying in the specs what to do if a range is left completely empty. So the change is agreeable. And it is more intuitive of course. :-)

@mpounsett mpounsett added major library bug Something isn't working needs review Needs developer review before assigning a milestone and removed library labels Nov 7, 2019
@mpounsett mpounsett added feature New feature or request minor and removed needs review Needs developer review before assigning a milestone bug Something isn't working major labels Feb 6, 2022
@mpounsett
Copy link
Owner Author

It looks like Christian never got around to dealing with this issue. I've had a look and at first glance what I think he had in mind seems reasonably do-able. The pull request mentioned by @mrvinti didn't survive the migration from BitBucket, but I think I can see what was probably done there. I'm adding this to the work list for the next 1.3.x release.

@mpounsett mpounsett added this to the 1.3.3 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request minor
Projects
None yet
Development

No branches or pull requests

1 participant