1-
2- # -*- encoding: utf-8 -*-
31#
42# Copyright 2012-2023 Ghent University
53#
@@ -143,7 +141,7 @@ def exit_from_errorcode(errorcode, msg, error_map=None):
143141 unknown_exit (f"{ msg } (errorcode { errorcode } not found in { e_map } " )
144142
145143
146- class NagiosRange ( object ) :
144+ class NagiosRange :
147145 """Implement Nagios ranges"""
148146 DEFAULT_START = 0
149147 def __init__ (self , nrange ):
@@ -244,7 +242,7 @@ def alert(self, test):
244242 return not self .range_fn (test )
245243
246244
247- class NagiosReporter ( object ) :
245+ class NagiosReporter :
248246 """Reporting class for Nagios/Icinga reports.
249247
250248 Can cache the result in a gzipped JSON file and print the result out at some later point.
@@ -282,7 +280,7 @@ def report_and_exit(self):
282280 """
283281 try :
284282 nagios_cache = FileCache (self .filename , True )
285- except ( IOError , OSError ) :
283+ except OSError :
286284 self .log .critical ("Error opening file %s for reading" , self .filename )
287285 unknown_exit (f"{ self .header } nagios gzipped JSON file unavailable ({ self .filename } )" )
288286
@@ -309,7 +307,7 @@ def cache(self, nagios_exit, nagios_message):
309307 nagios_cache .update ('nagios' , (nagios_exit , nagios_message ), 0 ) # always update
310308 nagios_cache .close ()
311309 self .log .info ("Wrote nagios check cache file %s at about %s" , self .filename , time .ctime (time .time ()))
312- except ( IOError , OSError ) as exc :
310+ except OSError as exc :
313311 # raising an error is ok, since we usually do this as the very last thing in the script
314312 msg = f"Cannot save to the nagios gzipped JSON file ({ self .filename } )"
315313 self .log .exception (msg )
@@ -336,7 +334,7 @@ def cache(self, nagios_exit, nagios_message):
336334 return True
337335
338336
339- class NagiosResult ( object ) :
337+ class NagiosResult :
340338 """Class representing the results of an Icinga/Nagios check.
341339
342340 It will contain a field with the message to be printed. And the
@@ -370,7 +368,7 @@ class NagiosResult(object):
370368 Nagios checks, please refer to
371369 U{http://docs.icinga.org/latest/en/perfdata.html}
372370 """
373- RESERVED_WORDS = set ([ 'message' ])
371+ RESERVED_WORDS = { 'message' }
374372 NAME_REG = re .compile (r'^(?P<name>.*?)(?:_(?P<option>warning|critical))?$' )
375373
376374 def __init__ (self , message , ** kwargs ):
@@ -442,8 +440,8 @@ class SimpleNagios(NagiosResult):
442440 """
443441
444442 USE_HEADER = True
445- RESERVED_WORDS = set ([ 'message' , 'ok' , 'warning' , 'critical' , 'unknown' ,
446- '_exit' , '_cache' , '_cache_user' , '_final' , '_final_state' , '_report' , '_threshold' ])
443+ RESERVED_WORDS = { 'message' , 'ok' , 'warning' , 'critical' , 'unknown' ,
444+ '_exit' , '_cache' , '_cache_user' , '_final' , '_final_state' , '_report' , '_threshold' }
447445
448446 def __init__ (self , ** kwargs ):
449447 """Initialise message and perfdata"""
0 commit comments