diff --git a/monsetup/README.md b/monsetup/README.md new file mode 100644 index 00000000..deea6cdd --- /dev/null +++ b/monsetup/README.md @@ -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. \ No newline at end of file diff --git a/monsetup/__init__.py b/monsetup/__init__.py new file mode 100644 index 00000000..9c0d1e7d --- /dev/null +++ b/monsetup/__init__.py @@ -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()) \ No newline at end of file diff --git a/monsetup/detection/__init__.py b/monsetup/detection/__init__.py new file mode 100644 index 00000000..1fd381a3 --- /dev/null +++ b/monsetup/detection/__init__.py @@ -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 \ No newline at end of file diff --git a/monsetup/detection/nova.py b/monsetup/detection/nova.py new file mode 100644 index 00000000..59a7bbbb --- /dev/null +++ b/monsetup/detection/nova.py @@ -0,0 +1,5 @@ +from . import Plugin + + +class Nova(Plugin): + """Detect Nova daemons and setup configuration to monitor them.""" diff --git a/monsetup/service/__init__.py b/monsetup/service/__init__.py new file mode 100644 index 00000000..37c09ef8 --- /dev/null +++ b/monsetup/service/__init__.py @@ -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 diff --git a/monsetup/service/sysv.py b/monsetup/service/sysv.py new file mode 100644 index 00000000..2d3f5027 --- /dev/null +++ b/monsetup/service/sysv.py @@ -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 \ No newline at end of file diff --git a/setup.py b/setup.py index 3b4ad185..4d3f520f 100644 --- a/setup.py +++ b/setup.py @@ -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,