diff --git a/surveilclient/tests/v2_0/actions/test_recheck.py b/surveilclient/tests/v2_0/actions/test_recheck.py new file mode 100644 index 0000000..fb83908 --- /dev/null +++ b/surveilclient/tests/v2_0/actions/test_recheck.py @@ -0,0 +1,37 @@ +# Copyright 2015 - 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 json + +import httpretty + +from surveilclient.tests.v2_0 import clienttest + + +class TestRecheck(clienttest.ClientTest): + + @httpretty.activate + def test_create(self): + httpretty.register_uri( + httpretty.POST, "http://localhost:8080/v2/actions/recheck", + body='{"message": "Ack received!"}') + + self.client.actions.recheck.create( + host_name="somehost", + service_description="someservice" + ) + + self.assertEqual( + json.loads(httpretty.last_request().body.decode()), + {"host_name": "somehost", "service_description": "someservice"} + ) diff --git a/surveilclient/v2_0/actions/__init__.py b/surveilclient/v2_0/actions/__init__.py index 48c0315..03948a6 100644 --- a/surveilclient/v2_0/actions/__init__.py +++ b/surveilclient/v2_0/actions/__init__.py @@ -15,6 +15,7 @@ from surveilclient.common import surveil_manager from surveilclient.v2_0.actions import acknowledge from surveilclient.v2_0.actions import downtime +from surveilclient.v2_0.actions import recheck class ActionsManager(surveil_manager.SurveilManager): @@ -24,3 +25,4 @@ class ActionsManager(surveil_manager.SurveilManager): super(ActionsManager, self).__init__(http_client) self.downtime = downtime.DowntimeManager(self.http_client) self.acknowledge = acknowledge.AcknowledgeManager(self.http_client) + self.recheck = recheck.RecheckManager(self.http_client) diff --git a/surveilclient/v2_0/actions/recheck.py b/surveilclient/v2_0/actions/recheck.py new file mode 100644 index 0000000..103303a --- /dev/null +++ b/surveilclient/v2_0/actions/recheck.py @@ -0,0 +1,27 @@ +# Copyright 2015 - 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. + +from surveilclient.common import surveil_manager + + +class RecheckManager(surveil_manager.SurveilManager): + base_url = '/actions/recheck' + + def create(self, **kwargs): + resp, body = self.http_client.json_request( + self.base_url, + 'POST', + body=kwargs, + ) + return body diff --git a/surveilclient/v2_0/shell.py b/surveilclient/v2_0/shell.py index 1a680bc..a4dfbbd 100644 --- a/surveilclient/v2_0/shell.py +++ b/surveilclient/v2_0/shell.py @@ -283,3 +283,16 @@ def do_status_service_list(sc, args): 'plugin_output': lambda x: x.get('plugin_output', '')[0:30], } utils.print_list(services, cols, formatters=formatters) + + +@cliutils.arg("host_name", help="Name of the host") +@cliutils.arg("--service_description", help="Service description") +@cliutils.arg("--time_stamp") +def do_action_recheck(sc, args): + """Schedule a recheck.""" + arg_names = ['host_name', + 'service_description', + 'time_stamp'] + + recheck = _dict_from_args(args, arg_names) + sc.actions.recheck.create(**recheck)