I have a question about subclassing the nagiosplugin.performance.Performance class. I wanted to override the str method, but ran into a problem (see traceback below). Looking over the documentation for super. It seems the second argument is expected to be an instance or subtype of the first argument. The way super is called in the new method of the nagiosplugin.performance.Performance class it doesn't seem possible to override class methods like below. If I were to swap the arguments in the super call in Performance.new I no longer get the TypeError below. Is this implementation by design? My apologies if I'm misinterpreting something here.
#!python
class PluginPerformance(nagiosplugin.Performance):
__str__(self):
# Do some stuff here
Traceback (most recent call last):
File "./plugins/check_consumer_metrics", line 75, in <module>
main()
File "./plugins/check_consumer_metrics", line 71, in main
check.main()
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/check.py", line 115, in main
runtime.execute(self, verbose, timeout)
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/runtime.py", line 118, in execute
with_timeout(self.timeout, self.run, check)
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/platform/posix.py", line 19, in with_timeout
func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/runtime.py", line 107, in run
check()
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/check.py", line 100, in __call__
self._evaluate_resource(resource)
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/check.py", line 86, in _evaluate_resource
self.perfdata.append(str(metric.performance() or ''))
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/metric.py", line 104, in performance
return self.contextobj.performance(self, self.resource)
File "/tmp/kafka-monitoring/monitoring.py", line 171, in performance
return PluginPerformance(metric.context, metric.value)
File "/usr/local/lib/python2.7/site-packages/nagiosplugin/performance.py", line 51, in __new__
return super(cls, Performance).__new__(
TypeError: super(type, obj): obj must be an instance or subtype of type
Original report by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).
From: Lofton Newton loftonnewton@gmail.com
I have a question about subclassing the nagiosplugin.performance.Performance class. I wanted to override the str method, but ran into a problem (see traceback below). Looking over the documentation for super. It seems the second argument is expected to be an instance or subtype of the first argument. The way super is called in the new method of the nagiosplugin.performance.Performance class it doesn't seem possible to override class methods like below. If I were to swap the arguments in the super call in Performance.new I no longer get the TypeError below. Is this implementation by design? My apologies if I'm misinterpreting something here.