Merge "Added (host_name)/services to host controller"
This commit is contained in:
commit
d1a66be563
@ -19,6 +19,9 @@ Hosts
|
|||||||
.. rest-controller:: surveil.api.controllers.v1.hosts:HostController
|
.. rest-controller:: surveil.api.controllers.v1.hosts:HostController
|
||||||
:webprefix: /v1/hosts
|
:webprefix: /v1/hosts
|
||||||
|
|
||||||
|
.. rest-controller:: surveil.api.controllers.v1.hosts:HostServicesSubController
|
||||||
|
:webprefix: /v1/hosts/(host_name)/services
|
||||||
|
|
||||||
.. autotype:: surveil.api.controllers.v1.datamodel.host.Host
|
.. autotype:: surveil.api.controllers.v1.datamodel.host.Host
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
@ -17,13 +17,35 @@ from pecan import rest
|
|||||||
import wsmeext.pecan as wsme_pecan
|
import wsmeext.pecan as wsme_pecan
|
||||||
|
|
||||||
from surveil.api.controllers.v1.datamodel import host
|
from surveil.api.controllers.v1.datamodel import host
|
||||||
|
from surveil.api.controllers.v1.datamodel import service
|
||||||
|
|
||||||
|
|
||||||
|
class HostServicesSubController(rest.RestController):
|
||||||
|
|
||||||
|
@wsme_pecan.wsexpose([service.Service])
|
||||||
|
def get_all(self):
|
||||||
|
"""Returns all services assocaited with this host."""
|
||||||
|
mongo_s = [
|
||||||
|
s for s
|
||||||
|
in pecan.request.mongo_connection.shinken.services.find(
|
||||||
|
{"host_name": pecan.request.context['host_name']}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
services = [service.Service(**s) for s in mongo_s]
|
||||||
|
|
||||||
|
return services
|
||||||
|
|
||||||
|
|
||||||
|
class HostSubController(rest.RestController):
|
||||||
|
services = HostServicesSubController()
|
||||||
|
|
||||||
|
|
||||||
class HostController(rest.RestController):
|
class HostController(rest.RestController):
|
||||||
|
|
||||||
def __init__(self, host_id):
|
def __init__(self, host_name):
|
||||||
pecan.request.context['host_id'] = host_id
|
pecan.request.context['host_name'] = host_name
|
||||||
self._id = host_id
|
self._id = host_name
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(host.Host)
|
@wsme_pecan.wsexpose(host.Host)
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -56,12 +78,16 @@ class HostController(rest.RestController):
|
|||||||
{"host_name": self._id}
|
{"host_name": self._id}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@pecan.expose()
|
||||||
|
def _lookup(self, *remainder):
|
||||||
|
return HostSubController(), remainder
|
||||||
|
|
||||||
|
|
||||||
class HostsController(rest.RestController):
|
class HostsController(rest.RestController):
|
||||||
|
|
||||||
@pecan.expose()
|
@pecan.expose()
|
||||||
def _lookup(self, host_id, *remainder):
|
def _lookup(self, host_name, *remainder):
|
||||||
return HostController(host_id), remainder
|
return HostController(host_name), remainder
|
||||||
|
|
||||||
@wsme_pecan.wsexpose([host.Host])
|
@wsme_pecan.wsexpose([host.Host])
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
@ -79,4 +105,4 @@ class HostsController(rest.RestController):
|
|||||||
"""
|
"""
|
||||||
pecan.request.mongo_connection.shinken.hosts.insert(
|
pecan.request.mongo_connection.shinken.hosts.insert(
|
||||||
data.as_dict()
|
data.as_dict()
|
||||||
)
|
)
|
||||||
|
@ -115,3 +115,30 @@ class TestHostController(functionalTest.FunctionalTest):
|
|||||||
|
|
||||||
self.assertTrue(new_host in hosts)
|
self.assertTrue(new_host in hosts)
|
||||||
self.assertEqual(response.status_int, 201)
|
self.assertEqual(response.status_int, 201)
|
||||||
|
|
||||||
|
def test_get_associated_services(self):
|
||||||
|
services = [
|
||||||
|
{
|
||||||
|
"host_name": "bogus-router",
|
||||||
|
"service_description": "check-",
|
||||||
|
"check_command": "check-disk!/dev/sdb1",
|
||||||
|
"max_check_attempts": "5",
|
||||||
|
"check_interval": "5",
|
||||||
|
"retry_interval": "3",
|
||||||
|
"check_period": "24x7",
|
||||||
|
"notification_interval": "30",
|
||||||
|
"notification_period": "24x7",
|
||||||
|
"contacts": "surveil-ptl,surveil-bob",
|
||||||
|
"contact_groups": "linux-admins"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self.mongoconnection.shinken.services.insert(
|
||||||
|
copy.deepcopy(services[0])
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self.app.get('/v1/hosts/bogus-router/services')
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
services,
|
||||||
|
json.loads(response.body.decode())
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user