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
|
||||
; fixed. setting it like below works but is no good design for optional options. same for notifications.
|
||||
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
|
||||
user = USERNAME
|
||||
password = PASSWORD
|
||||
|
|
|
|||
|
|
@ -65,26 +65,20 @@ class Monitor:
|
|||
if notification_option not in notifications:
|
||||
notification_package = 'linspector.notifications.' + notification_option.lower()
|
||||
notification_module = importlib.import_module(notification_package)
|
||||
notification = getattr(notification_module, notification_option +
|
||||
'Notification')
|
||||
|
||||
notification.__init__(self, configuration, environment)
|
||||
notification = notification_module.get(configuration, environment)
|
||||
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 monitor_configuration.get('monitor', 'service') not in services:
|
||||
service_package = 'linspector.services.' + \
|
||||
monitor_configuration.get('monitor', 'service').lower()
|
||||
|
||||
service_module = importlib.import_module(service_package)
|
||||
service = getattr(service_module,
|
||||
monitor_configuration.get('monitor', 'service') + 'Service')
|
||||
|
||||
service.__init__(self, configuration, environment)
|
||||
service = service_module.get(configuration, environment)
|
||||
services[monitor_configuration.get('monitor', 'service')] = service
|
||||
#print(__file__ + ' (87): ' + str(services))
|
||||
#print(__file__ + ' (81): ' + str(services))
|
||||
|
||||
#service.execute(self)
|
||||
|
||||
|
|
@ -107,14 +101,13 @@ class Monitor:
|
|||
|
||||
for task_option in task_list.split(','):
|
||||
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_module = importlib.import_module(task_package)
|
||||
task = getattr(task_module, task_option + 'Task')
|
||||
task.__init__(self, configuration, environment)
|
||||
task = task_module.get(configuration, environment)
|
||||
tasks[task_option] = task
|
||||
|
||||
#print(__file__ + ' (117): ' + str(tasks))
|
||||
#print(__file__ + ' (110): ' + str(tasks))
|
||||
|
||||
def get_identifier(self):
|
||||
return self.__identifier
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return CallNotification(configuration, environment)
|
||||
|
||||
|
||||
class CallNotification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return EmailNotification(configuration, environment)
|
||||
|
||||
|
||||
class EmailNotification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return SMSNotification(configuration, environment)
|
||||
|
||||
|
||||
class SMSNotification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return TwitterNotification(configuration, environment)
|
||||
|
||||
|
||||
class TwitterNotification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return XMPPNotification(configuration, environment)
|
||||
|
||||
|
||||
class XMPPNotification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return HTTPServerPlugin(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class HTTPServerPlugin:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return LishPlugin(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class LishPlugin:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return DummyService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class DummyService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return FritzboxUplinkService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class FritzboxUplinkService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return HTTPKeywordService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class HTTPKeywordService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return PingService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class PingService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return PortService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class PortService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return RandomService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class RandomService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return ShellService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class ShellService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return SNMPGetService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SNMPGetService:
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return SpeedtestService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SpeedtestService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return SSHService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SSHService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return TCPConnectService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class TCPConnectService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return UptimeService(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class UptimeService:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return FileLoggerTask(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class FileLoggerTask:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return MariaDBTask(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class MariaDBTask:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return RedisTask(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class RedisTask:
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ from logging import getLogger
|
|||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return SQLiteTask(configuration, environment)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SQLiteTask:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue