diff --git a/README.md b/README.md index b2d0e79..3d5e8b9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 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. +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 @@ -15,23 +15,35 @@ 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! +### Ideas + +- MAYBE rename this project to linspector and see it as an update. This is a nice idea +because [Linspector](https://hanez.org/linspector/) has it's GitHub organisation, +domain etc. And all I do here is +a better Linspector. Even all nice and useful features and ideas from Linspector but +also uplink should be reimplemented here. + +- Think about adding [APScheduler](https://pypi.org/project/APScheduler/) for +scheduling execution of the monitors instead of a self constructed thread +structure... was very nice to get the job done in Linspector. + +### 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. + ### Version numbering According to: [https://wiki.unixpeople.org/linux_kernel_version_numbering](https://wiki.unixpeople.org/linux_kernel_version_numbering) diff --git a/bin/monipyd b/bin/monipy similarity index 85% rename from bin/monipyd rename to bin/monipy index 92cf249..c58ca93 100755 --- a/bin/monipyd +++ b/bin/monipy @@ -27,14 +27,16 @@ import sys from logging import getLogger -from monipy.configuration import Configuration -from monipy.environment import Environment -from monipy.monipyd import Monipyd +from monipy.core.configuration import Configuration +from monipy.core.environment import Environment +from monipy.core.monipy import Monipy +# will only be used when running in daemon mode. +# from monipy.core.monipyd import Monipyd __version__ = '0.1' __author__ = 'Johannes Findeisen ' -logger = getLogger('monipyd') +logger = getLogger('monipy') def parse_args(): @@ -62,8 +64,8 @@ def main(): sys.exit(1) environment = Environment(configuration) - - monipyd = Monipyd(configuration, environment) + monipy = Monipy(configuration, environment) + # monipyd = Monipyd(configuration, environment) if __name__ == '__main__': diff --git a/etc/monipy.ini b/etc/monipy.ini index db606ec..3aeeea1 100644 --- a/etc/monipy.ini +++ b/etc/monipy.ini @@ -8,7 +8,7 @@ ; report core errors to the following users error_receivers = admin@example.com log_file = ~/code/monipy/log/uplink.log -log_level = verbose +log_level= verbose log_count = 5 log_size = 10485760 pid_file = /var/run/user/1000/monipy.pid @@ -43,4 +43,5 @@ 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] +[types] +foo = bar \ No newline at end of file diff --git a/monipy/configuration.py b/monipy/core/configuration.py similarity index 82% rename from monipy/configuration.py rename to monipy/core/configuration.py index 904bdd7..8f53869 100644 --- a/monipy/configuration.py +++ b/monipy/core/configuration.py @@ -27,9 +27,11 @@ import os from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') +# TODO: check for all required configuration options and set defaults if needed. do this only for +# options in the "monipy" section of monipy.ini. class Configuration: def __init__(self, configuration_path): @@ -74,3 +76,11 @@ class Configuration: return self.__configuration.get(section, option) else: return None + + # this function can be called by notifications, plugins and types to set a default value if not + # configured. since all objects have access to the configuration this should not be done from + # any other place because it can break monipy. + # maybe it can be used for dynamic runtime configuration later but need to think about it. + def set_option(self, section, option, value): + if not self.__configuration.has_option(section, option): + self.__configuration.set(section, option, value) diff --git a/monipy/daemon.py b/monipy/core/daemon.py similarity index 99% rename from monipy/daemon.py rename to monipy/core/daemon.py index 34f4b4b..ded8b48 100644 --- a/monipy/daemon.py +++ b/monipy/core/daemon.py @@ -29,7 +29,7 @@ import time from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Daemon: diff --git a/monipy/environment.py b/monipy/core/environment.py similarity index 93% rename from monipy/environment.py rename to monipy/core/environment.py index 8976e60..843d8e3 100644 --- a/monipy/environment.py +++ b/monipy/core/environment.py @@ -23,11 +23,14 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Environment: - + """ + Object for storing environment variables at runtime. These variables must not affect the + stability of monipy. + """ def __init__(self, configuration): self.__configuration = configuration diff --git a/monipy/logger.py b/monipy/core/logger.py similarity index 98% rename from monipy/logger.py rename to monipy/core/logger.py index 0b7d80b..8193de1 100644 --- a/monipy/logger.py +++ b/monipy/core/logger.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') # The logger can be used by any monitor to write arbitrary data to any arbitrary place. diff --git a/monipy/model.py b/monipy/core/model.py similarity index 97% rename from monipy/model.py rename to monipy/core/model.py index d7232e3..5f17f07 100644 --- a/monipy/model.py +++ b/monipy/core/model.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Model: diff --git a/monipy/monipy.py b/monipy/core/monipy.py similarity index 97% rename from monipy/monipy.py rename to monipy/core/monipy.py index b61d697..5990eee 100644 --- a/monipy/monipy.py +++ b/monipy/core/monipy.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Monipy: diff --git a/monipy/monipyd.py b/monipy/core/monipyd.py similarity index 88% rename from monipy/monipyd.py rename to monipy/core/monipyd.py index ea3651d..42688cd 100644 --- a/monipy/monipyd.py +++ b/monipy/core/monipyd.py @@ -24,12 +24,13 @@ 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('monipyd') +logger = getLogger('monipy') +# TODO: check for all required configuration options and set defaults if needed. class Monipyd(Daemon): def __init__(self, configuration, environment): - super().__init__('/tmp/uplink.pid') + super().__init__(configuration.get_option('monipy', 'pid_file')) self.__configuration = configuration self.__environment = environment diff --git a/monipy/monitor.py b/monipy/core/monitor.py similarity index 97% rename from monipy/monitor.py rename to monipy/core/monitor.py index 7280c36..2262f24 100644 --- a/monipy/monitor.py +++ b/monipy/core/monitor.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Monitor: diff --git a/monipy/monitors.py b/monipy/core/monitors.py similarity index 84% rename from monipy/monitors.py rename to monipy/core/monitors.py index 61177cb..87bfd74 100644 --- a/monipy/monitors.py +++ b/monipy/core/monitors.py @@ -23,9 +23,12 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') +# monitors could, should be added (and maybe changed) at runtime to add new monitors without +# restarting the daemon. maybe add a reset function to each monitor to reset the monitor at runtime +# when changed dynamically. class Monitors: def __init__(self, configuration, environment): diff --git a/monipy/notification.py b/monipy/core/notification.py similarity index 97% rename from monipy/notification.py rename to monipy/core/notification.py index 9612aca..d71a2be 100644 --- a/monipy/notification.py +++ b/monipy/core/notification.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Notification: diff --git a/monipy/notifications.py b/monipy/core/notifications.py similarity index 97% rename from monipy/notifications.py rename to monipy/core/notifications.py index 1190a90..beb6bb1 100644 --- a/monipy/notifications.py +++ b/monipy/core/notifications.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Notifications: diff --git a/monipy/plugin.py b/monipy/core/plugin.py similarity index 97% rename from monipy/plugin.py rename to monipy/core/plugin.py index 70bec99..3e22dfe 100644 --- a/monipy/plugin.py +++ b/monipy/core/plugin.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Plugin: diff --git a/monipy/plugins.py b/monipy/core/plugins.py similarity index 97% rename from monipy/plugins.py rename to monipy/core/plugins.py index 9781587..8682f40 100644 --- a/monipy/plugins.py +++ b/monipy/core/plugins.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Plugins: diff --git a/monipy/type.py b/monipy/core/type.py similarity index 97% rename from monipy/type.py rename to monipy/core/type.py index d69dad4..b08e28e 100644 --- a/monipy/type.py +++ b/monipy/core/type.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Type: diff --git a/monipy/types.py b/monipy/core/types.py similarity index 97% rename from monipy/types.py rename to monipy/core/types.py index 61c143d..ef30e8c 100644 --- a/monipy/types.py +++ b/monipy/core/types.py @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from logging import getLogger -logger = getLogger('monipyd') +logger = getLogger('monipy') class Types: diff --git a/monipy/notications/email.py b/monipy/notications/email.py index 24b00a0..fbac23f 100644 --- a/monipy/notications/email.py +++ b/monipy/notications/email.py @@ -22,7 +22,7 @@ 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 +from monipy.core.notification import Notification logger = getLogger('monipyd') diff --git a/monipy/notications/sms.py b/monipy/notications/sms.py index 2d22fa0..dc8cf4b 100644 --- a/monipy/notications/sms.py +++ b/monipy/notications/sms.py @@ -22,9 +22,9 @@ 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 +from monipy.core.notification import Notification -logger = getLogger('monipyd') +logger = getLogger('monipy') class SmsNotification(Notification): diff --git a/monipy/plugins/httpserver.py b/monipy/plugins/httpserver.py index de76c20..4109873 100644 --- a/monipy/plugins/httpserver.py +++ b/monipy/plugins/httpserver.py @@ -25,11 +25,12 @@ import cherrypy import json from logging import getLogger -from monipy.plugins.plugin import Plugin +from monipy.core.plugin import Plugin -logger = getLogger('monipyd') +logger = getLogger('monipy') +# TODO: check for all required configuration options and set defaults if needed. class HTTPServerPlugin(Plugin): def __init__(self, configuration, environment): diff --git a/monipy/plugins/mariadb.py b/monipy/plugins/mariadb.py index 51f4bed..43b49d3 100644 --- a/monipy/plugins/mariadb.py +++ b/monipy/plugins/mariadb.py @@ -22,11 +22,12 @@ 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 +from monipy.core.plugin import Plugin -logger = getLogger('monipyd') +logger = getLogger('monipy') +# TODO: check for all required configuration options and set defaults if needed. class MariadbPlugin(Plugin): def __init__(self, configuration, environment): diff --git a/monipy/plugins/redis.py b/monipy/plugins/redis.py index 903f5f2..2641631 100644 --- a/monipy/plugins/redis.py +++ b/monipy/plugins/redis.py @@ -22,11 +22,12 @@ 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 +from monipy.core.plugin import Plugin -logger = getLogger('monipyd') +logger = getLogger('monipy') +# TODO: check for all required configuration options and set defaults if needed. class RedisPlugin(Plugin): def __init__(self, configuration, environment): diff --git a/monipy/plugins/sqlite.py b/monipy/plugins/sqlite.py index d450eae..664647c 100644 --- a/monipy/plugins/sqlite.py +++ b/monipy/plugins/sqlite.py @@ -22,11 +22,12 @@ 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 +from monipy.core.plugin import Plugin logger = getLogger('monipyd') +# TODO: check for all required configuration options and set defaults if needed. class SqlitePlugin(Plugin): def __init__(self, configuration, environment): diff --git a/monipy/types/__init__.py b/monipy/services/__init__.py similarity index 100% rename from monipy/types/__init__.py rename to monipy/services/__init__.py diff --git a/monipy/types/fritzbox.py b/monipy/services/fritzbox.py similarity index 88% rename from monipy/types/fritzbox.py rename to monipy/services/fritzbox.py index 17f85eb..c3b00c2 100644 --- a/monipy/types/fritzbox.py +++ b/monipy/services/fritzbox.py @@ -22,12 +22,13 @@ 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 +from monipy.core.monitor import Monitor -logger = getLogger('monipyd') +logger = getLogger('monipy') -class FritzboxType(Type): +# TODO: check for all required configuration options and set defaults if needed. +class FritzboxMonitor(Monitor): def __init__(self, configuration, environment): super().__init__(configuration, environment) diff --git a/monipy/types/ping.py b/monipy/services/ping.py similarity index 88% rename from monipy/types/ping.py rename to monipy/services/ping.py index 213ff8c..3297f52 100644 --- a/monipy/types/ping.py +++ b/monipy/services/ping.py @@ -22,12 +22,13 @@ 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 +from monipy.core.monitor import Monitor -logger = getLogger('monipyd') +logger = getLogger('monipy') -class PingType(Type): +# TODO: check for all required configuration options and set defaults if needed. +class PingMonitor(Monitor): def __init__(self, configuration, environment): super().__init__(configuration, environment) diff --git a/monipy/types/port.py b/monipy/services/port.py similarity index 88% rename from monipy/types/port.py rename to monipy/services/port.py index 71817cd..0d62e7f 100644 --- a/monipy/types/port.py +++ b/monipy/services/port.py @@ -22,12 +22,13 @@ 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 +from monipy.core.monitor import Monitor -logger = getLogger('monipyd') +logger = getLogger('monipy') -class PortType(Type): +# TODO: check for all required configuration options and set defaults if needed. +class PortType(Monitor): def __init__(self, configuration, environment): super().__init__(configuration, environment) diff --git a/monipy/types/speedtest.py b/monipy/services/speedtest.py similarity index 95% rename from monipy/types/speedtest.py rename to monipy/services/speedtest.py index 063e94e..e82d5c8 100644 --- a/monipy/types/speedtest.py +++ b/monipy/services/speedtest.py @@ -27,12 +27,13 @@ import time from logging import getLogger -from monipy.types.type import Type +from monipy.core.monitor import Monitor -logger = getLogger('monipyd') +logger = getLogger('monipy') -class SpeedtestType(Type): +# TODO: check for all required configuration options and set defaults if needed. +class SpeedtestMonitor(Monitor): def __init__(self, configuration, environment): super().__init__(configuration, environment)