Actions API: added acknowledgements

Change-Id: Ie2554dee8a207fe8b4f582fec82abdffc32a054f
This commit is contained in:
aviau 2015-04-27 11:35:43 -04:00
parent 599c58e36c
commit 60058195b0
5 changed files with 131 additions and 0 deletions

View File

@ -14,8 +14,11 @@
from pecan import rest
from surveil.api.controllers.v2.actions import acknowledge
class ActionsController(rest.RestController):
acknowledge = acknowledge.AcknowledgeController()
# externalcommands = ExternalCommandsController()
# engine = EngineController()
pass

View File

@ -0,0 +1,40 @@
# 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 pecan
from pecan import rest
import requests
import wsmeext.pecan as wsme_pecan
from surveil.api.datamodel.actions import acknowledgement
from surveil.api.datamodel import info
class AcknowledgeController(rest.RestController):
@wsme_pecan.wsexpose(info.Info,
body=acknowledgement.Acknowledgement,
status_code=200)
def post(self, ack):
"""Acknowledge a host/service."""
data = ack.as_dict()
data.update({'action': 'add'})
requests.post(
pecan.request.ws_arbiter_url + "/acknowledge",
data=data
)
return info.Info(message='Acknowledgement received. %s' % data)

View File

@ -0,0 +1,50 @@
# 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
import wsme.types as wtypes
from surveil.api.datamodel import types
class Acknowledgement(types.Base):
host_name = wsme.wsattr(wtypes.text, mandatory=True)
"""The name of the host"""
service_description = wsme.wsattr(wtypes.text, mandatory=False)
time_stamp = wsme.wsattr(wtypes.text, mandatory=False)
sticky = wsme.wsattr(int, mandatory=False)
notify = wsme.wsattr(int, mandatory=False)
persistent = wsme.wsattr(int, mandatory=False)
author = wsme.wsattr(wtypes.text, mandatory=False)
comment = wsme.wsattr(wtypes.text, mandatory=False)
@classmethod
def sample(cls):
return cls(
host_name="localhost",
service_description="ws-arbiter",
time_stamp="",
sticky=1,
notify=0,
persistent=1,
author="aviau",
comment="Working on it.",
)

View File

@ -0,0 +1,38 @@
# 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 httpretty
from surveil.tests.api import functionalTest
class TestAcknowledgeController(functionalTest.FunctionalTest):
@httpretty.activate
def test_acknowledge(self):
httpretty.register_uri(httpretty.POST,
self.ws_arbiter_url + "/acknowledge")
ack = {
"host_name": "localhost"
}
response = self.app.post_json("/v2/actions/acknowledge/", params=ack)
self.assertEqual(response.status_int, 200)
self.assertEqual(httpretty.last_request().body,
'action=add&host_name=localhost')
self.assertEqual(httpretty.last_request().path,
'/acknowledge')