Fixed dynamic loading of notifications, tasks and service. My last implementation was wrong and ugly. Now it seems to be the pythonic way.
This commit is contained in:
parent
0d41077eb6
commit
c17b061fd0
25 changed files with 104 additions and 15 deletions
|
|
@ -13,6 +13,10 @@ sms_receivers = +329084320984,+39804932409
|
||||||
; setting to None fails. just do not set this option. currently i get an error when tasks is not set here. need to be
|
; setting to None fails. just do not set this option. currently i get an error when tasks is not set here. need to be
|
||||||
; fixed. setting it like below works but is no good design for optional options. same for notifications.
|
; fixed. setting it like below works but is no good design for optional options. same for notifications.
|
||||||
tasks = Redis
|
tasks = Redis
|
||||||
|
; maybe this should be some kind of range too, for example for the ping service like: 10.0.0.1-10.0.0.42 or more
|
||||||
|
; sophisticated kind of ranges... i will find a solution for that... like host groups in the old version of Linspector
|
||||||
|
; so we don't need to add a monitor for each host... but it would be a good idea to expose these hosts to become a
|
||||||
|
; monitor for each host internally. ;)
|
||||||
host = 192.168.0.1
|
host = 192.168.0.1
|
||||||
user = USERNAME
|
user = USERNAME
|
||||||
password = PASSWORD
|
password = PASSWORD
|
||||||
|
|
|
||||||
|
|
@ -65,26 +65,20 @@ class Monitor:
|
||||||
if notification_option not in notifications:
|
if notification_option not in notifications:
|
||||||
notification_package = 'linspector.notifications.' + notification_option.lower()
|
notification_package = 'linspector.notifications.' + notification_option.lower()
|
||||||
notification_module = importlib.import_module(notification_package)
|
notification_module = importlib.import_module(notification_package)
|
||||||
notification = getattr(notification_module, notification_option +
|
notification = notification_module.get(configuration, environment)
|
||||||
'Notification')
|
|
||||||
|
|
||||||
notification.__init__(self, configuration, environment)
|
|
||||||
notifications[notification_option] = notification
|
notifications[notification_option] = notification
|
||||||
#print(__file__ + ' (73): ' + str(notifications))
|
#print(__file__ + ' (70): ' + str(notifications))
|
||||||
|
|
||||||
#print(__file__ + ' (75): ' + str(monitor_configuration))
|
#print(__file__ + ' (72): ' + str(monitor_configuration))
|
||||||
if self.__monitor_configuration.get('monitor', 'service'):
|
if self.__monitor_configuration.get('monitor', 'service'):
|
||||||
if monitor_configuration.get('monitor', 'service') not in services:
|
if monitor_configuration.get('monitor', 'service') not in services:
|
||||||
service_package = 'linspector.services.' + \
|
service_package = 'linspector.services.' + \
|
||||||
monitor_configuration.get('monitor', 'service').lower()
|
monitor_configuration.get('monitor', 'service').lower()
|
||||||
|
|
||||||
service_module = importlib.import_module(service_package)
|
service_module = importlib.import_module(service_package)
|
||||||
service = getattr(service_module,
|
service = service_module.get(configuration, environment)
|
||||||
monitor_configuration.get('monitor', 'service') + 'Service')
|
|
||||||
|
|
||||||
service.__init__(self, configuration, environment)
|
|
||||||
services[monitor_configuration.get('monitor', 'service')] = service
|
services[monitor_configuration.get('monitor', 'service')] = service
|
||||||
#print(__file__ + ' (87): ' + str(services))
|
#print(__file__ + ' (81): ' + str(services))
|
||||||
|
|
||||||
#service.execute(self)
|
#service.execute(self)
|
||||||
|
|
||||||
|
|
@ -107,14 +101,13 @@ class Monitor:
|
||||||
|
|
||||||
for task_option in task_list.split(','):
|
for task_option in task_list.split(','):
|
||||||
if task_option not in tasks:
|
if task_option not in tasks:
|
||||||
#print(__file__ + ' (110): ' + str(task_option))
|
#print(__file__ + ' (104): ' + str(task_option))
|
||||||
task_package = 'linspector.tasks.' + task_option.lower()
|
task_package = 'linspector.tasks.' + task_option.lower()
|
||||||
task_module = importlib.import_module(task_package)
|
task_module = importlib.import_module(task_package)
|
||||||
task = getattr(task_module, task_option + 'Task')
|
task = task_module.get(configuration, environment)
|
||||||
task.__init__(self, configuration, environment)
|
|
||||||
tasks[task_option] = task
|
tasks[task_option] = task
|
||||||
|
|
||||||
#print(__file__ + ' (117): ' + str(tasks))
|
#print(__file__ + ' (110): ' + str(tasks))
|
||||||
|
|
||||||
def get_identifier(self):
|
def get_identifier(self):
|
||||||
return self.__identifier
|
return self.__identifier
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return CallNotification(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
class CallNotification:
|
class CallNotification:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return EmailNotification(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
class EmailNotification:
|
class EmailNotification:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return SMSNotification(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
class SMSNotification:
|
class SMSNotification:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return TwitterNotification(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
class TwitterNotification:
|
class TwitterNotification:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return XMPPNotification(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
class XMPPNotification:
|
class XMPPNotification:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return HTTPServerPlugin(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class HTTPServerPlugin:
|
class HTTPServerPlugin:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return LishPlugin(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class LishPlugin:
|
class LishPlugin:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return DummyService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class DummyService:
|
class DummyService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return FritzboxUplinkService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class FritzboxUplinkService:
|
class FritzboxUplinkService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return HTTPKeywordService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class HTTPKeywordService:
|
class HTTPKeywordService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return PingService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class PingService:
|
class PingService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return PortService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class PortService:
|
class PortService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return RandomService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class RandomService:
|
class RandomService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return ShellService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class ShellService:
|
class ShellService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return SNMPGetService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class SNMPGetService:
|
class SNMPGetService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return SpeedtestService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class SpeedtestService:
|
class SpeedtestService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return SSHService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class SSHService:
|
class SSHService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return TCPConnectService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class TCPConnectService:
|
class TCPConnectService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return UptimeService(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class UptimeService:
|
class UptimeService:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return FileLoggerTask(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class FileLoggerTask:
|
class FileLoggerTask:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return MariaDBTask(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class MariaDBTask:
|
class MariaDBTask:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return RedisTask(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class RedisTask:
|
class RedisTask:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
||||||
logger = getLogger('linspector')
|
logger = getLogger('linspector')
|
||||||
|
|
||||||
|
|
||||||
|
def get(configuration, environment):
|
||||||
|
return SQLiteTask(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class SQLiteTask:
|
class SQLiteTask:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue