Backup commit. Many internally changes. Known issues still need to be fixed.
This commit is contained in:
parent
8808b657c4
commit
ee423c01bb
22 changed files with 122 additions and 85 deletions
|
|
@ -46,10 +46,10 @@ class Linspector:
|
|||
'memory': MemoryJobStore()
|
||||
}
|
||||
executors = {
|
||||
#'default': ThreadPoolExecutor(int(configuration.get_option('linspector',
|
||||
# 'max_threads'))),
|
||||
'default': ProcessPoolExecutor(int(configuration.get_option('linspector',
|
||||
'max_processes')))
|
||||
'default': ThreadPoolExecutor(int(configuration.get_option('linspector',
|
||||
'max_threads'))),
|
||||
#'default': ProcessPoolExecutor(int(configuration.get_option('linspector',
|
||||
# 'max_processes')))
|
||||
}
|
||||
job_defaults = {
|
||||
'max_instances': 10000
|
||||
|
|
@ -59,7 +59,7 @@ class Linspector:
|
|||
job_defaults=job_defaults)
|
||||
|
||||
start_date = datetime.datetime.now()
|
||||
log('debug', __name__, monitors.get_monitors())
|
||||
#log('debug', __name__, monitors.get_monitors())
|
||||
monitors = self.__monitors.get_monitors()
|
||||
for monitor in monitors:
|
||||
time_delta = round(random.uniform(1.00, 10.00), 2)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ from linspector.core.task import Task, TaskExecutor
|
|||
class Monitor:
|
||||
|
||||
def __init__(self, configuration, environment, identifier, monitor_configuration, notifications,
|
||||
services, tasks):
|
||||
services, tasks, kwargs):
|
||||
self.__args = kwargs
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__identifier = identifier
|
||||
|
|
@ -29,7 +30,7 @@ class Monitor:
|
|||
self.__tasks = tasks
|
||||
|
||||
self.service = self.__service
|
||||
self.host = monitor_configuration.get('monitor', 'host')
|
||||
#self.host = monitor_configuration.get('monitor', 'host')
|
||||
#self.members = members
|
||||
#self.core = core
|
||||
self.hostgroup = monitor_configuration.get('monitor', 'hostgroup')
|
||||
|
|
@ -48,8 +49,9 @@ class Monitor:
|
|||
"""
|
||||
self.status = "NONE"
|
||||
self.last_execution = None
|
||||
self.monitor_information = MonitorInformation(self.job_id, self.hostgroup, self.host,
|
||||
self.service)
|
||||
#self.monitor_information = MonitorInformation(self.job_id, self.hostgroup, self.host,
|
||||
# self.service)
|
||||
self.monitor_information = MonitorInformation(self.job_id, self.service)
|
||||
|
||||
if configuration.get_option('linspector', 'notifications') or \
|
||||
monitor_configuration.get('monitor', 'notifications'):
|
||||
|
|
@ -83,10 +85,8 @@ class Monitor:
|
|||
|
||||
service_module = importlib.import_module(service_package)
|
||||
self.__service = monitor_configuration.get('monitor', 'service').lower()
|
||||
service = service_module.create(configuration, environment)
|
||||
services[monitor_configuration.get('monitor', 'service').lower()] = service
|
||||
|
||||
#service.execute(self)
|
||||
service = service_module.create(configuration, environment, **self.__args)
|
||||
self.__services[monitor_configuration.get('monitor', 'service').lower()] = service
|
||||
|
||||
if configuration.get_option('linspector', 'tasks') or \
|
||||
monitor_configuration.get('monitor', 'tasks'):
|
||||
|
|
@ -121,17 +121,11 @@ class Monitor:
|
|||
def get_service(self):
|
||||
return self.__service
|
||||
|
||||
# currently only used for testing but maybe i will add get functions for all known variables.
|
||||
# but not all variables can be known because all monitors are different. only the service
|
||||
# implementation can know all variables which are being used inside the service.
|
||||
def get_service(self):
|
||||
return self.__service
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
|
||||
def __hex__(self):
|
||||
return hex(crc32(bytes(self.hostgroup + self.host + self.service, 'utf-8')))
|
||||
return hex(crc32(bytes(self.hostgroup + self.service, 'utf-8')))
|
||||
|
||||
def hex_string(self):
|
||||
ret = self.__hex__()
|
||||
|
|
@ -186,6 +180,7 @@ class Monitor:
|
|||
|
||||
def handle_call(self):
|
||||
log('info', __name__, "handle call to identifier: " + self.__identifier)
|
||||
self.__services[self.__service].execute()
|
||||
#logger.debug("handle call")
|
||||
#logger.debug(self.service)
|
||||
if self.enabled:
|
||||
|
|
@ -201,7 +196,8 @@ class Monitor:
|
|||
self.handle_threshold(self.service.get_threshold(),
|
||||
self.last_execution.was_successful())
|
||||
|
||||
#logger.info("Job " + self.get_job_id() +
|
||||
log('info', __name__, 'sadasd')
|
||||
#log.info("Job " + self.get_job_id() +
|
||||
# ", Code: " + str(self.last_execution.get_error_code()) +
|
||||
# ", Message: " + str(self.last_execution.get_message()))
|
||||
|
||||
|
|
@ -212,8 +208,8 @@ class Monitor:
|
|||
else:
|
||||
log('info', __name__, "job " + self.get_job_id() + " disabled")
|
||||
|
||||
def get_host(self):
|
||||
return self.host
|
||||
#def get_host(self):
|
||||
# return self.host
|
||||
|
||||
def get_hostgroup(self):
|
||||
return self.hostgroup
|
||||
|
|
@ -262,10 +258,10 @@ class MonitorExecution:
|
|||
|
||||
|
||||
class MonitorInformation:
|
||||
def __init__(self, job_id, hostgroup, host, service):
|
||||
def __init__(self, job_id, service):
|
||||
self.job_id = job_id
|
||||
self.hostgroup = hostgroup
|
||||
self.host = host
|
||||
#self.hostgroup = hostgroup
|
||||
#self.host = host
|
||||
self.service = service
|
||||
|
||||
self.response_massage = None
|
||||
|
|
|
|||
|
|
@ -26,20 +26,32 @@ class Monitors:
|
|||
log('debug', __name__, 'monitor groups: ' + str(monitor_groups))
|
||||
monitor_configuration = configparser.ConfigParser()
|
||||
for monitor_group in monitor_groups:
|
||||
|
||||
monitors_file_list = glob.glob(self.__configuration.get_configuration_path() +
|
||||
'/monitors/' + monitor_group + '/*.conf')
|
||||
log('debug', __name__, 'monitor files: ' + str(monitors_file_list))
|
||||
#log('debug', __name__, 'monitor files: ' + str(monitors_file_list))
|
||||
for monitor_file in monitors_file_list:
|
||||
monitor_configuration.read(monitor_file, 'utf-8')
|
||||
|
||||
kwargs = {}
|
||||
for option in monitor_configuration.options('args'):
|
||||
#print(option)
|
||||
value = monitor_configuration.get('args', option)
|
||||
kwargs[option] = value
|
||||
|
||||
print(monitor_group + ' ' + str(kwargs))
|
||||
|
||||
identifier = monitor_group + '_' + os.path.splitext(os.path.basename(
|
||||
monitor_file))[0]
|
||||
|
||||
# create Monitor() object and copy monitor_configuration for each instance because
|
||||
# they else refer to the same object.
|
||||
self.__monitors[identifier] = copy.deepcopy(Monitor(configuration, environment, identifier,
|
||||
self.__monitors[identifier] = Monitor(configuration, environment, identifier,
|
||||
copy.deepcopy(monitor_configuration),
|
||||
notifications, services, tasks))
|
||||
notifications, services, tasks,
|
||||
copy.deepcopy(kwargs))
|
||||
|
||||
del kwargs
|
||||
|
||||
def get_monitors(self):
|
||||
return self.__monitors
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from linspector.core.helpers import log
|
|||
|
||||
class Service:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__()
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return HTTPKeywordService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return HTTPKeywordService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class HTTPKeywordService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,17 +7,18 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return DummyService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return DummyService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class DummyService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
log('debug', __name__, 'dummy object @' + str(self))
|
||||
log('debug', __name__, 'dummy object @' + str(self) + str(self.__kwargs['foo']))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return RandomService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return RandomService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class RandomService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -9,17 +9,18 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return FritzboxUplinkService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return FritzboxUplinkService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class FritzboxUplinkService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
print('huhu')
|
||||
log('debug', __name__, 'dummy object @' + str(self))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return PingService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return PingService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class PingService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -9,16 +9,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return PortService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return PortService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class PortService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self, execution):
|
||||
|
||||
|
|
|
|||
|
|
@ -11,16 +11,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SpeedtestService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return SpeedtestService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class SpeedtestService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
self.__speedtest_maximum_speed = None
|
||||
self.__speedtest_average_speed = None
|
||||
|
|
|
|||
|
|
@ -11,16 +11,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SSHService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return SSHService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class SSHService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
|
||||
|
|
|
|||
|
|
@ -7,17 +7,18 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return TCPConnectService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return TCPConnectService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class TCPConnectService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -9,16 +9,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return GetService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return GetService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class GetService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return ShellService(configuration, environment)
|
||||
def create(configuration, environment, **kwargs):
|
||||
return ShellService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class ShellService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ from linspector.core.helpers import log
|
|||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return UptimeService(configuration, environment)
|
||||
def get(configuration, environment, **kwargs):
|
||||
return UptimeService(configuration, environment, **kwargs)
|
||||
|
||||
|
||||
class UptimeService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
super().__init__(configuration, environment, **kwargs)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__kwargs = kwargs
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue