@@ -269,14 +269,16 @@ def report_and_exit(self):
269269 logging .critical ("Error opening file %s for reading" , self .filename )
270270 unknown_exit ("%s nagios gzipped JSON file unavailable (%s)" % (self .header , self .filename ))
271271
272- (timestamp , ((nagios_exit_code , nagios_exit_string ), nagios_message )) = nagios_cache .load ('nagios' )
272+ (timestamp , nagios_exit_info ) = nagios_cache .load ('nagios' )
273+
274+ if nagios_exit_info is None :
275+ unknown_exit ("%s nagios exit info expired" % self .header )
276+
277+ ((nagios_exit_code , nagios_exit_string ), nagios_message ) = nagios_exit_info
278+
279+ print ("%s %s" % (nagios_exit_string , nagios_message ))
280+ sys .exit (nagios_exit_code )
273281
274- if self .threshold <= 0 or time .time () - timestamp < self .threshold :
275- logging .info ("Nagios check cache file %s contents delivered: %s" , self .filename , nagios_message )
276- print ("%s %s" % (nagios_exit_string , nagios_message ))
277- sys .exit (nagios_exit_code )
278- else :
279- unknown_exit ("%s gzipped JSON file too old (timestamp = %s)" % (self .header , time .ctime (timestamp )))
280282
281283 def cache (self , nagios_exit , nagios_message ):
282284 """Store the result in the cache file with a timestamp.
@@ -289,7 +291,7 @@ def cache(self, nagios_exit, nagios_message):
289291 """
290292 try :
291293 nagios_cache = FileCache (self .filename )
292- nagios_cache .update ('nagios' , (nagios_exit , nagios_message ), 0 ) # always update
294+ nagios_cache .update ('nagios' , (nagios_exit , nagios_message ), threshold = self . threshold )
293295 nagios_cache .close ()
294296 logging .info ("Wrote nagios check cache file %s at about %s" , self .filename , time .ctime (time .time ()))
295297 except (IOError , OSError ):
0 commit comments