Switched from JSON to ini files for configuration, lots of code adds, refactoring and even many design changes.

This commit is contained in:
Johannes Findeisen 2022-09-24 22:34:53 +02:00
commit 779c2f0b48
58 changed files with 1227 additions and 649 deletions

1
.gitignore vendored
View file

@ -242,3 +242,4 @@ luac.out
/monipy.iml
/.idea/
!/MANIFEST

11
AUTHORS
View file

@ -1,7 +1,6 @@
PRIMARY AUTHORS (alphabetic order):
* Findeisen, Johannes
Main Developer and maintainer.
github.com: <https://github.com/hanez/>
git.unixpeople.org: <https://git.unixpeople.org/hanez>
Homepage: <http://hanez.org/>
Founder, core developer and maintainer.
Email: you@hanez.org
Homepage: http://hanez.org/
Git: https://git.unixpeople.org/hanez
GitHub: https://github.com/hanez/>

View file

@ -1 +1,72 @@
# monipy - A infrastructure monitoring toolchain
This is implemented in an old school way for easy understanding without cloud
and such stuff... Hope it will become useful someday for somebody and not only for
me.
## About
**monipy** contains some tools and a daemon to monitor your infrastructure. It
collects data for statistics and sends alerts in case of errors.
This project is at a very early stage of development it is not able for usage.
I design the software actually and try to convert my ideas to software. Code
nearly does not exist.
## Development
### Manifest
- All of this project **must be MIT licensed**. When using 3rd party libraries make
sure the license is compatible but MIT should always be preferred if an
alternative is available.
- The core of monipy/monipyd should not use 3rd party libraries. only plugins,
notifications and types may use other libraries. But coping code into the
source tree is ok when respecting the license. Not using 3rd party libraries
should always be preferred though.
- Inline comment should be all lowercase. Descriptions and documentation comments
must be natural language.
### To do
**Everything!** :) Just outlining the idea and creating code and structure skeletons
at the moment!
### Version numbering
According to: [https://wiki.unixpeople.org/linux_kernel_version_numbering]()
**MAJOR**.**FEATURE**.**MINOR**.**FIXES**
- **MAJOR** changes _can_ change the API. The lesser, the better.
- **FEATURE** changes can, but _should_ not break the API. New features are placed
here. It _expects_ a complete documentation.
- **MINOR** changes are "just-in-time" changes or small enhancements which _must_
not affect the documentation and _must_ not break the API.
- **FIXES** _must_ never affect anything else then stability or security.
## License
### MIT License
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.

View file

@ -1,65 +0,0 @@
#!/usr/bin/python3 -d
# 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 argparse
from logging import getLogger
#from monipy.configuration import Configuration
#from monipy.environment import Environment
#from monipy.monipy import Monipy
"""
According to: https://wiki.unixpeople.org/linux_kernel_version_numbering
MAJOR.FEATURE.MINOR.FIXES
MAJOR changes can change the API. The lesser, the better.
FEATURE changes can, but should not break the API. New features are placed here. It expects a
complete documentation.
MINOR changes are "just-in-time" changes or small enhancements which should not affect the
documentation.
FIXES should never affect anything else then stability or security.
"""
__version__ = '0.1'
__author__ = 'Johannes Findeisen <you@hanez.org>'
logger = getLogger('monipy')
def parse_args():
parser = argparse.ArgumentParser(
description='monipy is a client for the monipyd infrastructure monitoring daemon.',
epilog='author: ' + __author__,
prog='monipy')
parser.add_argument('configuration_path', metavar='CONFIGURATION_PATH',
help='the configuration path to use')
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + str(__version__))
return parser.parse_args()
def main():
args = parse_args()
if __name__ == '__main__':
main()

View file

@ -1,46 +1,40 @@
#!/usr/bin/python3 -d
# 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.
"""
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 argparse
import sys
from logging import getLogger
from monipy.configuration import Configuration
from monipy.environment import Environment
from monipy.monipyd import Monipyd
"""
According to: https://wiki.unixpeople.org/linux_kernel_version_numbering
MAJOR.FEATURE.MINOR.FIXES
MAJOR changes can change the API. The lesser, the better.
FEATURE changes can, but should not break the API. New features are placed here. It expects a
complete documentation.
MINOR changes are "just-in-time" changes or small enhancements which should not affect the
documentation.
FIXES should never affect anything else then stability or security.
"""
__version__ = '0.1'
__author__ = 'Johannes Findeisen <you@hanez.org>'
logger = getLogger('monipy')
logger = getLogger('monipyd')
def parse_args():
@ -60,6 +54,17 @@ def parse_args():
def main():
args = parse_args()
try:
configuration = Configuration(args.configuration_path)
configuration.dump_to_ini()
except Exception as err:
logger.error(str('[uplink] configuration error: {0}'.format(err)))
sys.exit(1)
environment = Environment(configuration)
monipyd = Monipyd(configuration, environment)
if __name__ == '__main__':
main()

46
etc/monipy.ini Normal file
View file

@ -0,0 +1,46 @@
; all you need to know: https://docs.python.org/3/library/configparser.html ... ;)
; manifest:
; - no inline comments so every available character can be used in values
; - values can be overridden in each monitor
; - file names are not important but section names and key names.
; - comments can be inserted using ',' or '#'
[monipy]
; report core errors to the following users
error_receivers = admin@example.com
log_file = ~/code/monipy/log/uplink.log
log_level = verbose
log_count = 5
log_size = 10485760
pid_file = /var/run/user/1000/monipy.pid
; default delimiters '=' and ':' should be changed to ',' to be more native
plugins = httpserver,mariadb,speedtest
; maybe the run_mode is obsolete because this will be a daemon but maybe it is useful for one time execution?
; in uplink the available run_modes were cron, daemon and foreground
run_mode = cron
; every notification can be configured in it's own ini file in etc/notifications; there no notification name as prefix
; is needed. see email example.
[notifications]
; some values can be overridden in each defined monitor
sms_receivers = +34324234234:+324242344
sms_configuration_file = ~/code/monipy/etc/gammurc
; retry to send interval and number of retries if something failed
sms_resend = 10
sms_resend_count = 5
email_resend = 10
; every plugin can be configured in it's own ini file in etc/plugins; there no plugin name as prefix is needed. see
; httpserver example.
[plugins]
mariadb_database = monipy
mariadb_host = 10.0.0.254
mariadb_password = 3qx7HfrxGNM83lqN
mariadb_port": 3306
mariadb_user = uplink
speedtest_interval = 3600
speedtest_url = https://go.microsoft.com/fwlink/?Linkid=850641
; if types can or must be configured before use; for now no use case seen.
; every type can be configured in it's own ini file in etc/types; there no type name as prefix is not needed.
;[types]

View file

View file

@ -1,9 +0,0 @@
{
"type": "uplink",
"interval": 60,
"notification": "sms",
"host": "192.168.0.1",
"user": "USERNAME",
"password": "PASSWORD",
"info": "Cable Provider"
}

View file

@ -0,0 +1,14 @@
[main]
; identifiers must be unique in the whole configuration so maybe it is better to create a random string for this
; dynamically.
identifier = cable
type = fritzbox
interval = 60
# default delimiters '=' and ':' should be changed to ',' to be more native
notifications = sms:email
email_receivers = admin@example.com:fallback@example.com
sms_receivers = +329084320984:+39804932409
host = 192.168.0.1
user = USERNAME
password = PASSWORD
info = Cable Provider

View file

@ -1,9 +0,0 @@
{
"type": "uplink",
"interval": 60,
"notification": "sms",
"host": "192.168.1.1",
"user": "USERNAME",
"password": "PASSWORD",
"info": "DSL Provider"
}

View file

@ -0,0 +1,12 @@
[main]
identifier = dsl
type = fritzbox
interval = 60
# default delimiters '=' and ':' should be changed to ',' to be more native
notifications = sms:email
email_receivers = admin@example.com:fallback@example.com
sms_receivers = +329084320984:+39804932409
host = 192.168.1.1
user = USERNAME
password = PASSWORD
info = Cable Provider

View file

@ -0,0 +1,7 @@
[email]
resend = 20
smtp_host = mail.example.com
smtp_port = 25
smtp_password = k4509knsd09
smtp_user = alert@hanez.org
receivers = admin@example.com

View file

@ -0,0 +1,3 @@
[httpserver]
ip = 127.0.0.1
port = 4242

View file

@ -1,29 +1,76 @@
# 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.
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipy')
logger = getLogger('monipyd')
class Configuration:
def __init__(self, configuration_file):
self.__configuration_file = configuration_file
def __init__(self, configuration_path):
self.__configuration = configparser.ConfigParser()
if os.path.isfile(configuration_path + '/monipy.ini'):
self.__configuration.read(configuration_path + '/monipy.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 + '/monipy/' + 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

View file

@ -1,22 +1,25 @@
# 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.
"""
This file is part of monipy (https://hanez.org/monipy/)
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
@ -26,48 +29,44 @@ import time
from logging import getLogger
logger = getLogger('monipy')
logger = getLogger('monipyd')
class Daemon:
"""
Usage: subclass the daemon class and override the run() method.
"""
# subclass the daemon class and override the run() method.
def __init__(self, pid_file):
self.pid_file = pid_file
self.__pid_file = pid_file
def daemonize(self):
"""
Daemonize the class using the UNIX double fork mechanism.
"""
# daemonize the class using the UNIX double fork mechanism.
# Do first fork
# do first fork.
try:
pid = os.fork()
if pid > 0:
# Exit first parent
# 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
# decouple from parent environment.
os.chdir('/')
os.setsid()
os.umask(0)
# Do second fork
# do second fork.
try:
pid = os.fork()
if pid > 0:
# Exit from second parent
# 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
# redirect standard file descriptors.
sys.stdout.flush()
sys.stderr.flush()
si = open(os.devnull, 'r')
@ -78,55 +77,50 @@ class Daemon:
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
# Write pidfile
atexit.register(self.del_pid)
# write pid file.
atexit.register(self.delete_pid)
pid = str(os.getpid())
with open(self.pid_file, 'w+') as f:
with open(self.__pid_file, 'w+') as f:
f.write(pid + '\n')
def del_pid(self):
os.remove(self.pid_file)
def delete_pid(self):
os.remove(self.__pid_file)
def start(self):
"""
Start the daemon.
"""
# start the daemon. check for a pidfile to see if the daemon already runs before.
# Check for a pidfile to see if the daemon already runs
try:
with open(self.pid_file, 'r') as pf:
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)))
logger.error(str(message.format(self.__pid_file)))
sys.exit(1)
# Start the daemon
# start the daemon.
self.daemonize()
self.run()
def stop(self):
"""
Stop the daemon.
"""
# stop the daemon.
# Get the pid from the pid_file
# get the pid from the pid file.
try:
with open(self.pid_file, 'r') as pf:
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)))
logger.error(str(message.format(self.__pid_file)))
return # not an error in a restart
# Try killing the daemon process
# try killing the daemon process.
try:
while 1:
os.kill(pid, signal.SIGTERM)
@ -134,23 +128,20 @@ class Daemon:
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)
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.
"""
# 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().
you should override this method when you subclass daemon. it will be called after the
process has been daemonized by start() or restart().
"""

View file

@ -1,29 +1,53 @@
# 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.
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipy')
logger = getLogger('monipyd')
class Environment:
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

39
monipy/logger.py Normal file
View file

@ -0,0 +1,39 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
# 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
monipy/model.py Normal file
View file

@ -0,0 +1,34 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Model:
def __init__(self, configuration, environment):
super().__init__()
self.__configuration = configuration
self._environment = environment

View file

@ -1,26 +1,29 @@
# 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.
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipy')
logger = getLogger('monipyd')
class Monipy:

View file

@ -1,31 +1,35 @@
# 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.
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.daemon import Daemon
logger = getLogger('monipy')
logger = getLogger('monipyd')
class Monipyd(Daemon):
def __init__(self, configuration, environment):
super().__init__('/tmp/uplink.pid')
self.__configuration = configuration
self.__environment = environment

33
monipy/monitor.py Normal file
View file

@ -0,0 +1,33 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Monitor:
def __init__(self, configuration, environment):
self.__configuration = configuration
self._environment = environment

33
monipy/monitors.py Normal file
View file

@ -0,0 +1,33 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Monitors:
def __init__(self, configuration, environment):
self.__configuration = configuration
self._environment = environment

View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.notications.notification import Notification
logger = getLogger('monipyd')
class EmailNotification(Notification):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

View file

@ -1,30 +0,0 @@
# 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 monipy.notications.notification import Notification
logger = getLogger('monipy')
class EmailNotification(Notification):
def __init__(self, configuration):
self._configuration = configuration

View file

@ -1,29 +0,0 @@
# 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('monipy')
class Notification:
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.notications.notification import Notification
logger = getLogger('monipy')
class SmsNotification(Notification):
def __init__(self, configuration):
self.__configuration = configuration

35
monipy/notications/sms.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.notications.notification import Notification
logger = getLogger('monipyd')
class SmsNotification(Notification):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

33
monipy/notification.py Normal file
View file

@ -0,0 +1,33 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Notification:
def __init__(self, configuration, environment):
self.__configuration = configuration
self.__environment = environment

34
monipy/notifications.py Normal file
View file

@ -0,0 +1,34 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Notifications:
def __init__(self, configuration, environment):
super().__init__()
self.__configuration = configuration
self.__environment = environment

33
monipy/plugin.py Normal file
View file

@ -0,0 +1,33 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Plugin:
def __init__(self, configuration, environment):
self.__configuration = configuration
self.__environment = environment

34
monipy/plugins.py Normal file
View file

@ -0,0 +1,34 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Plugins:
def __init__(self, configuration, environment):
super().__init__()
self.__configuration = configuration
self.__environment = environment

View file

@ -0,0 +1,105 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.plugins.plugin import Plugin
logger = getLogger('monipyd')
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)

35
monipy/plugins/mariadb.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.plugins.plugin import Plugin
logger = getLogger('monipyd')
class MariadbPlugin(Plugin):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

View file

@ -1,30 +0,0 @@
# 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 monipy.plugins.plugin import Plugin
logger = getLogger('monipy')
class HttpserverPlugin(Plugin):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,29 +0,0 @@
# 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('monipy')
class Plugin:
def __init__(self, configuration):
self.__configuration = configuration

35
monipy/plugins/redis.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.plugins.plugin import Plugin
logger = getLogger('monipyd')
class RedisPlugin(Plugin):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

35
monipy/plugins/sqlite.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.plugins.plugin import Plugin
logger = getLogger('monipyd')
class SqlitePlugin(Plugin):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

View file

@ -1,30 +0,0 @@
# 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 monipy.plugins.plugin import Plugin
logger = getLogger('monipy')
class MariadbPlugin(Plugin):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.plugins.plugin import Plugin
logger = getLogger('monipy')
class RedisPlugin(Plugin):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.plugins.plugin import Plugin
logger = getLogger('monipy')
class SqlitePlugin(Plugin):
def __init__(self, configuration):
self.__configuration = configuration

33
monipy/type.py Normal file
View file

@ -0,0 +1,33 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Type:
def __init__(self, configuration, environment):
self.__configuration = configuration
self.__environment = environment

34
monipy/types.py Normal file
View file

@ -0,0 +1,34 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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('monipyd')
class Types:
def __init__(self, configuration, environment):
super().__init__()
self.__configuration = configuration
self.__environment = environment

35
monipy/types/fritzbox.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.types.type import Type
logger = getLogger('monipyd')
class FritzboxType(Type):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

View file

@ -1,30 +0,0 @@
# 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 monipy.types.type import Type
logger = getLogger('monipy')
class PingType(Type):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.types.type import Type
logger = getLogger('monipy')
class PortType(Type):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.types.type import Type
logger = getLogger('monipy')
class SpeedtestType(Type):
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -1,30 +0,0 @@
# 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 monipy.types.type import Type
logger = getLogger('monipy')
class UplinkType(Type):
def __init__(self, configuration):
self.__configuration = configuration

35
monipy/types/ping.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.types.type import Type
logger = getLogger('monipyd')
class PingType(Type):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

35
monipy/types/port.py Normal file
View file

@ -0,0 +1,35 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.types.type import Type
logger = getLogger('monipyd')
class PortType(Type):
def __init__(self, configuration, environment):
super().__init__(configuration, environment)
self.__configuration = configuration
self.__environment = environment

94
monipy/types/speedtest.py Normal file
View file

@ -0,0 +1,94 @@
"""
This file is part of monipy (https://hanez.org/monipy/)
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 monipy.types.type import Type
logger = getLogger('monipyd')
class SpeedtestType(Type):
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

View file

@ -1,29 +0,0 @@
# 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('monipy')
class Type:
def __init__(self, configuration):
self.__configuration = configuration

View file

@ -0,0 +1,2 @@
requests~=2.28.1 # used by speedtest type
CherryPy~=18.8.0 # used by httpserver plugin