Esempio n. 1
0
    def validate(self, ctxt, alert_source):
        alert_source = dict(alert_source)
        engine_id = alert_source.get('engine_id')
        try:
            alert_source = self.validate_connectivity(alert_source)

            # If protocol is snmpv3, the snmp_validator will update
            # engine id if engine id is empty. Therefore, engine id
            # should be saved in database.
            if not engine_id and alert_source.get('engine_id'):

                alert_source_dict = {
                    'engine_id': alert_source.get('engine_id')}
                db.alert_source_update(ctxt,
                                       alert_source.get('storage_id'),
                                       alert_source_dict)
            self._handle_validation_result(ctxt,
                                           alert_source.get('storage_id'),
                                           constants.Category.RECOVERY)
        except exception.SNMPConnectionFailed:
            self._handle_validation_result(ctxt,
                                           alert_source.get('storage_id'))
        except Exception as e:
            msg = six.text_type(e)
            LOG.error("Failed to check snmp config. Reason: %s", msg)
Esempio n. 2
0
 def validate(self, ctxt, alert_source):
     engine_id = alert_source.get('engine_id')
     try:
         hosts = alert_source['host'].split(',')
         temp_alert_source = copy.deepcopy(alert_source)
         # Sets a value to raise a SNMPConnectionFailed when multiple
         # alarm sources fail to be verified
         connection_times = 0
         for host in hosts:
             temp_alert_source['host'] = host
             try:
                 connection_times += 1
                 alert_source = \
                     self.validate_connectivity(ctxt, temp_alert_source)
                 break
             except Exception as e:
                 if connection_times == len(hosts):
                     raise e
         # If protocol is snmpv3, the snmp_validator will update
         # engine id if engine id is empty. Therefore, engine id
         # should be saved in database.
         if not engine_id and alert_source.get('engine_id'):
             alert_source_dict = {
                 'engine_id': alert_source.get('engine_id')
             }
             db.alert_source_update(ctxt, alert_source.get('storage_id'),
                                    alert_source_dict)
         self._handle_validation_result(ctxt,
                                        alert_source.get('storage_id'),
                                        constants.Category.RECOVERY)
     except exception.SNMPConnectionFailed:
         self._handle_validation_result(ctxt,
                                        alert_source.get('storage_id'))
     except Exception as e:
         msg = six.text_type(e)
         LOG.error("Failed to check snmp config. Reason: %s", msg)
Esempio n. 3
0
    def put(self, req, id, body):
        """Create a new alert source or update an exist one."""
        ctx = req.environ['delfin.context']
        alert_source = body

        alert_source["storage_id"] = id
        db.storage_get(ctx, id)
        alert_source = self._input_check(alert_source)

        snmp_config_to_del = self._get_snmp_config_brief(ctx, id)
        if snmp_config_to_del is not None:
            alert_source = db.alert_source_update(ctx, id, alert_source)
        else:
            alert_source = db.alert_source_create(ctx, alert_source)
        snmp_config_to_add = alert_source
        self.alert_rpcapi.sync_snmp_config(ctx, snmp_config_to_del,
                                           snmp_config_to_add)

        return alert_view.build_alert_source(alert_source.to_dict())