Exemple #1
0
    def _get_alert_source_by_host(source_ip):
        """Gets alert source for given source ip address."""
        filters = {'host': source_ip}
        ctxt = context.RequestContext()

        # Using the known filter and db exceptions are handled by api
        alert_source = db.alert_source_get_all(ctxt, filters=filters)
        if not alert_source:
            raise exception.AlertSourceNotFoundWithHost(source_ip)

        # This is to make sure unique host is configured each alert source
        if len(alert_source) > 1:
            msg = (_("Failed to get unique alert source with host %s.")
                   % source_ip)
            raise exception.InvalidResults(msg)

        return alert_source[0]
    def _get_alert_source_by_host(source_ip):
        """Gets alert source for given source ip address."""
        filters = {'host~': source_ip}
        ctxt = context.RequestContext()

        # Using the known filter and db exceptions are handled by api
        alert_sources = db.alert_source_get_all(ctxt, filters=filters)
        if not alert_sources:
            raise exception.AlertSourceNotFoundWithHost(source_ip)

        # This is to make sure unique host is configured each alert source
        unique_alert_source = None
        if len(alert_sources) > 1:
            # Clear invalid alert_source
            for alert_source in alert_sources:
                try:
                    db.storage_get(ctxt, alert_source['storage_id'])
                except exception.StorageNotFound:
                    LOG.warning('Found redundancy alert source for storage %s'
                                % alert_source['storage_id'])
                    try:
                        db.alert_source_delete(
                            ctxt, alert_source['storage_id'])
                    except Exception as e:
                        LOG.warning('Delete the invalid alert source failed, '
                                    'reason is %s' % six.text_type(e))
                else:
                    unique_alert_source = alert_source
        else:
            unique_alert_source = alert_sources[0]

        if unique_alert_source is None:
            msg = (_("Failed to get unique alert source with host %s.")
                   % source_ip)
            raise exception.InvalidResults(msg)

        return unique_alert_source
Exemple #3
0
 def heart_beat_task_spawn(self, ctxt):
     """Periodical task to spawn snmp heart beat check."""
     LOG.info("Spawn the snmp heart beat check task.")
     alert_source_list = db.alert_source_get_all(ctxt)
     for alert_source in alert_source_list:
         self.alert_rpc_api.check_snmp_config(ctxt, alert_source)
    def show_all(self, req):
        """Show all snmp configs."""
        ctx = req.environ['delfin.context']
        snmp_configs = db.alert_source_get_all(ctx)

        return alert_view.show_all_snmp_configs(snmp_configs)