diff --git a/bin/linspector b/bin/linspector index eb44d6a..1ccf34a 100755 --- a/bin/linspector +++ b/bin/linspector @@ -35,7 +35,6 @@ from logging import getLogger from linspector.core.configuration import Configuration from linspector.core.environment import Environment from linspector.core.linspector import Linspector -from linspector.core.linspectord import Linspectord from linspector.core.monitors import Monitors __version__ = '0.1' @@ -80,8 +79,8 @@ def main(): except Exception as err: logger.warning('[linspector] monitor initialization error: {0}'.format(err)) - linspector = Linspector(configuration, environment, monitors) - #linspector.print_debug() + linspector = Linspector(configuration, environment, monitors, plugins) + linspector.print_debug() # so, if Linspector should start in Daemon mode, do it here... #Linspectord(configuration, environment, linspector).execute() diff --git a/etc/linspector.conf b/etc/linspector.conf index e55965d..c1ae0c0 100644 --- a/etc/linspector.conf +++ b/etc/linspector.conf @@ -8,12 +8,12 @@ log_count = 5 log_size = 10485760 pid_file = /var/run/user/1000/linspector.pid ; plugins separated by ','. no whitespaces allowed -plugins = Lish +plugins = lish,httpserver ; globally configured tasks will always run on all monitors when no task is configured there. if tasks are configured in ; 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. ; tasks separated by ','. no whitespaces allowed -tasks = SQLite +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? ; in uplink the available run_modes were cron, daemon and foreground diff --git a/etc/monitors/network1/gateway.conf b/etc/monitors/network1/gateway.conf index ea0c593..eb6b009 100644 --- a/etc/monitors/network1/gateway.conf +++ b/etc/monitors/network1/gateway.conf @@ -1,10 +1,10 @@ [monitor] ; currently i get errors when the service option is not spelled correct. error handling need to fix this. same for ; notifications and tasks. -service = FritzboxUplink +service = fritzboxuplink interval = 60 -; notifications separated by ','. no whitespaces allowed -notifications = SMS,Email +; notifications separated by ','. no whitespaces allowed. the case is not important. +notifications = sMs,Email ; values from main configuration can be overridden for each defined monitor ; email_receivers separated by ','. no whitespaces allowed email_receivers = admin@example.com,fallback@example.com @@ -12,7 +12,7 @@ email_receivers = admin@example.com,fallback@example.com 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 +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 diff --git a/etc/plugins/httpserver.conf b/etc/plugins/httpserver.conf index b832680..ea8f0b9 100644 --- a/etc/plugins/httpserver.conf +++ b/etc/plugins/httpserver.conf @@ -1,3 +1,4 @@ [httpserver] ip = 127.0.0.1 -port = 4242 \ No newline at end of file +port = 4242 +type=thread \ No newline at end of file diff --git a/etc/plugins/lish.conf b/etc/plugins/lish.conf new file mode 100644 index 0000000..a40fd32 --- /dev/null +++ b/etc/plugins/lish.conf @@ -0,0 +1,2 @@ +[lish] +type=none \ No newline at end of file diff --git a/linspector/core/linspector.py b/linspector/core/linspector.py index 44b07a6..dcaeb7a 100644 --- a/linspector/core/linspector.py +++ b/linspector/core/linspector.py @@ -20,6 +20,7 @@ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ +import importlib from logging import getLogger @@ -28,16 +29,29 @@ logger = getLogger('linspector') class Linspector: - def __init__(self, configuration, environment, monitors): + def __init__(self, configuration, environment, monitors, plugins): self.__configuration = configuration self.__environment = environment self.__monitors = monitors + self.__plugin_list = None + self.__plugins = plugins + + # load plugins + if configuration.get_option('linspector', 'plugins'): + plugin_list = configuration.get_option('linspector', 'plugins') + self.__plugin_list = plugin_list.split(',') + for plugin_option in plugin_list.split(','): + if plugin_option not in plugins: + plugin_package = 'linspector.plugins.' + plugin_option.lower() + plugin_module = importlib.import_module(plugin_package) + plugin = plugin_module.get(configuration, environment, self) + plugins[plugin_option.lower()] = plugin # this function is just for testing purposes and can be removed some day def print_debug(self): # example on how to access the monitor objects in monitors monitors = self.__monitors.get_monitors() - print(__file__ + ' (40): ' + str(monitors)) + print(__file__ + ' (59): ' + str(monitors)) for monitor in monitors: - print(__file__ + ' (42): ' + monitors.get(monitor).get_identifier()) - print(__file__ + ' (43): ' + monitors.get(monitor).get_service()) + print(__file__ + ' (61): ' + monitors.get(monitor).get_identifier()) + print(__file__ + ' (62): ' + monitors.get(monitor).get_service()) diff --git a/linspector/core/monitor.py b/linspector/core/monitor.py index 992b529..c5d6602 100644 --- a/linspector/core/monitor.py +++ b/linspector/core/monitor.py @@ -58,7 +58,7 @@ class Monitor: else: notification_list = None - self.__notification_list = notification_list + self.__notification_list = notification_list.split(',') for notification_option in notification_list.split(','): #print(__file__ + ' (64): ' + str(notification_option)) @@ -66,7 +66,7 @@ class Monitor: notification_package = 'linspector.notifications.' + notification_option.lower() notification_module = importlib.import_module(notification_package) notification = notification_module.get(configuration, environment) - notifications[notification_option] = notification + notifications[notification_option.lower()] = notification #print(__file__ + ' (70): ' + str(notifications)) #print(__file__ + ' (72): ' + str(monitor_configuration)) @@ -77,7 +77,7 @@ class Monitor: service_module = importlib.import_module(service_package) service = service_module.get(configuration, environment) - services[monitor_configuration.get('monitor', 'service')] = service + services[monitor_configuration.get('monitor', 'service').lower()] = service #print(__file__ + ' (81): ' + str(services)) #service.execute(self) @@ -97,7 +97,7 @@ class Monitor: else: task_list = None - self.task_list = task_list + self.task_list = task_list.split(',') for task_option in task_list.split(','): if task_option not in tasks: @@ -105,7 +105,7 @@ class Monitor: task_package = 'linspector.tasks.' + task_option.lower() task_module = importlib.import_module(task_package) task = task_module.get(configuration, environment) - tasks[task_option] = task + tasks[task_option.lower()] = task #print(__file__ + ' (110): ' + str(tasks)) diff --git a/linspector/core/monitors.py b/linspector/core/monitors.py index f362a88..130daa3 100644 --- a/linspector/core/monitors.py +++ b/linspector/core/monitors.py @@ -20,15 +20,15 @@ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - import configparser import copy import glob import os -from linspector.core.monitor import Monitor from logging import getLogger +from linspector.core.monitor import Monitor + logger = getLogger('linspector') diff --git a/linspector/plugins/lish.py b/linspector/plugins/lish.py index 8e3499a..84a447a 100644 --- a/linspector/plugins/lish.py +++ b/linspector/plugins/lish.py @@ -39,4 +39,4 @@ class LishPlugin: self.__linspector = linspector def run(self): - print('hello from Lish!') + return