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:
Johannes Findeisen 2022-10-06 02:42:15 +02:00
commit 7e228a3196
33 changed files with 188 additions and 204 deletions

View file

@ -29,16 +29,17 @@ import sys
from linspector.core.configuration import Configuration from linspector.core.configuration import Configuration
from linspector.core.environment import Environment from linspector.core.environment import Environment
from linspector.core.helpers import log
from linspector.core.linspector import Linspector from linspector.core.linspector import Linspector
from linspector.core.monitors import Monitors 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 # i currently only increase the 3rd number because the goal is that 0.19 will become the first
# stable version. # stable version.
__version__ = '0.19.30.dev1' __version__ = '0.19.31.dev1'
__author__ = 'Johannes Findeisen <you@hanez.org>' __author__ = 'Johannes Findeisen <you@hanez.org>'
logger = logging.getLogger('linspector')
def parse_args(): def parse_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@ -95,7 +96,7 @@ def main():
logger.addHandler(stdout_handler) logger.addHandler(stdout_handler)
try: try:
configuration = Configuration(args.configuration_path, environment) configuration = Configuration(args.configuration_path, environment, log)
logger.debug('configuration dump: ' + configuration.dump_to_ini()) logger.debug('configuration dump: ' + configuration.dump_to_ini())
except Exception as err: except Exception as err:
logger.critical('[linspector] configuration error: {0}'.format(err)) logger.critical('[linspector] configuration error: {0}'.format(err))
@ -132,25 +133,30 @@ def main():
log_file_handler.setFormatter(log_file_formatter) log_file_handler.setFormatter(log_file_formatter)
logger.addHandler(log_file_handler) 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. # critical errors will always show up even when no log_level is set. this is most silent.
logger.setLevel(logging.CRITICAL) logger.setLevel(logging.CRITICAL)
log_level = configuration.get_option('linspector', 'log_level') if configuration.get_option('linspector', 'log_level'):
if log_level == "error": log_level = str(configuration.get_option('linspector', 'log_level'))
logger.setLevel(logging.ERROR) if log_level == "error":
elif log_level == "warning": logger.setLevel(logging.ERROR)
logger.setLevel(logging.WARNING) elif log_level == "warning":
elif log_level == "info": logger.setLevel(logging.WARNING)
logger.setLevel(logging.INFO) elif log_level == "info":
elif log_level == "debug": logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG) 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: try:
monitors = Monitors(configuration, environment, notifications, services, tasks) monitors = Monitors(configuration, environment, log, notifications, services, tasks)
except Exception as err: except Exception as err:
logger.warning('[linspector] monitor initialization error: {0}'.format(err)) logger.warning('[linspector] monitor initialization error: {0}'.format(err))
try: try:
linspector = Linspector(configuration, environment, monitors, plugins, scheduler) linspector = Linspector(configuration, environment, log, monitors, plugins, scheduler)
#linspector.print_debug() #linspector.print_debug()
except Exception as err: except Exception as err:
logger.critical('[linspector] core initialization error: {0}'.format(err)) logger.critical('[linspector] core initialization error: {0}'.format(err))

View file

@ -2,24 +2,24 @@
[linspector] [linspector]
; report core errors to the following users ; report core errors to the following users
error_receivers = admin@example.com 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_level= debug
log_file = ~/code/linspector/linspector/log/linspector.log 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. ; 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 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 ; 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. ; 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 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 plugins = Lish,HTTPServer
; globally configured tasks will always run on all monitors when no task is configured there. if tasks are configured in ; 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 ; 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! not case sensitive.
tasks = SQLite tasks = SQLite
notifications = SMS notifications = 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?
@ -37,8 +37,9 @@ start_scheduler = true
scheduler_mode = process scheduler_mode = process
max_threads = 2048 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 ; 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. ; system is running other services you should lower this value when you have too high CPU load. if you have enough
max_processes = 24 ; 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. ; if timezone is not set, UTC is used by default.
timezone = CET 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 ; this is for scheduling jobs to not run all at the same time. this should be set to the lowest interval you use. it

View file

@ -5,6 +5,7 @@
description = Cable Provider description = Cable Provider
service = net.fritzboxuplink service = net.fritzboxuplink
hosts = 192.168.0.1,192.168.23.24,@group1,@testgroup1 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 interval = 60
; optional options when using notifications, plugins, services or tasks. btw. they still can be a required argument by ; optional options when using notifications, plugins, services or tasks. btw. they still can be a required argument by

View file

@ -7,17 +7,16 @@ import configparser
import glob import glob
import os import os
from linspector.core.helpers import log
# TODO: check for all required configuration options and set defaults if needed. do this only for # TODO: check for all required configuration options and set defaults if needed. do this only for
# options in the "linspector" section of linspector.ini. # options in the "linspector" section of linspector.ini.
class Configuration: class Configuration:
def __init__(self, configuration_path, environment): def __init__(self, configuration_path, environment, log):
self.__configuration = configparser.ConfigParser() self.__configuration = configparser.ConfigParser()
self.__configuration_path = configuration_path self.__configuration_path = configuration_path
self.__environment = environment self.__environment = environment
self.__log = log
log('info', 'reading configuration file: ' + configuration_path + '/linspector.conf') log('info', 'reading configuration file: ' + configuration_path + '/linspector.conf')
if os.path.isfile(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') section_list = glob.glob(configuration_path + '/' + target_section + '/*.conf')
for section_file in section_list: for section_file in section_list:
#print(__file__ + ' (45): ' + section_file) log('debug', 'reading section file: ' + section_file)
configuration = configparser.ConfigParser() configuration = configparser.ConfigParser()
configuration.read(section_file, 'utf-8') configuration.read(section_file, 'utf-8')
for source_section in configuration.sections(): for source_section in configuration.sections():

View file

@ -11,19 +11,17 @@ from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from linspector.core.helpers import log
def job_function(monitor): def job_function(monitor):
monitor.handle_call() monitor.handle_call()
class Linspector: class Linspector:
def __init__(self, configuration, environment, log, monitors, plugins, scheduler):
def __init__(self, configuration, environment, monitors, plugins, scheduler):
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__jobs = [] self.__jobs = []
self.__log = log
self.__monitors = monitors self.__monitors = monitors
self.__plugin_list = [] self.__plugin_list = []
self.__plugins = plugins self.__plugins = plugins

View file

@ -10,19 +10,19 @@ import importlib
from datetime import datetime from datetime import datetime
from binascii import crc32 from binascii import crc32
from linspector.core.helpers import log
from linspector.core.task import Task, TaskExecutor from linspector.core.task import Task, TaskExecutor
class Monitor: class Monitor:
def __init__(self, configuration, environment, identifier, monitor_configuration, notifications, def __init__(self, configuration, environment, identifier, log, monitor_configuration,
services, tasks, kwargs): notifications, services, tasks, kwargs):
self.__args = kwargs self.__args = kwargs
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__identifier = identifier self.__identifier = identifier
self.__interval = int(monitor_configuration.get('monitor', 'interval')) self.__interval = int(monitor_configuration.get('monitor', 'interval'))
self.__log = log
self.__monitor_configuration = monitor_configuration self.__monitor_configuration = monitor_configuration
self.__notification_list = [] self.__notification_list = []
self.__notifications = notifications self.__notifications = notifications
@ -30,7 +30,6 @@ class Monitor:
self.__services = services self.__services = services
self.__task_list = [] # put tasks for the dedicated job here. self.__task_list = [] # put tasks for the dedicated job here.
self.__tasks = tasks self.__tasks = tasks
self.service = self.__service self.service = self.__service
self.host = monitor_configuration.get('monitor', 'hosts') self.host = monitor_configuration.get('monitor', 'hosts')
@ -83,7 +82,7 @@ class Monitor:
if notification_option not in notifications: if notification_option not in notifications:
notification_package = 'linspector.notifications.' + notification_option.lower() notification_package = 'linspector.notifications.' + notification_option.lower()
notification_module = importlib.import_module(notification_package) 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 notifications[notification_option.lower()] = notification
except configparser.NoOptionError as err: except configparser.NoOptionError as err:
self.__notifications = notifications self.__notifications = notifications
@ -95,7 +94,7 @@ class Monitor:
service_module = importlib.import_module(service_package) service_module = importlib.import_module(service_package)
self.__service = monitor_configuration.get('monitor', 'service').lower() 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 self.__services[monitor_configuration.get('monitor', 'service').lower()] = service
try: try:
if configuration.get_option('linspector', 'tasks') or \ if configuration.get_option('linspector', 'tasks') or \
@ -119,7 +118,7 @@ class Monitor:
if task_option not in tasks: if task_option not in tasks:
task_package = 'linspector.tasks.' + task_option.lower() task_package = 'linspector.tasks.' + task_option.lower()
task_module = importlib.import_module(task_package) 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 tasks[task_option.lower()] = task
except configparser.NoOptionError: except configparser.NoOptionError:
self.__tasks = tasks self.__tasks = tasks
@ -194,13 +193,13 @@ class Monitor:
def handle_tasks(self, monitor_information): def handle_tasks(self, monitor_information):
for task in self.__tasks: for task in self.__tasks:
if self.status.lower() in task.get_task_type().lower(): 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 # tasks can but should not be executed here. putting them in a queue is the better
# solution to execute them in a serial process. # solution to execute them in a serial process.
#TaskExecutor.instance().schedule_task(monitor_information, task) #TaskExecutor.instance().schedule_task(monitor_information, task)
def handle_call(self): 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("handle call")
#logger.debug(self.service) #logger.debug(self.service)
if self.enabled: if self.enabled:
@ -210,7 +209,7 @@ class Monitor:
#self.__services[self.__service].execute(self.last_execution) #self.__services[self.__service].execute(self.last_execution)
self.__services[self.__service].execute(**self.__args) self.__services[self.__service].execute(**self.__args)
except Exception as err: except Exception as err:
log('error', err) self.__log('error', err)
#self.last_execution.set_execution_end() #self.last_execution.set_execution_end()
@ -226,7 +225,7 @@ class Monitor:
#self.handle_tasks(self.monitor_information) #self.handle_tasks(self.monitor_information)
else: else:
log('info', "job " + self.get_job_id() + " disabled") self.__log('info', "job " + self.get_job_id() + " disabled")
def get_host(self): def get_host(self):
return self.host return self.host

View file

@ -9,17 +9,16 @@ import glob
import os import os
from linspector.core.monitor import Monitor 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 # 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 # restarting the daemon. maybe add a reset function to each monitor to reset the monitor at runtime
# when changed dynamically. # when changed dynamically.
class Monitors: class Monitors:
def __init__(self, configuration, environment, log, notifications, services, tasks):
def __init__(self, configuration, environment, notifications, services, tasks):
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
self.__monitors = {} self.__monitors = {}
monitor_groups = os.listdir(self.__configuration.get_configuration_path() + '/monitors/') monitor_groups = os.listdir(self.__configuration.get_configuration_path() + '/monitors/')
@ -39,7 +38,9 @@ class Monitors:
kwargs = {} kwargs = {}
for option in monitor_configuration.options('args'): for option in monitor_configuration.options('args'):
value = monitor_configuration.get('args', option) 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 kwargs[option] = value
if kwargs: if kwargs:
@ -51,7 +52,7 @@ class Monitors:
# create Monitor() object and copy monitor_configuration for each instance because # create Monitor() object and copy monitor_configuration for each instance because
# they else refer to the same object. # they else refer to the same object.
self.__monitors[identifier] = Monitor(configuration, environment, identifier, self.__monitors[identifier] = Monitor(configuration, environment, identifier,
monitor_configuration, notifications, log, monitor_configuration, notifications,
services, tasks, copy.deepcopy(kwargs)) services, tasks, copy.deepcopy(kwargs))
del kwargs del kwargs

View file

@ -3,12 +3,11 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
class Notification: class Notification:
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment):
super().__init__() super().__init__()
self.__configuration = configuration self.__configuration = configuration
self._environment = environment self.__environment = environment
self.__log = log

View file

@ -3,11 +3,10 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
class Service: class Service:
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment):
self.__configuration = configuration self.__configuration = configuration
self._environment = environment self._environment = environment
self.__log = log

View file

@ -6,7 +6,6 @@ See LICENSE (MIT license)
from queue import Queue from queue import Queue
from threading import Event, Thread from threading import Event, Thread
from linspector.core.helpers import log
from linspector.core.singleton import Singleton from linspector.core.singleton import Singleton
KEY_TYPE = "type" KEY_TYPE = "type"
@ -15,11 +14,12 @@ KEY_CLASS = "class"
class Task: class Task:
def __init__(self, configuration, environment, **kwargs): def __init__(self, configuration, environment, log, **kwargs):
self._args = {}
self.__configuration = configuration self.__configuration = configuration
self._environment = environment self._environment = environment
self.__log = log
self._args = {}
if KEY_ARGS in kwargs: if KEY_ARGS in kwargs:
self.add_arguments(kwargs[KEY_ARGS]) self.add_arguments(kwargs[KEY_ARGS])
elif self.needs_arguments(): elif self.needs_arguments():
@ -66,7 +66,10 @@ class Task:
# when tasks are being implemented. # when tasks are being implemented.
@Singleton @Singleton
class TaskExecutor: class TaskExecutor:
def __init__(self): def __init__(self, configuration, environment, log):
self.__configuration = configuration
self.__environment = environment
self.__log = log
self.queue = Queue() self.queue = Queue()
self.taskInfos = [] self.taskInfos = []
task_thread = Thread(target=self._run_worker_thread) task_thread = Thread(target=self._run_worker_thread)
@ -81,12 +84,12 @@ class TaskExecutor:
try: try:
msg, task = self.queue.get() msg, task = self.queue.get()
if task: if task:
log('debug', "starting task execution...") self.__log('debug', "starting task execution...")
#task.execute(msg) #task.execute(msg)
self.queue.task_done() self.queue.task_done()
except Exception as err: except Exception as err:
log('error', "error " + str(err)) self.__log('error', "error " + str(err))
def is_instant_end(self): def is_instant_end(self):
return self._instantEnd return self._instantEnd

View file

@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.notification import Notification from linspector.core.notification import Notification
def create(configuration, environment): def create(configuration, environment, log):
return CallNotification(configuration, environment) return CallNotification(configuration, environment, log)
class CallNotification(Notification): class CallNotification(Notification):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.notification import Notification from linspector.core.notification import Notification
def create(configuration, environment): def create(configuration, environment, log):
return EmailNotification(configuration, environment) return EmailNotification(configuration, environment, log)
class EmailNotification(Notification): class EmailNotification(Notification):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment):
super().__init__(configuration, environment) super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -5,17 +5,16 @@ See LICENSE (MIT license)
""" """
import gammu import gammu
from linspector.core.helpers import log
from linspector.core.notification import Notification from linspector.core.notification import Notification
def create(configuration, environment): def create(configuration, environment, log):
return SMSNotification(configuration, environment) return SMSNotification(configuration, environment, log)
class SMSNotification(Notification): class SMSNotification(Notification):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,17 +3,16 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.notification import Notification from linspector.core.notification import Notification
def create(configuration, environment): def create(configuration, environment, log):
return TwitterNotification(configuration, environment) return TwitterNotification(configuration, environment, log)
class TwitterNotification(Notification): class TwitterNotification(Notification):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -5,17 +5,16 @@ See LICENSE (MIT license)
""" """
import xmpp import xmpp
from linspector.core.helpers import log
from linspector.core.notification import Notification from linspector.core.notification import Notification
def create(configuration, environment): def create(configuration, environment, log):
return XMPPNotification(configuration, environment) return XMPPNotification(configuration, environment, log)
class XMPPNotification(Notification): class XMPPNotification(Notification):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return HTTPKeywordService(configuration, environment) return HTTPKeywordService(configuration, environment, log)
class HTTPKeywordService(Service): class HTTPKeywordService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -3,22 +3,21 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return DummyService(configuration, environment) return DummyService(configuration, environment, log)
class DummyService(Service): class DummyService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): 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'])) #log('debug', 'dummy object @' + str(self) + str(self.__kwargs['foo']))
return return

View file

@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return RandomService(configuration, environment) return RandomService(configuration, environment, log)
class RandomService(Service): class RandomService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -5,21 +5,20 @@ See LICENSE (MIT)
""" """
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return FritzboxPhoneStatusService(configuration, environment) return FritzboxPhoneStatusService(configuration, environment, log)
class FritzboxPhoneStatusService(Service): class FritzboxPhoneStatusService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
log('debug', 'FritzboxPhoneStatusService object ' + str(self)) self.__log('debug', 'FritzboxPhoneStatusService object ' + str(self))
return return

View file

@ -5,21 +5,20 @@ See LICENSE (MIT)
""" """
from fritzconnection.lib.fritzstatus import FritzStatus from fritzconnection.lib.fritzstatus import FritzStatus
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return FritzboxUplinkService(configuration, environment) return FritzboxUplinkService(configuration, environment, log)
class FritzboxUplinkService(Service): class FritzboxUplinkService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): 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 return

View file

@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return PingService(configuration, environment) return PingService(configuration, environment, log)
class PingService(Service): class PingService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -5,20 +5,19 @@ See LICENSE (MIT license)
""" """
import socket import socket
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return PortService(configuration, environment) return PortService(configuration, environment, log)
class PortService(Service): class PortService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, execution, **kwargs): def execute(self, execution, **kwargs):

View file

@ -7,20 +7,19 @@ import calendar
import requests import requests
import time import time
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return SpeedtestService(configuration, environment) return SpeedtestService(configuration, environment, log)
class SpeedtestService(Service): class SpeedtestService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
self.__speedtest_maximum_speed = None self.__speedtest_maximum_speed = None
self.__speedtest_average_speed = None self.__speedtest_average_speed = None
@ -65,10 +64,10 @@ class SpeedtestService(Service):
self.__speedtest_time_elapsed = time.perf_counter() - start self.__speedtest_time_elapsed = time.perf_counter() - start
self.__environment.set_env_var('_speedtest_time_elapsed', self.__environment.set_env_var('_speedtest_time_elapsed',
str(self.__speedtest_time_elapsed)) str(self.__speedtest_time_elapsed))
logger.info('speedtest average: ' + str(self.__speedtest_average_speed) + self.__log('info', 'speedtest average: ' + str(self.__speedtest_average_speed) +
', max: ' + str(self.__speedtest_maximum_speed) + ', max: ' + str(self.__speedtest_maximum_speed) +
', time: ' + str(self.__speedtest_time_elapsed)) ', time: ' + str(self.__speedtest_time_elapsed))
else: else:
logger.warning('could not calculate download speed!') self.__log('warning', 'could not calculate download speed!')
time.sleep(self.__configuration.get_speedtest_interval()) time.sleep(self.__configuration.get_speedtest_interval())

View file

@ -7,20 +7,19 @@ import os
import paramiko import paramiko
import pprint import pprint
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return SSHService(configuration, environment) return SSHService(configuration, environment, log)
class SSHService(Service): class SSHService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa') path = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa')

View file

@ -3,21 +3,20 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return TCPConnectService(configuration, environment) return TCPConnectService(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class TCPConnectService(Service): class TCPConnectService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -5,20 +5,19 @@ See LICENSE (MIT license)
""" """
from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.entity.rfc3413.oneliner import cmdgen
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return GetService(configuration, environment) return GetService(configuration, environment, log)
class GetService(Service): class GetService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -3,21 +3,19 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def create(configuration, environment): def create(configuration, environment, log):
return ShellService(configuration, environment) return ShellService(configuration, environment, log)
class ShellService(Service): class ShellService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -3,20 +3,19 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.service import Service from linspector.core.service import Service
def get(configuration, environment): def get(configuration, environment, log):
return UptimeService(configuration, environment) return UptimeService(configuration, environment, log)
class UptimeService(Service): class UptimeService(Service):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log
def execute(self, **kwargs): def execute(self, **kwargs):
return return

View file

@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.task import Task from linspector.core.task import Task
def create(configuration, environment): def create(configuration, environment, log):
return CSVTask(configuration, environment) return CSVTask(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class CSVTask(Task): class CSVTask(Task):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,18 +3,18 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.task import Task from linspector.core.task import Task
def create(configuration, environment): def create(configuration, environment, log):
return FileLoggerTask(configuration, environment) return FileLoggerTask(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class FileLoggerTask(Task): class FileLoggerTask(Task):
def __init__(self, configuration, environment): def __init__(self, configuration, environment, log):
super().__init__(configuration, environment) super().__init__(configuration, environment, log)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.task import Task from linspector.core.task import Task
def create(configuration, environment): def create(configuration, environment, log):
return MariaDBTask(configuration, environment) return MariaDBTask(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class MariaDBTask(Task): class MariaDBTask(Task):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,18 +3,17 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.task import Task from linspector.core.task import Task
def create(configuration, environment): def create(configuration, environment, log):
return RedisTask(configuration, environment) return RedisTask(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class RedisTask(Task): class RedisTask(Task):
def __init__(self, configuration, environment, log):
def __init__(self, configuration, environment): super().__init__(configuration, environment, log)
super().__init__(configuration, environment)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log

View file

@ -3,18 +3,18 @@ This file is part of Linspector (https://linspector.org/)
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved. Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
See LICENSE (MIT license) See LICENSE (MIT license)
""" """
from linspector.core.helpers import log
from linspector.core.task import Task from linspector.core.task import Task
def create(configuration, environment): def create(configuration, environment, log):
return SQLiteTask(configuration, environment) return SQLiteTask(configuration, environment, log)
# TODO: check for all required configuration options and set defaults if needed. # TODO: check for all required configuration options and set defaults if needed.
class SQLiteTask(Task): class SQLiteTask(Task):
def __init__(self, configuration, environment): def __init__(self, configuration, environment, log):
super().__init__(configuration, environment) super().__init__(configuration, environment, log)
self.__configuration = configuration self.__configuration = configuration
self.__environment = environment self.__environment = environment
self.__log = log