Initial sketch of what monsetup could look like

This commit is contained in:
Tim Kuhlman 2014-06-05 10:56:13 -06:00
parent 08611edad8
commit 035722b296
7 changed files with 137 additions and 1 deletions

9
monsetup/README.md Normal file
View File

@ -0,0 +1,9 @@
# mon-setup
This script will detect running services and configure mon-agent to watch them as well as starting the agent and
configuring it to start up on boot.
## Future Considerations
- A good system for specifying active style checks for configuration would be great. Active style checks are those
which run locally but are checking a remote box.

48
monsetup/__init__.py Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env python
""" Detect running daemons then configure and start the agent.
"""
import argparse
import sys
import detection
import service
DETECTION_CLASSES = [detection.Core]
OS_SERVICE_MAP = {'linux': service.sysv.SysV}
def main(argv=None):
parser = argparse.ArgumentParser(description='Detect running daemons then configure and start the agent.')
# parser.add_argument('--foo')
# - It will need to be invoked with keystone credentials. Other options you can invoke with include:
# - non-interactive
# - force overwrite of existing config
# - alternative config output directory
# - Optional active check config to include -
args = parser.parse_args()
# todo these are currently hardcoded
config_dir = '/etc/mon-agent'
overwrite = True
# todo add the ability to build the config in a temp dir then diff
# Detect os
detected_os = 'linux' # todo add detection
# Run through detection and config building
for detect_class in DETECTION_CLASSES:
detect = detect_class(config_dir, overwrite)
detect.build_config()
# Service enable/start
agent_service = OS_SERVICE_MAP[detected_os]
# Todo add logic for situations where either enable or start is not needed or if not running as root isn't possible
agent_service.enable()
agent_service.start(restart=True)
if __name__ == "__main__":
sys.exit(main())

View File

@ -0,0 +1,23 @@
"""Classes for detection of running resources to be monitored.
Detection classes should be platform independent
"""
class Base(object):
"""Base detection class implementing the interface."""
def __init__(self, config_dir, overwrite=True):
self.config_dir = config_dir
self.overwrite = overwrite
def build_config(self):
raise NotImplementedError
class Core(Base):
"""Detect details related to the core mon-agent configuration."""
class Plugin(Base):
"""Abstract class implemented by the mon-agent plugin detection classes"""
# todo these should include dependency detection

View File

@ -0,0 +1,5 @@
from . import Plugin
class Nova(Plugin):
"""Detect Nova daemons and setup configuration to monitor them."""

View File

@ -0,0 +1,35 @@
"""Classes implementing different methods for running mon-agent on startup as well as starting the process immediately
"""
class Service(object):
"""Abstract base class implementing the interface for various service types."""
def __init__(self, name='mon-agent'):
self.name = name
def enable(self):
"""Sets mon-agent to start on boot.
Generally this requires running as super user
"""
raise NotImplementedError
def start(self, restart=True):
"""Starts mon-agent
If the agent is running and restart is True, restart
"""
raise NotImplementedError
def stop(self):
"""Stops mon-agent
"""
raise NotImplementedError
def is_enabled(self):
"""Returns True if mon-agent is setup to start on boot, false otherwise
"""
raise NotImplementedError
def is_running(self):
"""Returns True if mon-agent is running, false otherwise
"""
raise NotImplementedError

15
monsetup/service/sysv.py Normal file
View File

@ -0,0 +1,15 @@
"""System V style service.
"""
from . import Service
class SysV(Service):
def __init__(self, init_template):
"""Setup this service with the given init template"""
super(SysV, self).__init__()
self.init_template = init_template
# todo largely unimplemented, all needed files end up in /usr/local/share/mon/agent
# todo don't forget to setup the proper users for the agent to run as
# todo will need to setup supervisor.con

View File

@ -132,7 +132,8 @@ setup(
'console_scripts': [
'mon-forwarder = monagent.forwarder:main',
'mon-collector = monagent.collector.daemon:main',
'monstatsd = monagent.monstatsd:main'
'monstatsd = monagent.monstatsd:main',
'mon-setup = monsetup:main'
],
},
include_package_data=True,