Ejemplo n.º 1
0
 def process_args(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     self.key = self.get_opt('key')
     self.regex = self.get_opt('regex')
     if not self.key:
         self.usage('--key not defined')
     self.key = self.key.lstrip('/')
     validate_chars(self.key, 'key', r'\w\/-')
     if self.regex:
         validate_regex(self.regex, 'key')
     self.validate_thresholds(optional=True)
Ejemplo n.º 2
0
 def validate_threshold(self, name, threshold=None, optional=False, **kwargs):
     if not isStr(name):
         raise CodingError('non-string name passed to validate_threshold()')
     name = re.sub('[^A-Za-z0-9]', '_', name).lower()
     if threshold is None:
         # log.debug("using threshold option '%s'", name)
         threshold = self.get_opt(name)
         # log.debug("got threshold '%s'", threshold)
     if optional and threshold is None:  # pylint: disable=no-else-return
         return None
     else:
         try:
             self.__thresholds[name] = Threshold(threshold, name=name, **kwargs)
         except InvalidThresholdException as _:
             self.usage(_)
     log_option(name, threshold)
     return None
Ejemplo n.º 3
0
 def validate_thresholds(self,
                         name='',
                         warning=None,
                         critical=None,
                         **kwargs):
     if not isStr(name):
         raise CodingError(
             'non-string name passed to validate_thresholds()')
     if name:
         name += '_'
     if 'percent' in kwargs and kwargs['percent']:
         del kwargs['percent']
         kwargs['min'] = 0
         kwargs['max'] = 100
     self.validate_threshold(name='{0}{1}'.format(name, 'warning'),
                             threshold=warning,
                             **kwargs)
     self.validate_threshold(name='{0}{1}'.format(name, 'critical'),
                             threshold=critical,
                             **kwargs)
Ejemplo n.º 4
0
 def validate_threshold(self,
                        name,
                        threshold=None,
                        optional=False,
                        **kwargs):
     if not isStr(name):
         raise CodingError('non-string name passed to validate_threshold()')
     if threshold is None:
         # log.debug("using threshold option '%s'", name)
         threshold = self.get_opt(name)
         # log.debug("got threshold '%s'", threshold)
     if optional and threshold is None:
         return None
     else:
         try:
             self.__thresholds[name] = Threshold(threshold,
                                                 name=name,
                                                 **kwargs)
         except InvalidThresholdException as _:
             self.usage(_)
     log_option(name, threshold)
Ejemplo n.º 5
0
 def status(self, status):
     if status not in ERRORS:
         raise CodingError("invalid status '{0}' passed to harisekhon.NagiosPlugin.status()".format(status))
     self.__status = status
Ejemplo n.º 6
0
 def set_threshold(self, name, threshold):
     if not isinstance(threshold, Threshold):
         raise CodingError('passed a non-threshold to NagiosPlugin.set_threshold()')
     self.__thresholds[name] = threshold
Ejemplo n.º 7
0
Archivo: cli.py Proyecto: smutel/pylib
 def run(self):  # pragma: no cover
     raise CodingError('running HariSekhon.CLI().run() - this should be abstract and non-runnable!'
                       ' You should have overridden this run() method in the client code')
Ejemplo n.º 8
0
Archivo: cli.py Proyecto: smutel/pylib
 def verbose_default(self, arg):
     if not isInt(arg):
         raise CodingError('invalid verbose level passed to verbose_default(), must be an integer')
     log.debug('setting default verbose to %s', arg)
     self.__verbose_default = int(arg)
Ejemplo n.º 9
0
Archivo: cli.py Proyecto: smutel/pylib
 def get_opt(self, name):
     if not isStr(name):
         raise CodingError('passed non-string as arg to CLI.get_opt()')
     if not self.is_option_defined(name):
         raise CodingError('{0} option not defined'.format(name))
     return getattr(self.options, name)
Ejemplo n.º 10
0
 def add_options(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.add_hostoption(self.name, default_host=self.default_host, default_port=self.default_port)
     self.add_thresholds(default_warning=self.warning_threshold_default,
                         default_critical=self.critical_threshold_default)
Ejemplo n.º 11
0
 def status(self, status):
     if not ERRORS.has_key(status):
         raise CodingError(
             "invalid status '%(status)s' passed to harisekhon.NagiosPlugin.status()"
         )
     self.__status = status
Ejemplo n.º 12
0
 def timeout(self, secs):
     if not isInt(secs):
         raise CodingError('invalid timeout passed to set_timeout(), must be an integer representing seconds') # pylint: disable=line-too-long
     validate_int(secs, 'timeout', 0, self.timeout_max)
     log.debug('setting timeout to %s secs', secs)
     self.__timeout = int(secs)
Ejemplo n.º 13
0
 def add_options(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.add_hostoption(self.name, default_host=self.default_host, default_port=self.default_port)
     self._add_options()
Ejemplo n.º 14
0
 def add_options(self):
     super(RestVersionNagiosPlugin, self).add_options()
     if self.name is None:
         raise CodingError('self.name is not defined in inheriting class')
     self.add_expected_version_option()