@@ -280,11 +280,15 @@ def report_and_exit(self):
280280
281281 if self .threshold <= 0 or time .time () - timestamp < self .threshold :
282282 self .log .info ("Nagios check cache file %s contents delivered: %s" , self .filename , nagios_message )
283- print ( "%s %s" % ( nagios_exit_string , nagios_message ) )
283+ self . print_report ( nagios_exit_string , nagios_message )
284284 sys .exit (nagios_exit_code )
285285 else :
286286 unknown_exit ("%s gzipped JSON file too old (timestamp = %s)" % (self .header , time .ctime (timestamp )))
287287
288+ def print_report (self , nagios_exit_string , nagios_message ):
289+ """Print the nagios report"""
290+ print ("%s %s" % (nagios_exit_string , nagios_message ))
291+
288292 def cache (self , nagios_exit , nagios_message ):
289293 """Store the result in the cache file with a timestamp.
290294
@@ -434,6 +438,11 @@ class SimpleNagios(NagiosResult):
434438
435439 def __init__ (self , ** kwargs ):
436440 """Initialise message and perfdata"""
441+ self ._init (** kwargs )
442+
443+ def _init (self , reporterclass = NagiosReporter , ** kwargs ):
444+ """The real init method"""
445+
437446 self .__dict__ = {}
438447 self .message = None # the message
439448
@@ -453,10 +462,10 @@ def __init__(self, **kwargs):
453462 if self ._cache :
454463 # make a NagiosReporter instance that can be used for caching
455464 if self ._cache_user :
456- cache = NagiosReporter ('no header' , self ._cache , self ._threshold , nagios_username = self ._cache_user ,
465+ cache = reporterclass ('no header' , self ._cache , self ._threshold , nagios_username = self ._cache_user ,
457466 world_readable = self ._world_readable )
458467 else :
459- cache = NagiosReporter ('no header' , self ._cache , self ._threshold , world_readable = self ._world_readable )
468+ cache = reporterclass ('no header' , self ._cache , self ._threshold , world_readable = self ._world_readable )
460469 if self ._report_and_exit :
461470 cache .report_and_exit ()
462471 else :
0 commit comments