def __init__(self): # Python 2.x super(PubSubNagiosPlugin, self).__init__() # Python 3.x # super().__init__() self.name = None self.default_host = 'localhost' self.default_port = None self.host = None self.port = None self.producer = None self.consumer = None self.key = os.path.basename(get_topfile()) + '-' + random_alnum(20) self.start_offset = None timestamp = time.time() # socket.getfqdn() hangs on network / DNS outage, use socket.gethostname() instead self.publish_message = "Test message from Hari Sekhon {0} on host {1} "\ .format(os.path.basename(get_topfile()), socket.gethostname()) + \ "at epoch {0} ({1}) with random token '{2}'"\ .format(timestamp, time.ctime(timestamp), random_alnum(20)) self._consumed_message = None self._publish_timing = None self._consume_timing = None self.status = 'OK' self.warning = 1 self.critical = 2
def __init__(self): # Python 2.x super(PubSubNagiosPlugin, self).__init__() # Python 3.x # super().__init__() self.name = None self.default_host = 'localhost' self.default_port = None self.host = None self.port = None self.producer = None self.consumer = None self.key = os.path.basename(get_topfile()) + '-' + random_alnum(20) self.start_offset = None timestamp = time.time() # socket.getfqdn() hangs on network / DNS outage, use socket.gethostname() instead self.publish_message = "Test message from Hari Sekhon {0} on host {1} "\ .format(os.path.basename(get_topfile()), socket.gethostname()) + \ "at epoch {0} ({1}) with random token '{2}'"\ .format(timestamp, time.ctime(timestamp), random_alnum(20)) self._consumed_message = None self._publish_time = None self._consume_time = None self._total_time = None self._precision = 3 self.status = 'OK' self.warning_threshold_default = 1 self.critical_threshold_default = 2 self.__sleep_secs = 0
def __init__(self): # Python 2.x super(CheckKafka, self).__init__() # Python 3.x # super().__init__() self.name = 'Kafka' self.default_host = 'localhost' self.default_port = '9092' self.producer = None self.consumer = None self.topic = None self.client_id = 'Hari Sekhon {prog} {version}'.format( prog=os.path.basename(get_topfile()), version=__version__) self.group_id = '{client_id} {pid} {random}'.format( client_id=self.client_id, pid=os.getpid(), random=random_alnum(10)) self.acks = '1' self.retries = 0 self.partition = None self.topic_partition = None self.brokers = None self.timeout_ms = None self.start_offset = None self.sleep_secs = 0 self.sleep_usage = 'Sleep in seconds between producing and consuming from given topic' + \ ' (optional, default: {} secs)'.format(self.default_sleep_secs)
def req(self, method, url, *args, **kwargs): if '://' not in url: url = 'http://' + url self.url = url log.debug('%s %s', str(method).upper(), url) req = None if 'headers' in kwargs: kwargs['headers']['User-Agent'] = get_topfile() else: kwargs['headers'] = {'User-Agent': get_topfile()} try: req = getattr(requests, method)(url, *args, **kwargs) except requests.exceptions.RequestException as _: self.exception_handler(_) self.log_output(req) self.process_req(req) return req
def __init__(self): # Python 2.x super(KeyWriteNagiosPlugin, self).__init__() # Python 3.x # super().__init__() self.key = os.path.basename(get_topfile()) + "-" + random_alnum(20) self._write_value = random_alnum(20) self._write_timing = None self._delete_timing = None
def __init__(self): # Python 2.x super(KeyWriteNagiosPlugin, self).__init__() # Python 3.x # super().__init__() self.key = os.path.basename(get_topfile()) + '-' + random_alnum(20) self._write_value = random_alnum(20) self._write_timing = None self._delete_timing = None
def __init__(self): # instance attributes, feels safer self.name = None self.options = None self.args = None self.__verbose = None self.__verbose_default = 0 self.__timeout = None self.__timeout_default = 10 self.__timeout_max = 86400 self.__total_run_time = time.time() self.topfile = get_topfile() self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') # pylint: disable=line-too-long self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # _hidden attributes are shown in __dict__ self.version = '{prog} version {topfile_version} '.format(prog=self._prog, topfile_version=self._topfile_version) + \ '=> CLI version {cli_version} '.format(cli_version=self._cli_version) + \ '=> Utils version {utils_version}'.format(utils_version=self._utils_version) self.usagemsg = 'Hari Sekhon{sep}{github_repo}\n\n{prog}\n{docstring}\n'.format(\ sep=' - ' if self._github_repo else '', github_repo=self._github_repo, prog=self._prog, docstring=self._docstring) self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: try: width = Terminal().width except _curses.error: width = 80 width = min(width, 200) self.__parser = OptionParser(add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()
def __init__(self): # instance attributes, feels safer self.options = None self.args = None self.__verbose = None self.__verbose_default = 0 self.__timeout = None self.__timeout_default = 10 self.__timeout_max = 86400 self.topfile = get_topfile() # this gets utrunner.py in PyCharm and runpy.py from unittest if os.path.basename(self.topfile) in ('utrunner.py', 'runpy.py'): self.topfile = __file__ #print('topfile = %s' % self.topfile) self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') # pylint: disable=line-too-long self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # if not self.github_repo: # self.github_repo = 'https://github.com/harisekhon/pytools' if self._github_repo: self._github_repo = ' - ' + self._github_repo # _hidden attributes are shown in __dict__ self.version = '%(_prog)s version %(_topfile_version)s ' % self.__dict__ + \ '=> CLI version %(_cli_version)s => Utils version %(_utils_version)s' % self.__dict__ self.usagemsg = 'Hari Sekhon%(_github_repo)s\n\n%(_prog)s\n%(_docstring)s\n' \ % self.__dict__ self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: width = Terminal().width width = min(width, 200) self.__parser = OptionParser(add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()
def __init__(self): # Python 2.x super(CheckKafka, self).__init__() # Python 3.x # super().__init__() self.name = 'Kafka' self.default_port = 9092 self.producer = None self.consumer = None self.topic = None self.client_id = 'Hari Sekhon ' + os.path.basename(get_topfile()) + ' ' + __version__ self.group_id = self.client_id + ' ' + str(os.getpid()) + ' ' + random_alnum(10) self.acks = '1' self.retries = 0 self.partition = None self.topic_partition = None self.brokers = None self.timeout_ms = None self.start_offset = None
def __init__(self): # Python 2.x super(LiveNodesNagiosPlugin, self).__init__() # Python 3.x # super().__init__() self.default_host = 'localhost' self.default_port = None self.host = None self.port = None self.name = None self.agent_name = 'node' self.state = 'online' self.node_count = None self.additional_info = '' self.additional_perfdata = '' topfile = get_topfile() if 'workers' in topfile: self.agent_name = 'worker' elif 'slaves' in topfile: self.agent_name = 'slave' elif 'agents' in topfile: self.agent_name = 'agent'
def __init__(self): # instance attributes, feels safer self.name = None self.default_host = None self.default_port = None self.default_user = None self.default_password = None self.options = None self.args = None self.__verbose_default = 0 self.__verbose = self.__verbose_default self.__timeout_default = 10 self.__timeout = None self.__timeout_max = 86400 self.__total_run_time = time.time() self.topfile = get_topfile() self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # _hidden attributes are shown in __dict__ self.version = '{prog} version {topfile_version} '.format(prog=self._prog, topfile_version=self._topfile_version) + \ '=> CLI version {cli_version} '.format(cli_version=self._cli_version) + \ '=> Utils version {utils_version}'.format(utils_version=self._utils_version) self.usagemsg = 'Hari Sekhon{sep}{github_repo}\n\n{prog}\n{docstring}\n'.format(\ sep=' - ' if self._github_repo else '', github_repo=self._github_repo, prog=self._prog, docstring=self._docstring) self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: try: width = Terminal().width except _curses.error: width = 80 #width = min(width, 200) self.__parser = OptionParser( add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()