Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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})
Пример #6
0
    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})