diff --git a/.gitignore b/.gitignore index a8b1a3d..d1b1e63 100644 --- a/.gitignore +++ b/.gitignore @@ -242,3 +242,4 @@ luac.out /monipy.iml /.idea/ +!/MANIFEST diff --git a/AUTHORS b/AUTHORS index d20c371..f8444f5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,6 @@ -PRIMARY AUTHORS (alphabetic order): - * Findeisen, Johannes - Main Developer and maintainer. - github.com: - git.unixpeople.org: - Homepage: \ No newline at end of file + Founder, core developer and maintainer. + Email: you@hanez.org + Homepage: http://hanez.org/ + Git: https://git.unixpeople.org/hanez + GitHub: https://github.com/hanez/> diff --git a/README.md b/README.md index 1c9399a..f3a574a 100644 --- a/README.md +++ b/README.md @@ -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 + +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. diff --git a/bin/monipy b/bin/monipy deleted file mode 100755 index 8411a71..0000000 --- a/bin/monipy +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/python3 -d - -# Copyright (c) 2022 Johannes Findeisen -# -# 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 ' - -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() diff --git a/bin/monipyd b/bin/monipyd index 95c93a0..92cf249 100755 --- a/bin/monipyd +++ b/bin/monipyd @@ -1,46 +1,40 @@ #!/usr/bin/python3 -d -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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 ' -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() diff --git a/etc/monipy.ini b/etc/monipy.ini new file mode 100644 index 0000000..db606ec --- /dev/null +++ b/etc/monipy.ini @@ -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] diff --git a/etc/monipy/monipy.json b/etc/monipy/monipy.json deleted file mode 100644 index e69de29..0000000 diff --git a/etc/monipy/monitors/network1/cable_uplink.json b/etc/monipy/monitors/network1/cable_uplink.json deleted file mode 100644 index c2e8a24..0000000 --- a/etc/monipy/monitors/network1/cable_uplink.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "uplink", - "interval": 60, - "notification": "sms", - "host": "192.168.0.1", - "user": "USERNAME", - "password": "PASSWORD", - "info": "Cable Provider" -} \ No newline at end of file diff --git a/etc/monipy/monitors/network1/gateway.ini b/etc/monipy/monitors/network1/gateway.ini new file mode 100644 index 0000000..baf4578 --- /dev/null +++ b/etc/monipy/monitors/network1/gateway.ini @@ -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 \ No newline at end of file diff --git a/etc/monipy/monitors/network2/dsl_uplink.json b/etc/monipy/monitors/network2/dsl_uplink.json deleted file mode 100644 index a7286ce..0000000 --- a/etc/monipy/monitors/network2/dsl_uplink.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "uplink", - "interval": 60, - "notification": "sms", - "host": "192.168.1.1", - "user": "USERNAME", - "password": "PASSWORD", - "info": "DSL Provider" -} \ No newline at end of file diff --git a/etc/monipy/monitors/network2/gateway.ini b/etc/monipy/monitors/network2/gateway.ini new file mode 100644 index 0000000..315f369 --- /dev/null +++ b/etc/monipy/monitors/network2/gateway.ini @@ -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 diff --git a/etc/monipy/notifications/email.ini b/etc/monipy/notifications/email.ini new file mode 100644 index 0000000..215d9a9 --- /dev/null +++ b/etc/monipy/notifications/email.ini @@ -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 \ No newline at end of file diff --git a/etc/monipy/plugins/httpserver.ini b/etc/monipy/plugins/httpserver.ini new file mode 100644 index 0000000..b832680 --- /dev/null +++ b/etc/monipy/plugins/httpserver.ini @@ -0,0 +1,3 @@ +[httpserver] +ip = 127.0.0.1 +port = 4242 \ No newline at end of file diff --git a/TODO b/etc/monipy/types/.gitkeep similarity index 100% rename from TODO rename to etc/monipy/types/.gitkeep diff --git a/monipy/configuration.py b/monipy/configuration.py index a1f0a0b..904bdd7 100644 --- a/monipy/configuration.py +++ b/monipy/configuration.py @@ -1,29 +1,76 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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 diff --git a/monipy/daemon.py b/monipy/daemon.py index dc96747..34f4b4b 100644 --- a/monipy/daemon.py +++ b/monipy/daemon.py @@ -1,22 +1,25 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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(). """ diff --git a/monipy/environment.py b/monipy/environment.py index 2e7bf9f..8976e60 100644 --- a/monipy/environment.py +++ b/monipy/environment.py @@ -1,29 +1,53 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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 diff --git a/monipy/logger.py b/monipy/logger.py new file mode 100644 index 0000000..0b7d80b --- /dev/null +++ b/monipy/logger.py @@ -0,0 +1,39 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/model.py b/monipy/model.py new file mode 100644 index 0000000..d7232e3 --- /dev/null +++ b/monipy/model.py @@ -0,0 +1,34 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/monipy.py b/monipy/monipy.py index a18537e..b61d697 100644 --- a/monipy/monipy.py +++ b/monipy/monipy.py @@ -1,26 +1,29 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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: diff --git a/monipy/monipyd.py b/monipy/monipyd.py index 646f405..ea3651d 100644 --- a/monipy/monipyd.py +++ b/monipy/monipyd.py @@ -1,31 +1,35 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 + +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 diff --git a/monipy/monitor.py b/monipy/monitor.py new file mode 100644 index 0000000..7280c36 --- /dev/null +++ b/monipy/monitor.py @@ -0,0 +1,33 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/monitors.py b/monipy/monitors.py new file mode 100644 index 0000000..61177cb --- /dev/null +++ b/monipy/monitors.py @@ -0,0 +1,33 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/notications/email.py b/monipy/notications/email.py new file mode 100644 index 0000000..24b00a0 --- /dev/null +++ b/monipy/notications/email.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/notications/network/__init__.py b/monipy/notications/network/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monipy/notications/network/email.py b/monipy/notications/network/email.py deleted file mode 100644 index 8b0d7f9..0000000 --- a/monipy/notications/network/email.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/notications/notification.py b/monipy/notications/notification.py deleted file mode 100644 index e6d8127..0000000 --- a/monipy/notications/notification.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/notications/phone/__init__.py b/monipy/notications/phone/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monipy/notications/phone/sms.py b/monipy/notications/phone/sms.py deleted file mode 100644 index 593ddcd..0000000 --- a/monipy/notications/phone/sms.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/notications/sms.py b/monipy/notications/sms.py new file mode 100644 index 0000000..2d22fa0 --- /dev/null +++ b/monipy/notications/sms.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/notification.py b/monipy/notification.py new file mode 100644 index 0000000..9612aca --- /dev/null +++ b/monipy/notification.py @@ -0,0 +1,33 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/notifications.py b/monipy/notifications.py new file mode 100644 index 0000000..1190a90 --- /dev/null +++ b/monipy/notifications.py @@ -0,0 +1,34 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugin.py b/monipy/plugin.py new file mode 100644 index 0000000..70bec99 --- /dev/null +++ b/monipy/plugin.py @@ -0,0 +1,33 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugins.py b/monipy/plugins.py new file mode 100644 index 0000000..9781587 --- /dev/null +++ b/monipy/plugins.py @@ -0,0 +1,34 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugins/httpserver.py b/monipy/plugins/httpserver.py new file mode 100644 index 0000000..de76c20 --- /dev/null +++ b/monipy/plugins/httpserver.py @@ -0,0 +1,105 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 '[monipy-' + \ + self.__environment.get_env_var("__version__") + '@' + \ + self.__environment.get_env_var("_hostname") + '] configuration
' + \
+               json.dumps(vars(self.__configuration), sort_keys=True, indent=4) + \
+               '
' + + @cherrypy.expose + def environment(self): + return '[monipy-' + \ + self.__environment.get_env_var("__version__") + '@' + \ + self.__environment.get_env_var("_hostname") + '] environment
' + \
+               json.dumps(vars(self.__environment), sort_keys=True, indent=4) + \
+               '
' + + @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) diff --git a/monipy/plugins/mariadb.py b/monipy/plugins/mariadb.py new file mode 100644 index 0000000..51f4bed --- /dev/null +++ b/monipy/plugins/mariadb.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugins/network/__init__.py b/monipy/plugins/network/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monipy/plugins/network/httpserver.py b/monipy/plugins/network/httpserver.py deleted file mode 100644 index 599021b..0000000 --- a/monipy/plugins/network/httpserver.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/plugins/plugin.py b/monipy/plugins/plugin.py deleted file mode 100644 index c7354cd..0000000 --- a/monipy/plugins/plugin.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/plugins/redis.py b/monipy/plugins/redis.py new file mode 100644 index 0000000..903f5f2 --- /dev/null +++ b/monipy/plugins/redis.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugins/sqlite.py b/monipy/plugins/sqlite.py new file mode 100644 index 0000000..d450eae --- /dev/null +++ b/monipy/plugins/sqlite.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/plugins/storage/__init__.py b/monipy/plugins/storage/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monipy/plugins/storage/mariadb.py b/monipy/plugins/storage/mariadb.py deleted file mode 100644 index 8623caa..0000000 --- a/monipy/plugins/storage/mariadb.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/plugins/storage/redis.py b/monipy/plugins/storage/redis.py deleted file mode 100644 index 6fcd4d4..0000000 --- a/monipy/plugins/storage/redis.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/plugins/storage/sqlite.py b/monipy/plugins/storage/sqlite.py deleted file mode 100644 index 9ca17ba..0000000 --- a/monipy/plugins/storage/sqlite.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/type.py b/monipy/type.py new file mode 100644 index 0000000..d69dad4 --- /dev/null +++ b/monipy/type.py @@ -0,0 +1,33 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types.py b/monipy/types.py new file mode 100644 index 0000000..61c143d --- /dev/null +++ b/monipy/types.py @@ -0,0 +1,34 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types/fritzbox.py b/monipy/types/fritzbox.py new file mode 100644 index 0000000..17f85eb --- /dev/null +++ b/monipy/types/fritzbox.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types/network/__init__.py b/monipy/types/network/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monipy/types/network/ping.py b/monipy/types/network/ping.py deleted file mode 100644 index aad6623..0000000 --- a/monipy/types/network/ping.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/types/network/port.py b/monipy/types/network/port.py deleted file mode 100644 index c755d28..0000000 --- a/monipy/types/network/port.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/types/network/speedtest.py b/monipy/types/network/speedtest.py deleted file mode 100644 index 8721c89..0000000 --- a/monipy/types/network/speedtest.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/types/network/uplink.py b/monipy/types/network/uplink.py deleted file mode 100644 index 3972fe6..0000000 --- a/monipy/types/network/uplink.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/monipy/types/ping.py b/monipy/types/ping.py new file mode 100644 index 0000000..213ff8c --- /dev/null +++ b/monipy/types/ping.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types/port.py b/monipy/types/port.py new file mode 100644 index 0000000..71817cd --- /dev/null +++ b/monipy/types/port.py @@ -0,0 +1,35 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types/speedtest.py b/monipy/types/speedtest.py new file mode 100644 index 0000000..063e94e --- /dev/null +++ b/monipy/types/speedtest.py @@ -0,0 +1,94 @@ +""" +This file is part of monipy (https://hanez.org/monipy/) +Copyright (c) 2022 Johannes Findeisen + +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 diff --git a/monipy/types/type.py b/monipy/types/type.py deleted file mode 100644 index 8594bcb..0000000 --- a/monipy/types/type.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2022 Johannes Findeisen -# -# 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 diff --git a/requirements.txt b/requirements.txt index e69de29..48b8acd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests~=2.28.1 # used by speedtest type +CherryPy~=18.8.0 # used by httpserver plugin \ No newline at end of file