Added dynamic plugin loading. Made all dict keys lowercase so configuation keys are not case sensitive. And even some fixes.
This commit is contained in:
parent
98fa44f6ff
commit
947a14bdde
9 changed files with 38 additions and 22 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
[httpserver]
|
||||
ip = 127.0.0.1
|
||||
port = 4242
|
||||
port = 4242
|
||||
type=thread
|
||||
2
etc/plugins/lish.conf
Normal file
2
etc/plugins/lish.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[lish]
|
||||
type=none
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ class LishPlugin:
|
|||
self.__linspector = linspector
|
||||
|
||||
def run(self):
|
||||
print('hello from Lish!')
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue