mpounsett / nagiosplugin

A Python class library which helps with writing Nagios (Icinga) compatible plugins.
https://nagiosplugin.readthedocs.io/
Other
28 stars 14 forks source link

Verbosity can't be changed for @nagiosplugin.guarded #13

Closed mpounsett closed 8 years ago

mpounsett commented 8 years ago

Original report by Louis Sautier (Bitbucket: sbraz, GitHub: sbraz).


Hi, after looking at the code for the latest revision, it seems there is no way to change the verbosity of the exceptions trapped by @nagiosplugin.guarded without monkey-patching a lot of code.

Until version 1.2.3, I would force it with:

#!python

nagiosplugin.runtime.Runtime._verbose = 0

but since the attribute moved to another object, I don't see a simple way to do it.

Maybe adding arguments to the decorator could be the answer to this problem.

mpounsett commented 8 years ago

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


This is an interesting point. Could you give a bit of background info why one would need this functionality? In my opinion, uncaught exceptions during the initialization phase (before entering main()) should be fatal in any case...

mpounsett commented 8 years ago

Original comment by Louis Sautier (Bitbucket: sbraz, GitHub: sbraz).


@ckauhaus I'm using ScalarContext with user-submitted arguments. If the argument isn't valid, I see a huge backtrace:

UNKNOWN: ValueError: invalid literal for int() with base 10: 'test'
Traceback (most recent call last):
  File "/usr/lib64/python3.4/site-packages/nagiosplugin/runtime.py", line 38, in wrapper
    return func(*args, **kwds)
  File "/usr/lib/nagios/plugins/check_traffic", line 138, in main
    nagiosplugin.ScalarContext("traffic_rx", args.warning_rx, args.critical_rx),
  File "/usr/lib64/python3.4/site-packages/nagiosplugin/context.py", line 119, in __init__
    self.warning = Range(warning)
  File "/usr/lib64/python3.4/site-packages/nagiosplugin/range.py", line 32, in __new__
    start, end, invert = cls._parse(str(spec))
  File "/usr/lib64/python3.4/site-packages/nagiosplugin/range.py", line 50, in _parse
    end = cls._parse_atom(end, float('inf'))
  File "/usr/lib64/python3.4/site-packages/nagiosplugin/range.py", line 59, in _parse_atom
    return int(atom)
ValueError: invalid literal for int() with base 10: 'test'

Let me know if you want to see the whole code.

mpounsett commented 8 years ago

Original comment by Louis Sautier (Bitbucket: sbraz, GitHub: sbraz).


@ckauhaus Hi, do you think you'll have time to look into this?

mpounsett commented 8 years ago

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


Sorry, I somehow lost sight of this issue. I'll get to it during the next couple of days.

mpounsett commented 8 years ago

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


Configure verbosity level in initialization phase

Before entering Check.main(), the verbosity level used to be fixed to 1. Introduce optional 'verbose' keyword argument to guarded() to set verbosity level during the initialization phase.

Re #13

mpounsett commented 8 years ago

Original comment by Louis Sautier (Bitbucket: sbraz, GitHub: sbraz).


Thanks, will you make a new release soon with those changes?

mpounsett commented 8 years ago

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


The trunk is currently not in an optimal state. Maintenance is currently taking place on the 1.2-maint branch. I'm planning to integrate the stuff back into trunk before releasing 2.0.

W.r.t. to the 1.2 releases, I have added an optional parameter to @guarded() which allows to set the verbosity level during the initialization phase. E.g.:

@guarded(verbose=0)
def main():
...

I think this should solve your problem without requiring to override internal Runtime variables.

mpounsett commented 8 years ago

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


Release is on its way :)