示例#1
0
    def test_get_nagios_config_returns_from_memcache_over_datastore(self):
        memcache_nagios_model = model.Nagios(url='memcache_nagios')
        memcache.set(constants.DEFAULT_NAGIOS_ENTRY, memcache_nagios_model)

        datastore_nagios_model = model.Nagios(
            key_name=constants.DEFAULT_NAGIOS_ENTRY, url='datastore_nagios')
        datastore_nagios_model.put()

        retrieved = nagios_config_wrapper.get_nagios_config()
        self.assertEqual(retrieved.url, 'memcache_nagios')
    def test_get_nagios_config_returns_from_memcache_over_datastore(self):
        memcache_nagios_model = model.Nagios(url='memcache_nagios')
        memcache.set(constants.DEFAULT_NAGIOS_ENTRY, memcache_nagios_model)

        datastore_nagios_model = model.Nagios(
            key_name=constants.DEFAULT_NAGIOS_ENTRY,
            url='datastore_nagios')
        datastore_nagios_model.put()

        retrieved = nagios_config_wrapper.get_nagios_config()
        self.assertEqual(retrieved.url, 'memcache_nagios')
示例#3
0
    def get(self):
        """Triggers the update handler.

        Updates sliver status with information from Nagios. The Nagios URL
        containing the information is stored in the Nagios db along with
        the credentials necessary to access the data.
        """
        nagios = nagios_config_wrapper.get_nagios_config()
        if nagios is None:
            logging.error('Datastore does not have the Nagios credentials.')
            return util.send_not_found(self)

        nagios_status.authenticate_nagios(nagios)

        for slice_info in nagios_status.get_slice_info(nagios.url):

            slice_status = nagios_status.get_slice_status(slice_info.slice_url)
            if slice_status:
                self.update_sliver_tools_status(
                    slice_status, slice_info.tool_id, slice_info.address_family)
        return util.send_success(self)
示例#4
0
    def get(self):
        """Triggers the update handler.

        Updates sliver status with information from Nagios. The Nagios URL
        containing the information is stored in the Nagios db along with
        the credentials necessary to access the data.
        """
        nagios = nagios_config_wrapper.get_nagios_config()
        if nagios is None:
            logging.error('Datastore does not have the Nagios credentials.')
            return util.send_not_found(self)

        nagios_status.authenticate_nagios(nagios)

        for slice_info in nagios_status.get_slice_info(nagios.url):

            slice_status = nagios_status.get_slice_status(slice_info.slice_url)
            if slice_status:
                self.update_sliver_tools_status(
                    slice_status, slice_info.tool_id, slice_info.address_family)
        return util.send_success(self)
示例#5
0
    def get(self):
        """Triggers the update handler.

        Updates sliver status with information from either Nagios or Prometheus.
        The base URLs for accessing status information are stored in the
        datastore along with the credentials necessary to access the data.
        """
        # Determine if there are any dependencies on Prometheus.
        prometheus_deps = model.get_status_source_deps('prometheus')
        # Get Prometheus configs, and authenticate.
        prometheus_config = prometheus_config_wrapper.get_prometheus_config()
        if prometheus_config is None:
            logging.error('Datastore does not have the Prometheus configs.')
        else:
            prometheus_opener = prometheus_status.authenticate_prometheus(
                prometheus_config)

        # Determine if there are any dependencies on Nagios.
        nagios_deps = model.get_status_source_deps('nagios')
        # Get Nagios configs, and authenticate.
        nagios_config = nagios_config_wrapper.get_nagios_config()
        if nagios_config is None:
            logging.error('Datastore does not have the Nagios configs.')
        else:
            nagios_opener = nagios_status.authenticate_nagios(nagios_config)

        # If we have dependencies on both Prometheus and Nagios, and neither one
        # of the configs is available, then abort, because we can't fetch status
        # from either. However, if we have one or the other, then continue,
        # because it may be preferable to update _some_ statuses than none.
        if (prometheus_deps and not prometheus_config) and (nagios_deps and
                                                            not nagios_config):
            logging.error(
                'Neither Nagios nor Prometheus configs are available.')
            return util.send_not_found(self)

        for tool_id in model.get_all_tool_ids():
            tool = model.get_tool_from_tool_id(tool_id)
            for address_family in ['', '_ipv6']:
                if tool.status_source == 'prometheus':
                    logging.info('Status source for %s%s is: prometheus',
                                 tool_id, address_family)
                    # Only proceed if prometheus_config exists, and hence
                    # prometheus_opener should also exist.
                    if prometheus_config:
                        slice_info = prometheus_status.get_slice_info(
                            prometheus_config.url, tool_id, address_family)
                        if not slice_info:
                            continue
                        slice_status = prometheus_status.get_slice_status(
                            slice_info.slice_url, prometheus_opener)
                    else:
                        logging.error(
                            'Prometheus config unavailable. Skipping %s%s',
                            tool_id, address_family)
                        continue
                elif tool.status_source == 'nagios':
                    logging.info('Status source for %s%s is: nagios', tool_id,
                                 address_family)
                    # Only proceed if nagios_config exists, and hence
                    # nagios_opener should also exist.
                    if nagios_config:
                        slice_info = nagios_status.get_slice_info(
                            nagios_config.url, tool_id, address_family)
                        slice_status = nagios_status.get_slice_status(
                            slice_info.slice_url, nagios_opener)
                    else:
                        logging.error(
                            'Nagios config unavailable. Skipping %s%s', tool_id,
                            address_family)
                        continue
                else:
                    logging.error('Unknown tool status_source: %s.',
                                  tool.status_source)
                    continue

                if slice_status:
                    self.update_sliver_tools_status(slice_status,
                                                    slice_info.tool_id,
                                                    slice_info.address_family)

        return util.send_success(self)
示例#6
0
 def test_get_nagios_config_no_credentials_stored_logs_error(self):
     self.assertIsNone(nagios_config_wrapper.get_nagios_config())
示例#7
0
 def test_get_nagios_config_returns_successfully_from_datastore(self):
     nagios_model = model.Nagios(key_name=constants.DEFAULT_NAGIOS_ENTRY,
                                 url='foo')
     nagios_model.put()
     retrieved = nagios_config_wrapper.get_nagios_config()
     self.assertEqual(retrieved.url, 'foo')
示例#8
0
 def test_get_nagios_config_returns_successfully_from_memcache(self):
     nagios_model = model.Nagios(url='foo')
     memcache.set(constants.DEFAULT_NAGIOS_ENTRY, nagios_model)
     retrieved = nagios_config_wrapper.get_nagios_config()
     self.assertEqual(retrieved.url, 'foo')
示例#9
0
文件: update.py 项目: m-lab/mlab-ns
    def get(self):
        """Triggers the update handler.

        Updates sliver status with information from either Nagios or Prometheus.
        The base URLs for accessing status information are stored in the
        datastore along with the credentials necessary to access the data.
        """
        # Determine if there are any dependencies on Prometheus.
        prometheus_deps = model.get_status_source_deps('prometheus')
        # Get Prometheus configs, and authenticate.
        prometheus_config = prometheus_config_wrapper.get_prometheus_config()
        if prometheus_config is None:
            logging.error('Datastore does not have the Prometheus configs.')
        else:
            prometheus_opener = prometheus_status.authenticate_prometheus(
                prometheus_config)

        # Determine if there are any dependencies on Nagios.
        nagios_deps = model.get_status_source_deps('nagios')
        # Get Nagios configs, and authenticate.
        nagios_config = nagios_config_wrapper.get_nagios_config()
        if nagios_config is None:
            logging.error('Datastore does not have the Nagios configs.')
        else:
            nagios_opener = nagios_status.authenticate_nagios(nagios_config)

        # If we have dependencies on both Prometheus and Nagios, and neither one
        # of the configs is available, then abort, because we can't fetch status
        # from either. However, if we have one or the other, then continue,
        # because it may be preferable to update _some_ statuses than none.
        if (prometheus_deps and not prometheus_config) and (nagios_deps and
                                                            not nagios_config):
            logging.error(
                'Neither Nagios nor Prometheus configs are available.')
            return util.send_not_found(self)

        for tool_id in model.get_all_tool_ids():
            tool = model.get_tool_from_tool_id(tool_id)
            for address_family in ['', '_ipv6']:
                if tool.status_source == 'prometheus':
                    logging.info('Status source for %s%s is: prometheus',
                                 tool_id, address_family)
                    # Only proceed if prometheus_config exists, and hence
                    # prometheus_opener should also exist.
                    if prometheus_config:
                        slice_info = prometheus_status.get_slice_info(
                            prometheus_config.url, tool_id, address_family)
                        if not slice_info:
                            continue
                        slice_status = prometheus_status.get_slice_status(
                            slice_info.slice_url, prometheus_opener)
                    else:
                        logging.error(
                            'Prometheus config unavailable. Skipping %s%s',
                            tool_id, address_family)
                        continue
                elif tool.status_source == 'nagios':
                    logging.info('Status source for %s%s is: nagios', tool_id,
                                 address_family)
                    # Only proceed if nagios_config exists, and hence
                    # nagios_opener should also exist.
                    if nagios_config:
                        slice_info = nagios_status.get_slice_info(
                            nagios_config.url, tool_id, address_family)
                        slice_status = nagios_status.get_slice_status(
                            slice_info.slice_url, nagios_opener)
                    else:
                        logging.error(
                            'Nagios config unavailable. Skipping %s%s', tool_id,
                            address_family)
                        continue
                else:
                    logging.error('Unknown tool status_source: %s.',
                                  tool.status_source)
                    continue

                if slice_status:
                    self.update_sliver_tools_status(slice_status,
                                                    slice_info.tool_id,
                                                    slice_info.address_family)

        return util.send_success(self)
 def test_get_nagios_config_no_credentials_stored_logs_error(self):
     self.assertIsNone(nagios_config_wrapper.get_nagios_config())
 def test_get_nagios_config_returns_successfully_from_datastore(self):
     nagios_model = model.Nagios(key_name=constants.DEFAULT_NAGIOS_ENTRY,
                                 url='foo')
     nagios_model.put()
     retrieved = nagios_config_wrapper.get_nagios_config()
     self.assertEqual(retrieved.url, 'foo')
 def test_get_nagios_config_returns_successfully_from_memcache(self):
     nagios_model = model.Nagios(url='foo')
     memcache.set(constants.DEFAULT_NAGIOS_ENTRY, nagios_model)
     retrieved = nagios_config_wrapper.get_nagios_config()
     self.assertEqual(retrieved.url, 'foo')