Lot of optimizing and many fixes. Refactoring like every day... ;)
This commit is contained in:
parent
8d9ec5c73b
commit
8dcacfb4e5
5 changed files with 67 additions and 43 deletions
|
|
@ -13,7 +13,8 @@ plugins = HTTPServer
|
||||||
; a monitor then maybe only run tasks from the dedicated monitor. maybe it is a good idea to run global tasks in every
|
; a monitor then maybe only run tasks from the dedicated monitor. maybe it is a good idea to run global tasks in every
|
||||||
; monitor and the monitor can add tasks to the global settings... need to think about it.
|
; monitor and the monitor can add tasks to the global settings... need to think about it.
|
||||||
; tasks separated by ','. no whitespaces allowed
|
; tasks separated by ','. no whitespaces allowed
|
||||||
tasks = MariaDB,Logger
|
tasks = SQLite
|
||||||
|
notification = SMS
|
||||||
; maybe the run_mode is obsolete because this will be a daemon but maybe it is useful for one time execution?
|
; maybe the run_mode is obsolete because this will be a daemon but maybe it is useful for one time execution?
|
||||||
; in uplink the available run_modes were cron, daemon and foreground
|
; in uplink the available run_modes were cron, daemon and foreground
|
||||||
run_mode = cron
|
run_mode = cron
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
identifier = dsl
|
identifier = dsl
|
||||||
service = FritzboxUplink
|
service = FritzboxUplink
|
||||||
interval = 60
|
interval = 60
|
||||||
notifications = SMS,Email
|
notifications = Email
|
||||||
email_receivers = admin@example.com,fallback@example.com
|
email_receivers = admin@example.com,fallback@example.com
|
||||||
sms_receivers = +329084320984,+39804932409
|
sms_receivers = +329084320984,+39804932409
|
||||||
tasks = MariaDB
|
tasks = MariaDB,FileLogger
|
||||||
host = 192.168.1.1
|
host = 192.168.1.1
|
||||||
user = USERNAME
|
user = USERNAME
|
||||||
password = PASSWORD
|
password = PASSWORD
|
||||||
|
|
|
||||||
|
|
@ -36,64 +36,85 @@ class Monitor:
|
||||||
self.__environment = environment
|
self.__environment = environment
|
||||||
self.__identifier = identifier
|
self.__identifier = identifier
|
||||||
self.__monitor_configuration = monitor_configuration
|
self.__monitor_configuration = monitor_configuration
|
||||||
|
self.__notification_list = []
|
||||||
self.__notifications = notifications
|
self.__notifications = notifications
|
||||||
self.__services = services
|
self.__services = services
|
||||||
|
self.__task_list = [] # put tasks for the dedicated job here.
|
||||||
self.__tasks = tasks
|
self.__tasks = tasks
|
||||||
|
|
||||||
#print(__file__ + ' (43): ' + str(monitor_configuration))
|
if configuration.get_option('linspector', 'notifications') or \
|
||||||
|
monitor_configuration.get('monitor', 'notifications'):
|
||||||
|
|
||||||
|
if configuration.get_option('linspector', 'notifications') and \
|
||||||
|
monitor_configuration.get('monitor', 'notifications'):
|
||||||
|
|
||||||
|
notification_list = \
|
||||||
|
configuration.get_option('linspector', 'notifications') + ',' + \
|
||||||
|
monitor_configuration.get('monitor', 'notifications')
|
||||||
|
elif configuration.get_option('linspector', 'notifications'):
|
||||||
|
notification_list = configuration.get_option('linspector', 'notifications')
|
||||||
|
elif monitor_configuration.get('monitor', 'notifications'):
|
||||||
|
notification_list = monitor_configuration.get('monitor', 'notifications')
|
||||||
|
else:
|
||||||
|
notification_list = None
|
||||||
|
|
||||||
|
self.__notification_list = notification_list
|
||||||
|
|
||||||
|
for notification_option in notification_list.split(','):
|
||||||
|
#print(__file__ + ' (64): ' + str(notification_option))
|
||||||
|
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)
|
||||||
|
notifications[notification_option] = notification
|
||||||
|
#print(__file__ + ' (74): ' + str(notifications))
|
||||||
|
|
||||||
|
#print(__file__ + ' (75): ' + 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:
|
||||||
|
service_package = 'linspector.services.' + \
|
||||||
|
monitor_configuration.get('monitor', 'service').lower()
|
||||||
|
|
||||||
# TODO: the exception handling later!!!
|
service_module = importlib.import_module(service_package)
|
||||||
#try:
|
service = getattr(service_module,
|
||||||
service_package = 'linspector.services.' + \
|
monitor_configuration.get('monitor', 'service') + 'Service')
|
||||||
self.__monitor_configuration.get('monitor', 'service').lower()
|
|
||||||
service_module = importlib.import_module(service_package)
|
|
||||||
|
|
||||||
service = getattr(service_module,
|
service.__init__(self, configuration, environment)
|
||||||
self.__monitor_configuration.get('monitor', 'service') + 'Service')
|
services[monitor_configuration.get('monitor', 'service')] = service
|
||||||
service.__init__(self, configuration, environment)
|
#print(__file__ + ' (87): ' + str(services))
|
||||||
|
|
||||||
if self.__monitor_configuration.get('monitor', 'service') not in services:
|
|
||||||
services[self.__monitor_configuration.get('monitor', 'service')] = service
|
|
||||||
#print(__file__ + ' (58): ' + str(services))
|
|
||||||
#else:
|
|
||||||
# do some logging
|
|
||||||
|
|
||||||
#except ModuleNotFoundError as err:
|
|
||||||
# raise Exception('something went wrong when initializing a service. you are '
|
|
||||||
# 'using an unknown service in your monitor configuration '
|
|
||||||
# 'identified by: ' + identifier + '({0})'.format(err))
|
|
||||||
|
|
||||||
#service.execute(self)
|
#service.execute(self)
|
||||||
|
|
||||||
if self.__monitor_configuration.get('monitor', 'notifications'):
|
if configuration.get_option('linspector', 'tasks') or \
|
||||||
for notification_option in self.__monitor_configuration.get('monitor',
|
monitor_configuration.get('monitor', 'tasks'):
|
||||||
'notifications').split(','):
|
|
||||||
|
|
||||||
#print(__file__ + ' (73): ' + str(notification_option))
|
if configuration.get_option('linspector', 'tasks') and \
|
||||||
notification_package = 'linspector.notifications.' + notification_option.lower()
|
monitor_configuration.get('monitor', 'tasks'):
|
||||||
notification_module = importlib.import_module(notification_package)
|
|
||||||
|
|
||||||
notification = getattr(notification_module, notification_option + 'Notification')
|
task_list = configuration.get_option('linspector', 'tasks') + ',' + \
|
||||||
notification.__init__(self, configuration, environment)
|
monitor_configuration.get('monitor', 'tasks')
|
||||||
|
elif configuration.get_option('linspector', 'tasks'):
|
||||||
|
task_list = configuration.get_option('linspector', 'tasks')
|
||||||
|
elif monitor_configuration.get('monitor', 'tasks'):
|
||||||
|
task_list = monitor_configuration.get('monitor', 'tasks')
|
||||||
|
else:
|
||||||
|
task_list = None
|
||||||
|
|
||||||
if notification_option not in notifications:
|
self.task_list = task_list
|
||||||
notifications[notification_option] = notification
|
|
||||||
#print(__file__ + ' (82): ' + str(notifications))
|
|
||||||
|
|
||||||
if self.__monitor_configuration.get('monitor', 'tasks'):
|
|
||||||
for task_option in self.__monitor_configuration.get('monitor',
|
|
||||||
'tasks').split(','):
|
|
||||||
#print(__file__ + ' (87): ' + 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)
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
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)
|
||||||
tasks[task_option] = task
|
tasks[task_option] = task
|
||||||
#print(__file__ + ' (96): ' + str(tasks))
|
|
||||||
|
#print(__file__ + ' (117): ' + str(tasks))
|
||||||
|
|
||||||
def get_identifier(self):
|
def get_identifier(self):
|
||||||
return self.__identifier
|
return self.__identifier
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,4 @@ class RedisTask:
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
self.__configuration = configuration
|
self.__configuration = configuration
|
||||||
self.__environment = environment
|
self.__environment = environment
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,4 @@ class SQLiteTask:
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
self.__configuration = configuration
|
self.__configuration = configuration
|
||||||
self.__environment = environment
|
self.__environment = environment
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue