onSave()

in metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts [405:469]


  onSave() {
    if (!this.indexingConfigurations.hdfs.index) {
      this.indexingConfigurations.hdfs.index = this.sensorName;
    }
    if (!this.indexingConfigurations.elasticsearch.index) {
      this.indexingConfigurations.elasticsearch.index = this.sensorName;
    }
    if (!this.indexingConfigurations.solr.index) {
      this.indexingConfigurations.solr.index = this.sensorName;
    }
    this.sensorParserConfigService
      .post(this.sensorName, this.sensorParserConfig)
      .subscribe(
        sensorParserConfig => {
          if (this.isGrokParser(sensorParserConfig)) {
            this.hdfsService
              .post(
                this.sensorParserConfig.parserConfig['grokPath'],
                this.grokStatement.toString()
              )
              .subscribe(
                response => {},
                (error: RestError) =>
                  this.metronAlerts.showErrorMessage(error.message)
              );
          }
          this.sensorEnrichmentConfigService
            .post(this.sensorName, this.sensorEnrichmentConfig)
            .subscribe(
              (sensorEnrichmentConfig: SensorEnrichmentConfig) => {},
              (error: RestError) => {
                let msg =
                  ' Sensor parser config but unable to save enrichment configuration: ';
                this.metronAlerts.showErrorMessage(
                  this.getMessagePrefix() + msg + error.message
                );
              }
            );
          this.sensorIndexingConfigService
            .post(this.sensorName, this.indexingConfigurations)
            .subscribe(
              (indexingConfigurations: IndexingConfigurations) => {},
              (error: RestError) => {
                let msg =
                  ' Sensor parser config but unable to save indexing configuration: ';
                this.metronAlerts.showErrorMessage(
                  this.getMessagePrefix() + msg + error.message
                );
              }
            );
          this.metronAlerts.showSuccessMessage(
            this.getMessagePrefix() + ' Sensor ' + this.sensorName
          );
          this.sensorParserConfigService.dataChangedSource.next([
            this.sensorName
          ]);
          this.goBack();
        },
        (error: RestError) => {
          this.metronAlerts.showErrorMessage(
            'Unable to save sensor config: ' + error.message
          );
        }
      );
  }