Some more logging stuff. log is now a global function as argument.
Don't know if it is good, but it made things easier to me.
This commit is contained in:
parent
e665933bfb
commit
7e228a3196
33 changed files with 188 additions and 204 deletions
|
|
@ -29,16 +29,17 @@ import sys
|
|||
|
||||
from linspector.core.configuration import Configuration
|
||||
from linspector.core.environment import Environment
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.linspector import Linspector
|
||||
from linspector.core.monitors import Monitors
|
||||
|
||||
logger = logging.getLogger('linspector')
|
||||
|
||||
# i currently only increase the 3rd number because the goal is that 0.19 will become the first
|
||||
# stable version.
|
||||
__version__ = '0.19.30.dev1'
|
||||
__version__ = '0.19.31.dev1'
|
||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||
|
||||
logger = logging.getLogger('linspector')
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
|
|
@ -95,7 +96,7 @@ def main():
|
|||
logger.addHandler(stdout_handler)
|
||||
|
||||
try:
|
||||
configuration = Configuration(args.configuration_path, environment)
|
||||
configuration = Configuration(args.configuration_path, environment, log)
|
||||
logger.debug('configuration dump: ' + configuration.dump_to_ini())
|
||||
except Exception as err:
|
||||
logger.critical('[linspector] configuration error: {0}'.format(err))
|
||||
|
|
@ -132,25 +133,30 @@ def main():
|
|||
log_file_handler.setFormatter(log_file_formatter)
|
||||
logger.addHandler(log_file_handler)
|
||||
|
||||
log_level = 'None'
|
||||
# critical errors will always show up even when no log_level is set. this is most silent.
|
||||
logger.setLevel(logging.CRITICAL)
|
||||
log_level = configuration.get_option('linspector', 'log_level')
|
||||
if log_level == "error":
|
||||
logger.setLevel(logging.ERROR)
|
||||
elif log_level == "warning":
|
||||
logger.setLevel(logging.WARNING)
|
||||
elif log_level == "info":
|
||||
logger.setLevel(logging.INFO)
|
||||
elif log_level == "debug":
|
||||
logger.setLevel(logging.DEBUG)
|
||||
if configuration.get_option('linspector', 'log_level'):
|
||||
log_level = str(configuration.get_option('linspector', 'log_level'))
|
||||
if log_level == "error":
|
||||
logger.setLevel(logging.ERROR)
|
||||
elif log_level == "warning":
|
||||
logger.setLevel(logging.WARNING)
|
||||
elif log_level == "info":
|
||||
logger.setLevel(logging.INFO)
|
||||
elif log_level == "debug":
|
||||
logger.setLevel(logging.DEBUG)
|
||||
#elif configuration.get_option('linspector', 'log_level') != 'error' != 'warning' \
|
||||
# != 'info' != 'debug':
|
||||
# logger.warning('[linspector] log level: "' + log_level + '" not found!')
|
||||
|
||||
try:
|
||||
monitors = Monitors(configuration, environment, notifications, services, tasks)
|
||||
monitors = Monitors(configuration, environment, log, notifications, services, tasks)
|
||||
except Exception as err:
|
||||
logger.warning('[linspector] monitor initialization error: {0}'.format(err))
|
||||
|
||||
try:
|
||||
linspector = Linspector(configuration, environment, monitors, plugins, scheduler)
|
||||
linspector = Linspector(configuration, environment, log, monitors, plugins, scheduler)
|
||||
#linspector.print_debug()
|
||||
except Exception as err:
|
||||
logger.critical('[linspector] core initialization error: {0}'.format(err))
|
||||
|
|
|
|||
|
|
@ -2,24 +2,24 @@
|
|||
[linspector]
|
||||
; report core errors to the following users
|
||||
error_receivers = admin@example.com
|
||||
; available log levels are: "error", "warning", "info" and "debug".
|
||||
; available log levels are: "error", "warning", "info" and "debug". if no log_level is set, it will be critical only.
|
||||
log_level= debug
|
||||
log_file = ~/code/linspector/linspector/log/linspector.log
|
||||
; number of log files to be kept. i recommend to use the lowest sensible value for keeping performance hight. so set
|
||||
; number of log files to be kept. i recommend to use the lowest sensible value for keeping performance high. so set
|
||||
; the size of the log file higher to increase the log history.
|
||||
log_file_count = 50
|
||||
log_file_count = 25
|
||||
; log file size in megabytes as float.
|
||||
log_file_size = 1
|
||||
;log_file_size = 1
|
||||
; log file size in bytes as int. you can set to bytes if you want to set a value lower then 1 megabyte. but it will
|
||||
; only be used when log_file_size is not set.
|
||||
log_file_size_bytes = 10485760
|
||||
;log_file_size_bytes = 10485760
|
||||
pid_file = /var/run/user/1000/linspector.pid
|
||||
; plugins separated by ','. no whitespaces allowed. not case sensitive.
|
||||
; plugins separated by ','. no whitespaces allowed! not case sensitive.
|
||||
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 separated by ','. no whitespaces allowed! not case sensitive.
|
||||
tasks = SQLite
|
||||
notifications = SMS
|
||||
; maybe the run_mode is obsolete because this will be a daemon but maybe it is useful for one time execution?
|
||||
|
|
@ -37,8 +37,9 @@ start_scheduler = true
|
|||
scheduler_mode = process
|
||||
max_threads = 2048
|
||||
; i recommend to set this to your number of CPU cores available when running on a dedicated Linspector host. but if the
|
||||
; system is running other services you should lower this value when you have too high CPU load.
|
||||
max_processes = 24
|
||||
; system is running other services you should lower this value when you have too high CPU load. if you have enough
|
||||
; resources this value really can be higher then your available CPU cores.
|
||||
max_processes = 48
|
||||
; if timezone is not set, UTC is used by default.
|
||||
timezone = CET
|
||||
; this is for scheduling jobs to not run all at the same time. this should be set to the lowest interval you use. it
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
description = Cable Provider
|
||||
service = net.fritzboxuplink
|
||||
hosts = 192.168.0.1,192.168.23.24,@group1,@testgroup1
|
||||
; this only depends on the SLA you made with the product owner.
|
||||
interval = 60
|
||||
|
||||
; optional options when using notifications, plugins, services or tasks. btw. they still can be a required argument by
|
||||
|
|
|
|||
|
|
@ -7,17 +7,16 @@ import configparser
|
|||
import glob
|
||||
import os
|
||||
|
||||
from linspector.core.helpers import log
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed. do this only for
|
||||
# options in the "linspector" section of linspector.ini.
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, configuration_path, environment):
|
||||
def __init__(self, configuration_path, environment, log):
|
||||
self.__configuration = configparser.ConfigParser()
|
||||
self.__configuration_path = configuration_path
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
log('info', 'reading configuration file: ' + configuration_path + '/linspector.conf')
|
||||
if os.path.isfile(configuration_path + '/linspector.conf'):
|
||||
|
|
@ -38,7 +37,7 @@ class Configuration:
|
|||
|
||||
section_list = glob.glob(configuration_path + '/' + target_section + '/*.conf')
|
||||
for section_file in section_list:
|
||||
#print(__file__ + ' (45): ' + section_file)
|
||||
log('debug', 'reading section file: ' + section_file)
|
||||
configuration = configparser.ConfigParser()
|
||||
configuration.read(section_file, 'utf-8')
|
||||
for source_section in configuration.sections():
|
||||
|
|
|
|||
|
|
@ -11,19 +11,17 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
|||
from apscheduler.jobstores.memory import MemoryJobStore
|
||||
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
|
||||
|
||||
from linspector.core.helpers import log
|
||||
|
||||
|
||||
def job_function(monitor):
|
||||
monitor.handle_call()
|
||||
|
||||
|
||||
class Linspector:
|
||||
|
||||
def __init__(self, configuration, environment, monitors, plugins, scheduler):
|
||||
def __init__(self, configuration, environment, log, monitors, plugins, scheduler):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__jobs = []
|
||||
self.__log = log
|
||||
self.__monitors = monitors
|
||||
self.__plugin_list = []
|
||||
self.__plugins = plugins
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@ import importlib
|
|||
from datetime import datetime
|
||||
from binascii import crc32
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task, TaskExecutor
|
||||
|
||||
|
||||
class Monitor:
|
||||
|
||||
def __init__(self, configuration, environment, identifier, monitor_configuration, notifications,
|
||||
services, tasks, kwargs):
|
||||
def __init__(self, configuration, environment, identifier, log, monitor_configuration,
|
||||
notifications, services, tasks, kwargs):
|
||||
self.__args = kwargs
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__identifier = identifier
|
||||
self.__interval = int(monitor_configuration.get('monitor', 'interval'))
|
||||
self.__log = log
|
||||
self.__monitor_configuration = monitor_configuration
|
||||
self.__notification_list = []
|
||||
self.__notifications = notifications
|
||||
|
|
@ -30,7 +30,6 @@ class Monitor:
|
|||
self.__services = services
|
||||
self.__task_list = [] # put tasks for the dedicated job here.
|
||||
self.__tasks = tasks
|
||||
|
||||
self.service = self.__service
|
||||
self.host = monitor_configuration.get('monitor', 'hosts')
|
||||
|
||||
|
|
@ -83,7 +82,7 @@ class Monitor:
|
|||
if notification_option not in notifications:
|
||||
notification_package = 'linspector.notifications.' + notification_option.lower()
|
||||
notification_module = importlib.import_module(notification_package)
|
||||
notification = notification_module.create(configuration, environment)
|
||||
notification = notification_module.create(configuration, environment, log)
|
||||
notifications[notification_option.lower()] = notification
|
||||
except configparser.NoOptionError as err:
|
||||
self.__notifications = notifications
|
||||
|
|
@ -95,7 +94,7 @@ class Monitor:
|
|||
|
||||
service_module = importlib.import_module(service_package)
|
||||
self.__service = monitor_configuration.get('monitor', 'service').lower()
|
||||
service = service_module.create(configuration, environment)
|
||||
service = service_module.create(configuration, environment, log)
|
||||
self.__services[monitor_configuration.get('monitor', 'service').lower()] = service
|
||||
try:
|
||||
if configuration.get_option('linspector', 'tasks') or \
|
||||
|
|
@ -119,7 +118,7 @@ class Monitor:
|
|||
if task_option not in tasks:
|
||||
task_package = 'linspector.tasks.' + task_option.lower()
|
||||
task_module = importlib.import_module(task_package)
|
||||
task = task_module.create(configuration, environment)
|
||||
task = task_module.create(configuration, environment, log)
|
||||
tasks[task_option.lower()] = task
|
||||
except configparser.NoOptionError:
|
||||
self.__tasks = tasks
|
||||
|
|
@ -194,13 +193,13 @@ class Monitor:
|
|||
def handle_tasks(self, monitor_information):
|
||||
for task in self.__tasks:
|
||||
if self.status.lower() in task.get_task_type().lower():
|
||||
log('debug', 'executing task of type: ' + self.status)
|
||||
self.__log('debug', 'executing task of type: ' + self.status)
|
||||
# tasks can but should not be executed here. putting them in a queue is the better
|
||||
# solution to execute them in a serial process.
|
||||
#TaskExecutor.instance().schedule_task(monitor_information, task)
|
||||
|
||||
def handle_call(self):
|
||||
log('info', 'handle call to monitor with identifier: ' + self.__identifier)
|
||||
self.__log('info', 'handle call to monitor with identifier: ' + self.__identifier)
|
||||
#logger.debug("handle call")
|
||||
#logger.debug(self.service)
|
||||
if self.enabled:
|
||||
|
|
@ -210,7 +209,7 @@ class Monitor:
|
|||
#self.__services[self.__service].execute(self.last_execution)
|
||||
self.__services[self.__service].execute(**self.__args)
|
||||
except Exception as err:
|
||||
log('error', err)
|
||||
self.__log('error', err)
|
||||
|
||||
#self.last_execution.set_execution_end()
|
||||
|
||||
|
|
@ -226,7 +225,7 @@ class Monitor:
|
|||
|
||||
#self.handle_tasks(self.monitor_information)
|
||||
else:
|
||||
log('info', "job " + self.get_job_id() + " disabled")
|
||||
self.__log('info', "job " + self.get_job_id() + " disabled")
|
||||
|
||||
def get_host(self):
|
||||
return self.host
|
||||
|
|
|
|||
|
|
@ -9,17 +9,16 @@ import glob
|
|||
import os
|
||||
|
||||
from linspector.core.monitor import Monitor
|
||||
from linspector.core.helpers import log
|
||||
|
||||
|
||||
# monitors may could / should be added (and maybe changed) at runtime to add new monitors without
|
||||
# restarting the daemon. maybe add a reset function to each monitor to reset the monitor at runtime
|
||||
# when changed dynamically.
|
||||
class Monitors:
|
||||
|
||||
def __init__(self, configuration, environment, notifications, services, tasks):
|
||||
def __init__(self, configuration, environment, log, notifications, services, tasks):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
self.__monitors = {}
|
||||
|
||||
monitor_groups = os.listdir(self.__configuration.get_configuration_path() + '/monitors/')
|
||||
|
|
@ -39,7 +38,9 @@ class Monitors:
|
|||
kwargs = {}
|
||||
for option in monitor_configuration.options('args'):
|
||||
value = monitor_configuration.get('args', option)
|
||||
#log('debug', 'added option to kwargs: ' + option + ' = ' + value)
|
||||
log('debug', 'added option in ' + identifier + ' to kwargs: ' + option + ' = '
|
||||
+ value)
|
||||
|
||||
kwargs[option] = value
|
||||
|
||||
if kwargs:
|
||||
|
|
@ -51,7 +52,7 @@ class Monitors:
|
|||
# create Monitor() object and copy monitor_configuration for each instance because
|
||||
# they else refer to the same object.
|
||||
self.__monitors[identifier] = Monitor(configuration, environment, identifier,
|
||||
monitor_configuration, notifications,
|
||||
log, monitor_configuration, notifications,
|
||||
services, tasks, copy.deepcopy(kwargs))
|
||||
|
||||
del kwargs
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
|
||||
|
||||
class Notification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__()
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
|
||||
|
||||
class Service:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
def __init__(self, configuration, environment, log):
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ See LICENSE (MIT license)
|
|||
from queue import Queue
|
||||
from threading import Event, Thread
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.singleton import Singleton
|
||||
|
||||
KEY_TYPE = "type"
|
||||
|
|
@ -15,11 +14,12 @@ KEY_CLASS = "class"
|
|||
|
||||
|
||||
class Task:
|
||||
def __init__(self, configuration, environment, **kwargs):
|
||||
def __init__(self, configuration, environment, log, **kwargs):
|
||||
self._args = {}
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
self.__log = log
|
||||
|
||||
self._args = {}
|
||||
if KEY_ARGS in kwargs:
|
||||
self.add_arguments(kwargs[KEY_ARGS])
|
||||
elif self.needs_arguments():
|
||||
|
|
@ -66,7 +66,10 @@ class Task:
|
|||
# when tasks are being implemented.
|
||||
@Singleton
|
||||
class TaskExecutor:
|
||||
def __init__(self):
|
||||
def __init__(self, configuration, environment, log):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
self.queue = Queue()
|
||||
self.taskInfos = []
|
||||
task_thread = Thread(target=self._run_worker_thread)
|
||||
|
|
@ -81,12 +84,12 @@ class TaskExecutor:
|
|||
try:
|
||||
msg, task = self.queue.get()
|
||||
if task:
|
||||
log('debug', "starting task execution...")
|
||||
self.__log('debug', "starting task execution...")
|
||||
#task.execute(msg)
|
||||
self.queue.task_done()
|
||||
|
||||
except Exception as err:
|
||||
log('error', "error " + str(err))
|
||||
self.__log('error', "error " + str(err))
|
||||
|
||||
def is_instant_end(self):
|
||||
return self._instantEnd
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return CallNotification(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return CallNotification(configuration, environment, log)
|
||||
|
||||
|
||||
class CallNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return EmailNotification(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return EmailNotification(configuration, environment, log)
|
||||
|
||||
|
||||
class EmailNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ See LICENSE (MIT license)
|
|||
"""
|
||||
import gammu
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SMSNotification(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return SMSNotification(configuration, environment, log)
|
||||
|
||||
|
||||
class SMSNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return TwitterNotification(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return TwitterNotification(configuration, environment, log)
|
||||
|
||||
|
||||
class TwitterNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ See LICENSE (MIT license)
|
|||
"""
|
||||
import xmpp
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return XMPPNotification(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return XMPPNotification(configuration, environment, log)
|
||||
|
||||
|
||||
class XMPPNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return HTTPKeywordService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return HTTPKeywordService(configuration, environment, log)
|
||||
|
||||
|
||||
class HTTPKeywordService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,22 +3,21 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return DummyService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return DummyService(configuration, environment, log)
|
||||
|
||||
|
||||
class DummyService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
log('debug', 'DummyService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
self.__log('debug', 'DummyService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
#log('debug', 'dummy object @' + str(self) + str(self.__kwargs['foo']))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return RandomService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return RandomService(configuration, environment, log)
|
||||
|
||||
|
||||
class RandomService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,21 +5,20 @@ See LICENSE (MIT)
|
|||
"""
|
||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return FritzboxPhoneStatusService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return FritzboxPhoneStatusService(configuration, environment, log)
|
||||
|
||||
|
||||
class FritzboxPhoneStatusService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
log('debug', 'FritzboxPhoneStatusService object ' + str(self))
|
||||
self.__log('debug', 'FritzboxPhoneStatusService object ' + str(self))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,21 +5,20 @@ See LICENSE (MIT)
|
|||
"""
|
||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return FritzboxUplinkService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return FritzboxUplinkService(configuration, environment, log)
|
||||
|
||||
|
||||
class FritzboxUplinkService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
log('debug', 'FritzboxUplinkService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
self.__log('debug', 'FritzboxUplinkService object ' + str(self) + ' using kwargs: ' + str(kwargs))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return PingService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return PingService(configuration, environment, log)
|
||||
|
||||
|
||||
class PingService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,20 +5,19 @@ See LICENSE (MIT license)
|
|||
"""
|
||||
import socket
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return PortService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return PortService(configuration, environment, log)
|
||||
|
||||
|
||||
class PortService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, execution, **kwargs):
|
||||
|
||||
|
|
|
|||
|
|
@ -7,20 +7,19 @@ import calendar
|
|||
import requests
|
||||
import time
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SpeedtestService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return SpeedtestService(configuration, environment, log)
|
||||
|
||||
|
||||
class SpeedtestService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
self.__speedtest_maximum_speed = None
|
||||
self.__speedtest_average_speed = None
|
||||
|
|
@ -65,10 +64,10 @@ class SpeedtestService(Service):
|
|||
self.__speedtest_time_elapsed = time.perf_counter() - start
|
||||
self.__environment.set_env_var('_speedtest_time_elapsed',
|
||||
str(self.__speedtest_time_elapsed))
|
||||
logger.info('speedtest average: ' + str(self.__speedtest_average_speed) +
|
||||
', max: ' + str(self.__speedtest_maximum_speed) +
|
||||
', time: ' + str(self.__speedtest_time_elapsed))
|
||||
self.__log('info', 'speedtest average: ' + str(self.__speedtest_average_speed) +
|
||||
', max: ' + str(self.__speedtest_maximum_speed) +
|
||||
', time: ' + str(self.__speedtest_time_elapsed))
|
||||
else:
|
||||
logger.warning('could not calculate download speed!')
|
||||
self.__log('warning', 'could not calculate download speed!')
|
||||
|
||||
time.sleep(self.__configuration.get_speedtest_interval())
|
||||
|
|
|
|||
|
|
@ -7,20 +7,19 @@ import os
|
|||
import paramiko
|
||||
import pprint
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SSHService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return SSHService(configuration, environment, log)
|
||||
|
||||
|
||||
class SSHService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')
|
||||
|
|
|
|||
|
|
@ -3,21 +3,20 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return TCPConnectService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return TCPConnectService(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class TCPConnectService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -5,20 +5,19 @@ See LICENSE (MIT license)
|
|||
"""
|
||||
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return GetService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return GetService(configuration, environment, log)
|
||||
|
||||
|
||||
class GetService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,21 +3,19 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return ShellService(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return ShellService(configuration, environment, log)
|
||||
|
||||
|
||||
class ShellService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.service import Service
|
||||
|
||||
|
||||
def get(configuration, environment):
|
||||
return UptimeService(configuration, environment)
|
||||
def get(configuration, environment, log):
|
||||
return UptimeService(configuration, environment, log)
|
||||
|
||||
|
||||
class UptimeService(Service):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
||||
def execute(self, **kwargs):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return CSVTask(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return CSVTask(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class CSVTask(Task):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return FileLoggerTask(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return FileLoggerTask(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class FileLoggerTask(Task):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return MariaDBTask(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return MariaDBTask(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class MariaDBTask(Task):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return RedisTask(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return RedisTask(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class RedisTask(Task):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@ This file is part of Linspector (https://linspector.org/)
|
|||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||
See LICENSE (MIT license)
|
||||
"""
|
||||
from linspector.core.helpers import log
|
||||
from linspector.core.task import Task
|
||||
|
||||
|
||||
def create(configuration, environment):
|
||||
return SQLiteTask(configuration, environment)
|
||||
def create(configuration, environment, log):
|
||||
return SQLiteTask(configuration, environment, log)
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SQLiteTask(Task):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
self.__log = log
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue