Initial commit after complete rewrite of Linspector.
This commit is contained in:
commit
0c64555155
52 changed files with 1712 additions and 0 deletions
0
linspector/__init__.py
Normal file
0
linspector/__init__.py
Normal file
86
linspector/core/configuration.py
Normal file
86
linspector/core/configuration.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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 glob
|
||||
import os
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed. do this only for
|
||||
# options in the "monipy" section of monipy.ini.
|
||||
class Configuration:
|
||||
|
||||
def __init__(self, configuration_path):
|
||||
self.__configuration = configparser.ConfigParser()
|
||||
|
||||
if os.path.isfile(configuration_path + '/linspector.ini'):
|
||||
self.__configuration.read(configuration_path + '/linspector.ini', 'utf-8')
|
||||
|
||||
# add keys and values from notifications, plugins and types defined in their subdir ini
|
||||
# files.
|
||||
for target_section in ['notifications', 'plugins', 'types']:
|
||||
# check if section exists before adding content. if not exists add the section.
|
||||
if not self.__configuration.has_section(target_section):
|
||||
self.__configuration.add_section(target_section)
|
||||
|
||||
section_list = glob.glob(configuration_path + '/linspector/' + target_section + '/*')
|
||||
for section_file in section_list:
|
||||
configuration = configparser.ConfigParser()
|
||||
configuration.read(section_file, 'utf-8')
|
||||
for source_section in configuration.sections():
|
||||
source_section_options = configuration.options(source_section)
|
||||
for source_section_option in source_section_options:
|
||||
self.__configuration.set(target_section, source_section + '_' +
|
||||
source_section_option,
|
||||
configuration.get(source_section,
|
||||
source_section_option))
|
||||
|
||||
def dump_to_ini(self):
|
||||
i = 0
|
||||
for section in self.__configuration.sections():
|
||||
if i < 1:
|
||||
print('[' + section + ']')
|
||||
else:
|
||||
print('\n[' + section + ']')
|
||||
options = self.__configuration.options(section)
|
||||
for option in options:
|
||||
print(option + " = " + self.__configuration.get(section, option))
|
||||
i = 1
|
||||
|
||||
def get_option(self, section, option):
|
||||
if self.__configuration.has_option(section, option):
|
||||
return self.__configuration.get(section, option)
|
||||
else:
|
||||
return None
|
||||
|
||||
# this function can be called by notifications, plugins and types to set a default value if not
|
||||
# configured. since all objects have access to the configuration this should not be done from
|
||||
# any other place because it can break monipy.
|
||||
# maybe it can be used for dynamic runtime configuration later but need to think about it.
|
||||
def set_option(self, section, option, value):
|
||||
if not self.__configuration.has_option(section, option):
|
||||
self.__configuration.set(section, option, value)
|
||||
147
linspector/core/daemon.py
Normal file
147
linspector/core/daemon.py
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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 atexit
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Daemon:
|
||||
# subclass the daemon class and override the run() method.
|
||||
|
||||
def __init__(self, pid_file):
|
||||
self.__pid_file = pid_file
|
||||
|
||||
def daemonize(self):
|
||||
# daemonize the class using the UNIX double fork mechanism.
|
||||
|
||||
# do first fork.
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# exit first parent.
|
||||
sys.exit(0)
|
||||
except OSError as err:
|
||||
logger.error(str('fork #1 failed: {0}'.format(err)))
|
||||
sys.exit(1)
|
||||
|
||||
# decouple from parent environment.
|
||||
os.chdir('/')
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
# do second fork.
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# Exit from second parent.
|
||||
sys.exit(0)
|
||||
except OSError as err:
|
||||
logger.error(str('fork #2 failed: {0}'.format(err)))
|
||||
sys.exit(1)
|
||||
|
||||
# redirect standard file descriptors.
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
si = open(os.devnull, 'r')
|
||||
so = open(os.devnull, 'a+')
|
||||
se = open(os.devnull, 'a+')
|
||||
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
# write pid file.
|
||||
atexit.register(self.delete_pid)
|
||||
|
||||
pid = str(os.getpid())
|
||||
with open(self.__pid_file, 'w+') as f:
|
||||
f.write(pid + '\n')
|
||||
|
||||
def delete_pid(self):
|
||||
os.remove(self.__pid_file)
|
||||
|
||||
def start(self):
|
||||
# start the daemon. check for a pidfile to see if the daemon already runs before.
|
||||
|
||||
try:
|
||||
with open(self.__pid_file, 'r') as pf:
|
||||
pid = int(pf.read().strip())
|
||||
except IOError:
|
||||
pid = None
|
||||
|
||||
if pid:
|
||||
message = 'pid_file {0} already exist. daemon already running?'
|
||||
logger.error(str(message.format(self.__pid_file)))
|
||||
sys.exit(1)
|
||||
|
||||
# start the daemon.
|
||||
self.daemonize()
|
||||
self.run()
|
||||
|
||||
def stop(self):
|
||||
# stop the daemon.
|
||||
|
||||
# get the pid from the pid file.
|
||||
try:
|
||||
with open(self.__pid_file, 'r') as pf:
|
||||
pid = int(pf.read().strip())
|
||||
except IOError:
|
||||
pid = None
|
||||
|
||||
if not pid:
|
||||
message = 'pid_file {0} does not exist. daemon not running?'
|
||||
logger.error(str(message.format(self.__pid_file)))
|
||||
return # not an error in a restart
|
||||
|
||||
# try killing the daemon process.
|
||||
try:
|
||||
while 1:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
time.sleep(0.1)
|
||||
except OSError as err:
|
||||
e = str(err.args)
|
||||
if e.find('no such process') > 0:
|
||||
if os.path.exists(self.__pid_file):
|
||||
os.remove(self.__pid_file)
|
||||
else:
|
||||
logger.error(str(err.args))
|
||||
sys.exit(1)
|
||||
|
||||
def restart(self):
|
||||
# restart the daemon.
|
||||
|
||||
self.stop()
|
||||
self.start()
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
you should override this method when you subclass daemon. it will be called after the
|
||||
process has been daemonized by start() or restart().
|
||||
"""
|
||||
56
linspector/core/environment.py
Normal file
56
linspector/core/environment.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Environment:
|
||||
"""
|
||||
Object for storing environment variables at runtime. These variables must not affect the
|
||||
stability of monipy.
|
||||
"""
|
||||
def __init__(self, configuration):
|
||||
self.__configuration = configuration
|
||||
|
||||
self.__env = {}
|
||||
|
||||
def get_env_var(self, key):
|
||||
if key in self.__env:
|
||||
return self.__env[key]
|
||||
else:
|
||||
logger.info('environment var "' + key + '" not found! could be that it is set later at '
|
||||
'runtime. if you encounter any errors '
|
||||
'executing monipyd, something is wrong in the '
|
||||
'logic of the code. please consider reporting '
|
||||
'this as a bug! btw. INFO is not an ERROR! '
|
||||
'monipyd should work even with missing '
|
||||
'environment variables.')
|
||||
return None
|
||||
|
||||
def set_env_var(self, key, value):
|
||||
if self.__env[key]:
|
||||
logger.info('environment var "' + key + ' existed and was overwritten.')
|
||||
|
||||
self.__env[key] = value
|
||||
33
linspector/core/linspector.py
Normal file
33
linspector/core/linspector.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Linspector:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
35
linspector/core/linspectord.py
Normal file
35
linspector/core/linspectord.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.daemon import Daemon
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Linspector(Daemon):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration.get_option('linspector', 'pid_file'))
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
39
linspector/core/logger.py
Normal file
39
linspector/core/logger.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# The logger can be used by any monitor to write arbitrary data to any arbitrary place.
|
||||
# Need to think about this more but some monitors are or can collect more data than needed for
|
||||
# running monipyd. This enables longtime storage of collected data like in uplink.
|
||||
# Maybe this can be archived by storing an arbitrary JSON string in a none defined field in the
|
||||
# database. then maybe redis can be used for everything. Storing data should be optional for
|
||||
# running monipyd.
|
||||
class Logger:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
34
linspector/core/model.py
Normal file
34
linspector/core/model.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Model:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__()
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
33
linspector/core/monitor.py
Normal file
33
linspector/core/monitor.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Monitor:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
36
linspector/core/monitors.py
Normal file
36
linspector/core/monitors.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# monitors 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):
|
||||
self.__configuration = configuration
|
||||
self._environment = environment
|
||||
33
linspector/core/notification.py
Normal file
33
linspector/core/notification.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Notification:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
34
linspector/core/notifications.py
Normal file
34
linspector/core/notifications.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Notifications:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__()
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
33
linspector/core/plugin.py
Normal file
33
linspector/core/plugin.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Plugin:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
34
linspector/core/plugins.py
Normal file
34
linspector/core/plugins.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Plugins:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__()
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
33
linspector/core/type.py
Normal file
33
linspector/core/type.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Type:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
34
linspector/core/types.py
Normal file
34
linspector/core/types.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class Types:
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__()
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
0
linspector/notications/__init__.py
Normal file
0
linspector/notications/__init__.py
Normal file
35
linspector/notications/email.py
Normal file
35
linspector/notications/email.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class EmailNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
35
linspector/notications/sms.py
Normal file
35
linspector/notications/sms.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.notification import Notification
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
class SmsNotification(Notification):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
0
linspector/plugins/__init__.py
Normal file
0
linspector/plugins/__init__.py
Normal file
106
linspector/plugins/httpserver.py
Normal file
106
linspector/plugins/httpserver.py
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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 cherrypy
|
||||
import json
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.plugin import Plugin
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class HTTPServerPlugin(Plugin):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
return 'Hello world!'
|
||||
|
||||
@cherrypy.expose
|
||||
def configuration(self):
|
||||
return '<!DOCTYPE html><html><head><title>[monipy-' + \
|
||||
self.__environment.get_env_var("__version__") + '@' + \
|
||||
self.__environment.get_env_var("_hostname") + '] configuration</title><meta ' + \
|
||||
'http-equiv="refresh" content="60"></head><body><pre ' + \
|
||||
'style="border:2px solid black;background:#1d2021;color:#f0751a;">' + \
|
||||
json.dumps(vars(self.__configuration), sort_keys=True, indent=4) + \
|
||||
'</pre></body></html>'
|
||||
|
||||
@cherrypy.expose
|
||||
def environment(self):
|
||||
return '<!DOCTYPE html><html><head><title>[monipy-' + \
|
||||
self.__environment.get_env_var("__version__") + '@' + \
|
||||
self.__environment.get_env_var("_hostname") + '] environment</title><meta ' + \
|
||||
'http-equiv="refresh" content="60"></head><body><pre ' + \
|
||||
'style="border:2px solid black;background:#1d2021;color:#f0751a;">' + \
|
||||
json.dumps(vars(self.__environment), sort_keys=True, indent=4) + \
|
||||
'</pre></body></html>'
|
||||
|
||||
@cherrypy.expose
|
||||
def playground(self):
|
||||
return 'My Playground!'
|
||||
|
||||
def run_server(self):
|
||||
conf = {
|
||||
'/': {
|
||||
# 'tools.sessions.on': True,
|
||||
# 'tools.staticdir.root': os.path.abspath(os.getcwd())
|
||||
'tools.response_headers.on': True,
|
||||
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
|
||||
},
|
||||
'/configuration': {
|
||||
# 'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
|
||||
'tools.response_headers.on': True,
|
||||
'tools.response_headers.headers': [('Content-Type', 'text/html')],
|
||||
},
|
||||
'/environment': {
|
||||
# 'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
|
||||
'tools.response_headers.on': True,
|
||||
'tools.response_headers.headers': [('Content-Type', 'text/html')],
|
||||
},
|
||||
'/playground': {
|
||||
# 'tools.staticdir.on': True,
|
||||
# 'tools.staticdir.dir': './public'
|
||||
}
|
||||
}
|
||||
#cherrypy.config.update({
|
||||
# 'global': {
|
||||
# 'engine.autoreload.on': False
|
||||
# }
|
||||
#})
|
||||
cherrypy.config.update({
|
||||
'global': {
|
||||
'server.socket_host': self.__configuration.get_httpserver_host(),
|
||||
'server.socket_port': self.__configuration.get_httpserver_port(),
|
||||
'environment': 'production'
|
||||
}
|
||||
})
|
||||
cherrypy.tree.mount(root=None, config=conf)
|
||||
cherrypy.quickstart(self, '/', conf)
|
||||
#cherrypy.server.bus.exit(self)
|
||||
36
linspector/plugins/mariadb.py
Normal file
36
linspector/plugins/mariadb.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.plugin import Plugin
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class MariadbPlugin(Plugin):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
36
linspector/plugins/redis.py
Normal file
36
linspector/plugins/redis.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.plugin import Plugin
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class RedisPlugin(Plugin):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
36
linspector/plugins/sqlite.py
Normal file
36
linspector/plugins/sqlite.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.plugin import Plugin
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SqlitePlugin(Plugin):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
0
linspector/services/__init__.py
Normal file
0
linspector/services/__init__.py
Normal file
36
linspector/services/fritzbox.py
Normal file
36
linspector/services/fritzbox.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.monitor import Monitor
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class FritzboxMonitor(Monitor):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
36
linspector/services/ping.py
Normal file
36
linspector/services/ping.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.monitor import Monitor
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class PingMonitor(Monitor):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
36
linspector/services/port.py
Normal file
36
linspector/services/port.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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.
|
||||
"""
|
||||
|
||||
from logging import getLogger
|
||||
from linspector.core.monitor import Monitor
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class PortType(Monitor):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
96
linspector/services/speedtest.py
Normal file
96
linspector/services/speedtest.py
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
"""
|
||||
This file is part of Linspector (https://linspector.org/)
|
||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||
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 calendar
|
||||
import requests
|
||||
import time
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
|
||||
from linspector.core.monitor import Monitor
|
||||
|
||||
logger = getLogger('linspector')
|
||||
|
||||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class SpeedtestMonitor(Monitor):
|
||||
|
||||
def __init__(self, configuration, environment):
|
||||
super().__init__(configuration, environment)
|
||||
self.__configuration = configuration
|
||||
self.__environment = environment
|
||||
|
||||
self.__speedtest_maximum_speed = None
|
||||
self.__speedtest_average_speed = None
|
||||
self.__speedtest_time_elapsed = None
|
||||
|
||||
def execute(self):
|
||||
while True:
|
||||
tmp_time = time.localtime(calendar.timegm(time.gmtime()))
|
||||
self.__environment.set_env_var('_speedtest_last_run_date',
|
||||
time.strftime('%Y-%m-%d %H:%M:%S',
|
||||
tmp_time))
|
||||
|
||||
self.__environment.set_env_var('_speedtest_last_run_timestamp',
|
||||
calendar.timegm(time.gmtime()))
|
||||
|
||||
start = time.perf_counter()
|
||||
request = requests.get(self.__configuration.get_speedtest_url(), stream=True)
|
||||
size = int(request.headers.get('Content-Length'))
|
||||
downloaded = 0.0
|
||||
total_mbps = 0.0
|
||||
maximum_speed = 0.0
|
||||
total_chunks = 0.0
|
||||
|
||||
if size is not None:
|
||||
for chunk in request.iter_content(1024 * 1024):
|
||||
downloaded += len(chunk)
|
||||
# megabytes per second
|
||||
mbps = downloaded / (time.perf_counter() - start) / (1024 * 1024)
|
||||
if mbps > maximum_speed:
|
||||
maximum_speed = mbps
|
||||
total_chunks += 1
|
||||
total_mbps += mbps
|
||||
|
||||
self.__speedtest_average_speed = total_mbps / total_chunks
|
||||
self.__environment.set_env_var('_speedtest_average_speed_megabyte_per_second',
|
||||
str(round(self.__speedtest_average_speed)))
|
||||
|
||||
self.__speedtest_maximum_speed = maximum_speed
|
||||
self.__environment.set_env_var('_speedtest_maximum_speed_megabyte_per_second',
|
||||
str(round(self.__speedtest_maximum_speed)))
|
||||
|
||||
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))
|
||||
else:
|
||||
logger.warning('could not calculate download speed!')
|
||||
|
||||
time.sleep(self.__configuration.get_speedtest_interval())
|
||||
|
||||
def write_to_db(self):
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue