diff --git a/Dockerfile b/Dockerfile index 896f5f0..8083aa4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,11 @@ MAINTAINER Alexandre Viau RUN apt-get update -RUN apt-get install -y vim +RUN apt-get install -y vim supervisor ### Shinken RUN apt-get install -y python-pip -RUN useradd shinken && pip install https://github.com/naparuba/shinken/archive/master.tar.gz +RUN useradd shinken && pip install https://github.com/naparuba/shinken/archive/2.2-RC1.zip RUN apt-get install -y python-pycurl RUN shinken --init @@ -44,6 +44,9 @@ ADD tools/docker/etc/shinken /etc/shinken RUN chown -R root:shinken /etc/shinken ### Surveil +## Package deps +RUN apt-get install -y python3-pip python-dev libffi-dev libssl-dev + ## Copy files ADD surveil /surveil/surveil ADD setup.cfg /surveil/setup.cfg @@ -53,13 +56,11 @@ ADD .git /surveil/.git ADD README.rst surveil/README.rst ## Install -RUN apt-get install -y python3-pip python-dev libffi-dev libssl-dev RUN pip install -r /surveil/requirements.txt RUN apt-get install -y git RUN cd surveil && python setup.py install ### Supervisor -RUN apt-get -y install supervisor ADD tools/docker/etc/supervisor /etc/supervisor # Shinken WEBUI diff --git a/surveil/api/controllers/v1/datamodel/info.py b/surveil/api/controllers/v1/datamodel/info.py new file mode 100644 index 0000000..75c5b29 --- /dev/null +++ b/surveil/api/controllers/v1/datamodel/info.py @@ -0,0 +1,19 @@ +# Copyright 2014 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import wsme + + +class Info(wsme.types.Base): + message = wsme.types.text \ No newline at end of file diff --git a/surveil/api/controllers/v1/reload_config.py b/surveil/api/controllers/v1/reload_config.py new file mode 100644 index 0000000..5e598c6 --- /dev/null +++ b/surveil/api/controllers/v1/reload_config.py @@ -0,0 +1,33 @@ +# Copyright 2014 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import pecan +from pecan import rest +import requests +import wsmeext.pecan as wsme_pecan + +from surveil.api.controllers.v1.datamodel import info + + +class ReloadConfigController(rest.RestController): + + @wsme_pecan.wsexpose(info.Info) + def post(self): + """Reloads Shinken's config.""" + + requests.post( + pecan.request.ws_arbiter_url + "/reload" + ) + + return info.Info(message='Arbiter reloading.') diff --git a/surveil/api/controllers/v1/v1.py b/surveil/api/controllers/v1/v1.py index b069f81..3f8f190 100644 --- a/surveil/api/controllers/v1/v1.py +++ b/surveil/api/controllers/v1/v1.py @@ -15,6 +15,7 @@ from surveil.api.controllers.v1 import commands from surveil.api.controllers.v1 import hello from surveil.api.controllers.v1 import hosts +from surveil.api.controllers.v1 import reload_config from surveil.api.controllers.v1 import services @@ -24,3 +25,4 @@ class V1Controller(object): hosts = hosts.HostsController() commands = commands.CommandsController() services = services.ServicesController() + reload_config = reload_config.ReloadConfigController() diff --git a/surveil/cmd/os_discovery.py b/surveil/cmd/os_discovery.py index 09150af..b8de827 100644 --- a/surveil/cmd/os_discovery.py +++ b/surveil/cmd/os_discovery.py @@ -122,6 +122,8 @@ def main(args=None): } ) + # Reload the surveil config + cli_surveil.reload_config() if __name__ == '__main__': sys.exit(main()) diff --git a/surveil/tests/api/controllers/v1/test_reload_config.py b/surveil/tests/api/controllers/v1/test_reload_config.py new file mode 100644 index 0000000..0b4f32e --- /dev/null +++ b/surveil/tests/api/controllers/v1/test_reload_config.py @@ -0,0 +1,32 @@ +# Copyright 2014 - Savoir-Faire Linux inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import httpretty + +from surveil.tests.api import functionalTest + + +class TestReloadConfigController(functionalTest.FunctionalTest): + + @httpretty.activate + def test_reload_config(self): + httpretty.register_uri(httpretty.POST, + self.ws_arbiter_url + "/reload") + + response = self.app.post("/v1/reload_config") + self.assertEqual(response.status_int, 200) + self.assertEqual( + httpretty.last_request().path, + '/reload' + ) diff --git a/tools/docker/etc/shinken/arbiters/arbiter-master.cfg b/tools/docker/etc/shinken/arbiters/arbiter-master.cfg index a97da46..aa724d1 100644 --- a/tools/docker/etc/shinken/arbiters/arbiter-master.cfg +++ b/tools/docker/etc/shinken/arbiters/arbiter-master.cfg @@ -35,7 +35,7 @@ define arbiter { # - FileTag = Tag an host if it's on a flat file # - CSVTag = Tag an host from the content of a CSV file - modules named-pipe,mongodb + modules named-pipe,mongodb,ws-arbiter #modules named-pipe, mongodb, nsca, VMWare_auto_linking, ws-arbiter, Collectd, mport-landscape, SnmpBooster, AWS # Enable https or not diff --git a/tools/docker/etc/shinken/commands/reload-shinken.cfg b/tools/docker/etc/shinken/commands/reload-shinken.cfg index 228d299..3bc9110 100644 --- a/tools/docker/etc/shinken/commands/reload-shinken.cfg +++ b/tools/docker/etc/shinken/commands/reload-shinken.cfg @@ -1,5 +1,5 @@ define command { command_name reload-shinken - command_line sudo /etc/init.d/shinken reload + command_line /etc/init.d/shinken reload } diff --git a/tools/docker/etc/shinken/commands/restart-shinken.cfg b/tools/docker/etc/shinken/commands/restart-shinken.cfg index 5fdcba7..4c05ce7 100644 --- a/tools/docker/etc/shinken/commands/restart-shinken.cfg +++ b/tools/docker/etc/shinken/commands/restart-shinken.cfg @@ -1,5 +1,5 @@ define command { command_name restart-shinken - command_line sudo /etc/init.d/shinken restart + command_line /etc/init.d/shinken restart } diff --git a/tools/docker/etc/shinken/receivers/receiver-master.cfg b/tools/docker/etc/shinken/receivers/receiver-master.cfg index 7067a8f..0a03f37 100644 --- a/tools/docker/etc/shinken/receivers/receiver-master.cfg +++ b/tools/docker/etc/shinken/receivers/receiver-master.cfg @@ -22,7 +22,7 @@ define receiver { # - TSCA = TSCA server # - ws-arbiter = WebService for pushing results to the arbiter # - Collectd = Receive collectd perfdata - modules ws-arbiter + modules # Enable https or not use_ssl 0