Merge "Add recheck command"

This commit is contained in:
Jenkins 2015-05-13 20:43:09 +00:00 committed by Gerrit Code Review
commit 2481fd67d7
4 changed files with 79 additions and 0 deletions

View File

@ -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"}
)

View File

@ -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)

View File

@ -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

View File

@ -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)