Dont include templates in queries
Change-Id: I7228d88f03524845f1d62d0599e4f0d199c1285d
This commit is contained in:
parent
42fe1bfa92
commit
9d07d3c63b
@ -161,7 +161,10 @@ class HostsController(rest.RestController):
|
||||
"""Returns all hosts."""
|
||||
hosts = [h for h
|
||||
in pecan.request.mongo_connection.
|
||||
shinken.hosts.find(None, {'_id': 0})]
|
||||
shinken.hosts.find(
|
||||
{"register": {"$ne": "0"}}, # Don't return templates
|
||||
{'_id': 0}
|
||||
)]
|
||||
|
||||
return [host.Host(**h) for h in hosts]
|
||||
|
||||
|
@ -24,8 +24,12 @@ class ServicesController(rest.RestController):
|
||||
@wsme_pecan.wsexpose([service.Service])
|
||||
def get_all(self):
|
||||
"""Returns all services."""
|
||||
services = [s for s
|
||||
in pecan.request.mongo_connection.shinken.services.find()]
|
||||
services = [
|
||||
s for s
|
||||
in pecan.request.mongo_connection.
|
||||
# Don't return templates
|
||||
shinken.services.find({"register": {"$ne": "0"}})
|
||||
]
|
||||
|
||||
return [service.Service(**s) for s in services]
|
||||
|
||||
|
@ -77,6 +77,24 @@ class TestHostController(functionalTest.FunctionalTest):
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_all_hosts_no_templates(self):
|
||||
self.mongoconnection.shinken.hosts.insert(
|
||||
copy.deepcopy(
|
||||
{"host_name": "bogus-router", "address": "192.168.1.254",
|
||||
"max_check_attempts": 5, "check_period": "24x7",
|
||||
"contacts": "admin,carl", "contact_groups": "router-admins",
|
||||
"notification_interval": 30, "notification_period": "24x7",
|
||||
"register": "0"}
|
||||
)
|
||||
)
|
||||
response = self.app.get('/v1/hosts')
|
||||
|
||||
self.assert_count_equal_backport(
|
||||
json.loads(response.body.decode()),
|
||||
self.hosts
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_specific_host(self):
|
||||
response = self.app.get('/v1/hosts/bogus-router333')
|
||||
|
||||
|
@ -77,6 +77,31 @@ class TestServiceController(functionalTest.FunctionalTest):
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_get_all_services_no_templates(self):
|
||||
self.mongoconnection.shinken.services.insert(
|
||||
copy.deepcopy(
|
||||
{"host_name": "sample-server3",
|
||||
"service_description": "check-disk-sdb",
|
||||
"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",
|
||||
"register": "0",
|
||||
"contact_groups": "linux-admins"}
|
||||
)
|
||||
)
|
||||
response = self.app.get('/v1/services')
|
||||
|
||||
self.assert_count_equal_backport(
|
||||
json.loads(response.body.decode()),
|
||||
self.services
|
||||
)
|
||||
self.assertEqual(response.status_int, 200)
|
||||
|
||||
def test_add_host(self):
|
||||
new_service = {
|
||||
"host_name": "SOMEHOSTNAME",
|
||||
|
Loading…
x
Reference in New Issue
Block a user