Skip to content

Commit bc3c247

Browse files
committed
add monitorclass arg to __init__ instead of prologue
1 parent 7b639b9 commit bc3c247

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/vsc/utils/script_tools.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ class ExtendedSimpleOption(SimpleOption):
115115
The prologue should be called at the start of the script; the epilogue at the end.
116116
"""
117117

118-
def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
118+
def __init__(self, options, run_prologue=True, excepthook=None, monitorclass=SimpleNagios, **kwargs):
119119
"""Initialise.
120120
121121
If run_prologue is True (default), we immediately execute the prologue.
122122
123+
- MonitorClass: the class to use for interaction with the monitoring software
124+
123125
Note that if taking a lock is requested (default), and the lock cannot be
124126
acquire for some reason, the program will exit,
125127
"""
@@ -129,6 +131,7 @@ def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
129131

130132
self.nagios_reporter = None
131133
self.lockfile = None
134+
self.MonitorClass = monitorclass
132135

133136
if run_prologue:
134137
self.prologue()
@@ -140,23 +143,23 @@ def __init__(self, options, run_prologue=True, excepthook=None, **kwargs):
140143

141144
self.log = fancylogger.getLogger()
142145

143-
def prologue(self, MonitorClass=SimpleNagios):
146+
def prologue(self):
144147
"""Checks the options given for settings and takes appropriate action.
145148
146149
See _merge_options for the format.
147-
- MonitorClass: the class to use for interaction with the monitoring software
150+
148151
- if nagios_report is set, creates a MonitorClass instance and prints the report.
149152
- if ha is set, checks if running on the correct host, set the appropriate nagios message and bail if not.
150153
- if locking_filename is set, take a lock. If the lock fails, bork and set the nagios exit accordingly.
151154
"""
152155

153156
# bail if nagios report is requested
154-
self.nagios_reporter = MonitorClass(_cache=self.options.nagios_check_filename,
155-
_report_and_exit=self.options.nagios_report,
156-
_threshold=self.options.nagios_check_interval_threshold,
157-
_cache_user=self.options.nagios_user,
158-
_world_readable=self.options.nagios_world_readable_check,
159-
)
157+
self.nagios_reporter = self.MonitorClass(_cache=self.options.nagios_check_filename,
158+
_report_and_exit=self.options.nagios_report,
159+
_threshold=self.options.nagios_check_interval_threshold,
160+
_cache_user=self.options.nagios_user,
161+
_world_readable=self.options.nagios_world_readable_check,
162+
)
160163

161164
# check for HA host
162165
if self.options.ha and not proceed_on_ha_service(self.options.ha):

0 commit comments

Comments
 (0)