def get_storage_from_parsed_alert(self, ctxt, storage, alert_model):
        # If parse_alert sets 'serial_number' or 'storage_name' in the
        # alert_model, we need to get corresponding storage details
        # from the db and fill that in alert_model
        storage_sn = alert_model.get('serial_number')
        storage_name = alert_model.get('storage_name')
        filters = {
            "vendor": storage['vendor'],
            "model": storage['model'],
        }
        try:
            if storage_sn and storage_sn != storage['serial_number']:
                filters['serial_number'] = storage_sn
            elif storage_name and storage_name != storage['name']:
                filters['name'] = storage_name
            else:
                return storage

            storage_list = db.storage_get_all(ctxt, filters=filters)
            if not storage_list:
                msg = "Failed to get destination storage for SNMP Trap. " \
                      "Storage with serial number {} or storage name {} " \
                      "not found in DB".format(storage_sn, storage_name)
                raise exception.AlertSourceNotFound(msg)
            db.alert_source_get(ctxt, storage_list[0]['id'])
            storage = storage_list[0]
        except exception.AlertSourceNotFound:
            LOG.info("Storage with serial number {} or name {} "
                     "is not registered for receiving "
                     "SNMP Trap".format(storage_sn, storage_name))
            raise

        return storage
Beispiel #2
0
 def _get_snmp_config_brief(self, ctx, storage_id):
     """
     Get snmp configuration that will be used to delete from trap receiver.
     Only community_index(storage_id) required for snmp v1/v2 deletion,
     user_name and engine_id are required for snmp v3. So here we only get
     those required parameters. Return None if configuration not found.
     """
     try:
         alert_source = db.alert_source_get(ctx, storage_id)
         snmp_config = {
             "storage_id": alert_source["storage_id"],
             "version": alert_source["version"]
         }
         if snmp_config["version"].lower() == "snmpv3":
             snmp_config["username"] = alert_source["username"]
             snmp_config["engine_id"] = alert_source["engine_id"]
         return snmp_config
     except exception.AlertSourceNotFound:
         return None
Beispiel #3
0
    def show(self, req, id):
        ctx = req.environ['delfin.context']
        alert_source = db.alert_source_get(ctx, id)

        return alert_view.build_alert_source(alert_source.to_dict())