def get_all(self, live_query=None): """Return all live services.""" if live_query: lq_filters, lq_fields = _translate_live_query(live_query) else: lq_filters = {} lq_fields = {} query, fields = mongodb_query.build_mongodb_query( lq_filters, lq_fields) if fields != {}: mongo_dicts = ( self.request.mongo_connection.alignak_live.services.find( query, fields)) else: mongo_dicts = (self.request.mongo_connection.alignak_live.services. find(query)) service_dicts = [_service_dict_from_mongo_item(s) for s in mongo_dicts] services = [] for service_dict in service_dicts: service = live_service.LiveService(**service_dict) services.append(service) return services
def get_all(self, live_query=None): """Return all live hosts.""" if live_query: lq_filters, lq_fields = _translate_live_query(live_query) else: lq_filters = {} lq_fields = {} query, fields = mongodb_query.build_mongodb_query(lq_filters, lq_fields) if fields != {}: mongo_dicts = (self.request.mongo_connection. alignak_live.hosts.find(query, fields)) else: mongo_dicts = (self.request.mongo_connection. alignak_live.hosts.find(query)) host_dicts = [ _host_dict_from_mongo_item(s) for s in mongo_dicts ] hosts = [] for host_dict in host_dicts: host = live_host.LiveHost(**host_dict) hosts.append(host) return hosts
def get_all(self, live_query=None): """Return all live services.""" service_mappings = { "last_check": "last_chk", "description": "service_description", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged", } if live_query: lq = mongodb_query.translate_live_query(live_query.as_dict(), service_mappings) else: lq = {} query, kwargs = mongodb_query.build_mongodb_query(lq) mongo_dicts = (self.request.mongo_connection. alignak_live.services.find(*query, **kwargs)) service_dicts = [ _service_dict_from_mongo_item(s) for s in mongo_dicts ] services = [] for service_dict in service_dicts: service = live_service.LiveService(**service_dict) services.append(service) return services
def get_all(self, live_query=None): """Return all live hosts.""" if live_query: lq_filters, lq_fields = _translate_live_query(live_query) else: lq_filters = {} lq_fields = {} query, fields = mongodb_query.build_mongodb_query( lq_filters, lq_fields) if fields != {}: mongo_dicts = ( self.request.mongo_connection.alignak_live.hosts.find( query, fields)) else: mongo_dicts = ( self.request.mongo_connection.alignak_live.hosts.find(query)) host_dicts = [_host_dict_from_mongo_item(s) for s in mongo_dicts] hosts = [] for host_dict in host_dicts: host = live_host.LiveHost(**host_dict) hosts.append(host) return hosts
def get_all(self, live_query=None): """Return all live hosts.""" host_mappings = { "last_check": "last_chk", "description": "display_name", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged", } if live_query: lq = mongodb_query.translate_live_query(live_query.as_dict(), host_mappings) else: lq = {} query, kwargs = mongodb_query.build_mongodb_query(lq) mongo_dicts = self.request.mongo_connection.alignak_live.hosts.find(*query, **kwargs) host_dicts = [_host_dict_from_mongo_item(s) for s in mongo_dicts] hosts = [] for host_dict in host_dicts: host = live_host.LiveHost(**host_dict) hosts.append(host) return hosts
def get_all(self, live_query=None): """Return all live hosts.""" host_mappings = { "last_check": "last_chk", "description": "display_name", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged" } if live_query: lq = mongodb_query.translate_live_query(live_query.as_dict(), host_mappings) else: lq = {} query, kwargs = mongodb_query.build_mongodb_query(lq) mongo_dicts = (self.request.mongo_connection.alignak_live.hosts.find( *query, **kwargs)) host_dicts = [_host_dict_from_mongo_item(s) for s in mongo_dicts] hosts = [] for host_dict in host_dicts: host = live_host.LiveHost(**host_dict) hosts.append(host) return hosts
def get_all(self, live_query=None): """Return all live services.""" service_mappings = { "last_check": "last_chk", "description": "service_description", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged", } if live_query: lq = mongodb_query.translate_live_query(live_query.as_dict(), service_mappings) else: lq = {} query, kwargs = mongodb_query.build_mongodb_query(lq) mongo_dicts = ( self.request.mongo_connection.alignak_live.services.find( *query, **kwargs)) service_dicts = [_service_dict_from_mongo_item(s) for s in mongo_dicts] services = [] for service_dict in service_dicts: service = live_service.LiveService(**service_dict) services.append(service) return services
def test_build_mongo_query(self): query = live_query.LiveQuery(fields=['host_name', 'last_check'], filters=json.dumps({ "isnot": { "state": [0, 1], "last_check": ["test_keystone"] } }), paging=paging.Paging(size=7, page=4)) service_mappings = { "last_check": "last_chk", "description": "service_description", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged", } lq = mongodb_query.translate_live_query(query.as_dict(), service_mappings) self.assertEqual( lq, { 'fields': [u'host_name', 'last_chk'], 'filters': { u'isnot': { u'state': [0, 1], 'last_chk': [u'test_keystone'] } }, 'paging': query.paging }, ) query, kwargs = mongodb_query.build_mongodb_query(lq) expected_query = { "state": { "$nin": [0, 1] }, "last_chk": { "$nin": ["test_keystone"] } } expected_fields = {"host_name": 1, "last_chk": 1} self.assertEqual(query[0], expected_query) self.assertEqual(query[1], expected_fields) self.assertEqual(kwargs, {'limit': 7, 'skip': 28})
def test_build_mongo_query(self): query = live_query.LiveQuery( fields=['host_name', 'last_check'], filters=json.dumps({ "isnot": { "state": [0, 1], "last_check": ["test_keystone"] } }), paging=paging.Paging(size=7, page=4) ) service_mappings = { "last_check": "last_chk", "description": "service_description", "plugin_output": "output", "acknowledged": "problem_has_been_acknowledged", } lq = mongodb_query.translate_live_query( query.as_dict(), service_mappings ) self.assertEqual( lq, {'fields': [u'host_name', 'last_chk'], 'filters': {u'isnot': {u'state': [0, 1], 'last_chk': [u'test_keystone']}}, 'paging': query.paging}, ) query, kwargs = mongodb_query.build_mongodb_query(lq) expected_query = { "state": {"$nin": [0, 1]}, "last_chk": {"$nin": ["test_keystone"]} } expected_fields = { "host_name": 1, "last_chk": 1 } self.assertEqual(query[0], expected_query) self.assertEqual(query[1], expected_fields) self.assertEqual(kwargs, {'limit': 7, 'skip': 28})
def test_build_mongo_query(self): query = live_query.LiveQuery( fields=['host_name', 'last_check'], filters=json.dumps({ "isnot": { "state": [0, 1], "last_check": ["test_keystone"] } }) ) lq_filters, lq_fields = live_service_handler._translate_live_query( query ) self.assertEqual( lq_fields, ['host_name', 'last_chk'] ) self.assertEqual(lq_filters, {'isnot': {'state': [0, 1], 'last_chk': ['test_keystone']}}) query, fields = mongodb_query.build_mongodb_query(lq_filters, lq_fields) expected_query = { "state": {"$nin": [0, 1]}, "last_chk": {"$nin": ["test_keystone"]} } expected_fields = { "host_name": 1, "last_chk": 1 } self.assertEqual(query, expected_query) self.assertEqual(fields, expected_fields)
def get_all(self, live_query=None): """Return all live services.""" if live_query: lq_filters, lq_fields = _translate_live_query(live_query) else: lq_filters = {} lq_fields = {} query, fields = mongodb_query.build_mongodb_query(lq_filters, lq_fields) if fields != {}: mongo_dicts = self.request.mongo_connection.alignak_live.services.find(query, fields) else: mongo_dicts = self.request.mongo_connection.alignak_live.services.find(query) service_dicts = [_service_dict_from_mongo_item(s) for s in mongo_dicts] services = [] for service_dict in service_dicts: service = live_service.LiveService(**service_dict) services.append(service) return services