Closed mpounsett closed 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...
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.
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
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.
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:
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.