Lot of refactoring to prepare project renaming to my old and similiar project linspector
This commit is contained in:
parent
029fa05a32
commit
6ff165e761
29 changed files with 99 additions and 59 deletions
38
README.md
38
README.md
|
|
@ -7,7 +7,7 @@ me.
|
||||||
## About
|
## About
|
||||||
|
|
||||||
**monipy** contains some tools and a daemon to monitor your infrastructure. It
|
**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.
|
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
|
I design the software actually and try to convert my ideas to software. Code
|
||||||
|
|
@ -15,23 +15,35 @@ nearly does not exist.
|
||||||
|
|
||||||
## Development
|
## 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
|
### To do
|
||||||
|
|
||||||
**Everything!** :) Just outlining the idea and creating code and structure skeletons
|
**Everything!** :) Just outlining the idea and creating code and structure skeletons
|
||||||
at the moment!
|
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
|
### Version numbering
|
||||||
|
|
||||||
According to: [https://wiki.unixpeople.org/linux_kernel_version_numbering](https://wiki.unixpeople.org/linux_kernel_version_numbering)
|
According to: [https://wiki.unixpeople.org/linux_kernel_version_numbering](https://wiki.unixpeople.org/linux_kernel_version_numbering)
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,16 @@ import sys
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
from monipy.configuration import Configuration
|
from monipy.core.configuration import Configuration
|
||||||
from monipy.environment import Environment
|
from monipy.core.environment import Environment
|
||||||
from monipy.monipyd import Monipyd
|
from monipy.core.monipy import Monipy
|
||||||
|
# will only be used when running in daemon mode.
|
||||||
|
# from monipy.core.monipyd import Monipyd
|
||||||
|
|
||||||
__version__ = '0.1'
|
__version__ = '0.1'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
|
@ -62,8 +64,8 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
environment = Environment(configuration)
|
environment = Environment(configuration)
|
||||||
|
monipy = Monipy(configuration, environment)
|
||||||
monipyd = Monipyd(configuration, environment)
|
# monipyd = Monipyd(configuration, environment)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
; report core errors to the following users
|
; report core errors to the following users
|
||||||
error_receivers = admin@example.com
|
error_receivers = admin@example.com
|
||||||
log_file = ~/code/monipy/log/uplink.log
|
log_file = ~/code/monipy/log/uplink.log
|
||||||
log_level = verbose
|
log_level= verbose
|
||||||
log_count = 5
|
log_count = 5
|
||||||
log_size = 10485760
|
log_size = 10485760
|
||||||
pid_file = /var/run/user/1000/monipy.pid
|
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.
|
; 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.
|
; 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
|
||||||
|
|
@ -27,9 +27,11 @@ import os
|
||||||
|
|
||||||
from logging import getLogger
|
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:
|
class Configuration:
|
||||||
|
|
||||||
def __init__(self, configuration_path):
|
def __init__(self, configuration_path):
|
||||||
|
|
@ -74,3 +76,11 @@ class Configuration:
|
||||||
return self.__configuration.get(section, option)
|
return self.__configuration.get(section, option)
|
||||||
else:
|
else:
|
||||||
return None
|
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)
|
||||||
|
|
@ -29,7 +29,7 @@ import time
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
|
|
@ -23,11 +23,14 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Environment:
|
class Environment:
|
||||||
|
"""
|
||||||
|
Object for storing environment variables at runtime. These variables must not affect the
|
||||||
|
stability of monipy.
|
||||||
|
"""
|
||||||
def __init__(self, configuration):
|
def __init__(self, configuration):
|
||||||
self.__configuration = configuration
|
self.__configuration = configuration
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
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.
|
# The logger can be used by any monitor to write arbitrary data to any arbitrary place.
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Model:
|
class Model:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Monipy:
|
class Monipy:
|
||||||
|
|
@ -24,12 +24,13 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from monipy.daemon import Daemon
|
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):
|
class Monipyd(Daemon):
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
super().__init__('/tmp/uplink.pid')
|
super().__init__(configuration.get_option('monipy', 'pid_file'))
|
||||||
self.__configuration = configuration
|
self.__configuration = configuration
|
||||||
self.__environment = environment
|
self.__environment = environment
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
|
|
@ -23,9 +23,12 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
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:
|
class Monitors:
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Notification:
|
class Notification:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Notifications:
|
class Notifications:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Plugins:
|
class Plugins:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Type:
|
class Type:
|
||||||
|
|
@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipy')
|
||||||
|
|
||||||
|
|
||||||
class Types:
|
class Types:
|
||||||
|
|
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from monipy.notications.notification import Notification
|
from monipy.core.notification import Notification
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipyd')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
class SmsNotification(Notification):
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,12 @@ import cherrypy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
class HTTPServerPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
class MariadbPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
class RedisPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from monipy.plugins.plugin import Plugin
|
from monipy.core.plugin import Plugin
|
||||||
|
|
||||||
logger = getLogger('monipyd')
|
logger = getLogger('monipyd')
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: check for all required configuration options and set defaults if needed.
|
||||||
class SqlitePlugin(Plugin):
|
class SqlitePlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, configuration, environment):
|
def __init__(self, configuration, environment):
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
def __init__(self, configuration, environment):
|
||||||
super().__init__(configuration, environment)
|
super().__init__(configuration, environment)
|
||||||
|
|
@ -22,12 +22,13 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
def __init__(self, configuration, environment):
|
||||||
super().__init__(configuration, environment)
|
super().__init__(configuration, environment)
|
||||||
|
|
@ -22,12 +22,13 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
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):
|
def __init__(self, configuration, environment):
|
||||||
super().__init__(configuration, environment)
|
super().__init__(configuration, environment)
|
||||||
|
|
@ -27,12 +27,13 @@ import time
|
||||||
from logging import getLogger
|
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):
|
def __init__(self, configuration, environment):
|
||||||
super().__init__(configuration, environment)
|
super().__init__(configuration, environment)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue