metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmerri...@apache.org
Subject [metron] branch master updated: METRON-2007 Management UI not loading grok statements correctly (merrimanr) closes apache/metron#1340
Date Tue, 19 Feb 2019 16:49:15 GMT
This is an automated email from the ASF dual-hosted git repository.

rmerriman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new 36946ff  METRON-2007 Management UI not loading grok statements correctly (merrimanr)
closes apache/metron#1340
36946ff is described below

commit 36946ff09aadd54bebb503e89121d996f9242cc9
Author: merrimanr <merrimanr@gmail.com>
AuthorDate: Tue Feb 19 10:49:00 2019 -0600

    METRON-2007 Management UI not loading grok statements correctly (merrimanr) closes apache/metron#1340
---
 .../sensor-parser-config.component.html            | 12 ++++----
 .../sensor-parser-config.component.spec.ts         | 32 +++++++---------------
 .../sensor-parser-config.component.ts              | 29 ++++++--------------
 .../src/app/service/grok-validation.service.ts     |  2 +-
 .../metron-config/src/app/service/hdfs.service.ts  |  4 +--
 .../metron-config/src/app/service/kafka.service.ts |  2 +-
 6 files changed, 29 insertions(+), 52 deletions(-)

diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
index c9895c7..b4bdd92 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.html
@@ -73,7 +73,7 @@
                 <div class="form-group" [ngClass]="{'panel-selected': showGrokValidator
}" *ngIf="isGrokParser(sensorParserConfig)" >
                     <label attr.for="grokStatement">GROK STATEMENT</label>
                     <div  class="input-group" [attr.disabled]="!sensorNameValid || !parserClassValid">
-                        <input type="text" class="form-control" formControlName="grokStatement"
 [(ngModel)]="this.grokStatement" (ngModelChange)="onGrokStatementChange()" readonly>
+                        <input type="text" class="form-control" formControlName="grokStatement"
 [(ngModel)]="this.grokStatement" readonly>
                         <span class="input-group-btn">
                             <button class="btn btn-default" type="button" (click)="sensorNameValid
&& parserClassValid && onShowGrokPane()" readonly>
                             <i class="fa fa-columns" aria-hidden="true"></i>
@@ -85,7 +85,7 @@
 
                 <div class="form-group" [ngClass]="{'panel-selected': showFieldSchema
}" >
                     <label attr.for="fieldSchema">SCHEMA</label>
-                    <div  class="input-group" [attr.disabled]="!configValid">
+                    <div  class="input-group" [attr.disabled]="!isConfigValid()">
                         <div class="form-control table-wrapper" readonly>
                             <table cellspacing="10">
                                 <tr> <td class="p-l-1">TRANSFORMATIONS </td>
<td class="p-l-1">&nbsp;&nbsp;</td><td class="p-1-1">{{getTransformationCount()}}</td>
</tr>
@@ -94,7 +94,7 @@
                             </table>
                         </div>
                         <span class="input-group-btn">
-                            <button class="btn btn-default" type="button" (click)="configValid
&& showPane(pane.FIELDSCHEMA)" style="height: 80px;" readonly>
+                            <button class="btn btn-default" type="button" (click)="isConfigValid()
&& showPane(pane.FIELDSCHEMA)" style="height: 80px;" readonly>
                                 <i class="fa fa-columns" aria-hidden="true"></i>
                                 <i class="fa fa-angle-double-right" style="padding-left:
3px" aria-hidden="true"></i>
                           </button>
@@ -104,14 +104,14 @@
 
                 <div class="form-group" [ngClass]="{'panel-selected': showThreatTriage
}">
                     <label attr.for="stellar">THREAT TRIAGE</label>
-                    <div class="input-group" [attr.disabled]="!configValid">
+                    <div class="input-group" [attr.disabled]="!isConfigValid()">
                         <div  class="form-control" style="resize: none;" readonly>
                             <table style="margin: 0">
                                 <tr> <td class="p-l-1">RULES </td> <td
class="p-l-1">&nbsp;&nbsp;</td><td class="p-3-1">{{getRuleCount()}}</td>
</tr>
                             </table>
                         </div>
                         <span class="input-group-btn">
-                            <button class="btn btn-default" type="button" (click)="configValid
&& showPane(pane.THREATTRIAGE)" readonly>
+                            <button class="btn btn-default" type="button" (click)="isConfigValid()
&& showPane(pane.THREATTRIAGE)" readonly>
                                 <i class="fa fa-columns" aria-hidden="true"></i>
                                 <i class="fa fa-angle-double-right" style="padding-left:
3px" aria-hidden="true"></i>
                             </button>
@@ -197,7 +197,7 @@
                 <div class="form-group">
                     <div class="form-seperator-edit"></div>
                     <div class="button-row">
-                        <button type="submit" class="btn save-button" [ngClass]="{'disabled':!configValid}"
[disabled]="!configValid" (click)="onSave()">SAVE</button>
+                        <button type="submit" class="btn save-button" [ngClass]="{'disabled':!isConfigValid()}"
[disabled]="!isConfigValid()" (click)="onSave()">SAVE</button>
                         <button class="btn form-enable-disable-button" (click)="goBack()"
>CANCEL</button>
                         <span class="advanced-link" [hidden]="showAdvancedParserConfiguration"
(click)="showAdvancedParserConfiguration = true">Advanced</span>
                     </div>
diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
index 4be0703..ff1a812 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.spec.ts
@@ -713,11 +713,9 @@ describe('Component: SensorParserConfig', () => {
 
   it('should handle onSetKafkaTopic', async(() => {
     spyOn(component, 'getKafkaStatus');
-    spyOn(component, 'isConfigValid');
 
     component.onSetKafkaTopic();
     expect(component.getKafkaStatus).not.toHaveBeenCalled();
-    expect(component.isConfigValid).toHaveBeenCalled();
 
     component.sensorParserConfig.sensorTopic = 'bro';
     component.onSetKafkaTopic();
@@ -726,10 +724,8 @@ describe('Component: SensorParserConfig', () => {
   }));
 
   it('should handle onSetSensorName', async(() => {
-    spyOn(component, 'isConfigValid');
 
     component.onSetSensorName();
-    expect(component.isConfigValid).toHaveBeenCalled();
     expect(component.sensorNameValid).toEqual(false);
 
     component.sensorName = 'squid';
@@ -785,11 +781,9 @@ describe('Component: SensorParserConfig', () => {
 
   it('should handle onParserTypeChange', async(() => {
     spyOn(component, 'hidePane');
-    spyOn(component, 'isConfigValid');
 
     component.onParserTypeChange();
     expect(component.hidePane).not.toHaveBeenCalled();
-    expect(component.isConfigValid).toHaveBeenCalled();
 
     component.sensorParserConfig.parserClassName =
       'org.apache.metron.parsers.GrokParser';
@@ -803,37 +797,31 @@ describe('Component: SensorParserConfig', () => {
     expect(component.hidePane).toHaveBeenCalledWith(Pane.GROK);
   }));
 
-  it('should handle onGrokStatementChange', async(() => {
-    spyOn(component, 'isConfigValid');
+  it('isGrokStatementValid should validate grokStatement', async(() => {
+    expect(component.isGrokStatementValid()).toEqual(false);
 
-    component.onGrokStatementChange();
-    expect(component.grokStatementValid).toEqual(false);
-    expect(component.isConfigValid).toHaveBeenCalled();
+    component.grokStatement = '';
+    expect(component.isGrokStatementValid()).toEqual(false);
 
     component.grokStatement = 'grok statement';
-    component.onGrokStatementChange();
-    expect(component.grokStatementValid).toEqual(true);
+    expect(component.isGrokStatementValid()).toEqual(true);
   }));
 
   it('should handle isConfigValid', async(() => {
-    component.isConfigValid();
-    expect(component.configValid).toEqual(false);
+    expect(component.isConfigValid()).toEqual(false);
 
     component.sensorNameValid = true;
     component.kafkaTopicValid = true;
     component.parserClassValid = true;
 
-    component.isConfigValid();
-    expect(component.configValid).toEqual(true);
+    expect(component.isConfigValid()).toEqual(true);
 
     component.sensorParserConfig.parserClassName =
       'org.apache.metron.parsers.GrokParser';
-    component.isConfigValid();
-    expect(component.configValid).toEqual(false);
+    expect(component.isConfigValid()).toEqual(false);
 
-    component.grokStatementValid = true;
-    component.isConfigValid();
-    expect(component.configValid).toEqual(true);
+    component.grokStatement = 'grok statement';
+    expect(component.isConfigValid()).toEqual(true);
   }));
 
   it('should getKafkaStatus', async(() => {
diff --git a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
index efd08d0..bb59de5 100644
--- a/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
+++ b/metron-interface/metron-config/src/app/sensors/sensor-parser-config/sensor-parser-config.component.ts
@@ -68,17 +68,14 @@ export class SensorParserConfigComponent implements OnInit {
   showFieldSchema: boolean = false;
   showThreatTriage: boolean = false;
   showStormSettings: boolean = false;
-
-  configValid = false;
   sensorNameValid = false;
   sensorNameUnique = true;
   sensorNameNoSpecChars = false;
   kafkaTopicValid = false;
   parserClassValid = false;
-  grokStatementValid = false;
   availableParsers = {};
   availableParserNames = [];
-  grokStatement = {};
+  grokStatement = '';
   patternLabel = '';
   currentSensors = [];
 
@@ -135,12 +132,12 @@ export class SensorParserConfigComponent implements OnInit {
             if (path) {
               this.hdfsService.read(path).subscribe(
                 contents => {
-                  this.grokStatement = contents;
+                  this.grokStatement = contents as string;
                 },
                 (hdfsError: RestError) => {
                   this.grokValidationService.getStatement(path).subscribe(
                     contents => {
-                      this.grokStatement = contents;
+                      this.grokStatement = contents as string;
                     },
                     (grokError: RestError) => {
                       this.metronAlerts.showErrorMessage(
@@ -304,8 +301,6 @@ export class SensorParserConfigComponent implements OnInit {
       this.sensorName.length > 0 &&
       this.sensorNameUnique &&
       this.sensorNameNoSpecChars;
-
-    this.isConfigValid();
   }
 
   onSetKafkaTopic(): void {
@@ -315,7 +310,6 @@ export class SensorParserConfigComponent implements OnInit {
     if (this.kafkaTopicValid) {
       this.getKafkaStatus();
     }
-    this.isConfigValid();
   }
 
   onParserTypeChange(): void {
@@ -328,23 +322,18 @@ export class SensorParserConfigComponent implements OnInit {
         this.hidePane(Pane.GROK);
       }
     }
-    this.isConfigValid();
   }
 
-  onGrokStatementChange(): void {
-    this.grokStatementValid =
-      this.grokStatement !== undefined &&
-      Object.keys(this.grokStatement).length > 0;
-    this.isConfigValid();
+  isGrokStatementValid(): boolean {
+    return this.grokStatement !== undefined && Object.keys(this.grokStatement).length
> 0;
   }
 
   isConfigValid() {
     let isGrokParser = this.isGrokParser(this.sensorParserConfig);
-    this.configValid =
-      this.sensorNameValid &&
-      this.kafkaTopicValid &&
-      this.parserClassValid &&
-      (!isGrokParser || this.grokStatementValid);
+    return this.sensorNameValid &&
+            this.kafkaTopicValid &&
+            this.parserClassValid &&
+            (!isGrokParser || this.isGrokStatementValid());
   }
 
   getKafkaStatus() {
diff --git a/metron-interface/metron-config/src/app/service/grok-validation.service.ts b/metron-interface/metron-config/src/app/service/grok-validation.service.ts
index 1e61b3e..1f5e9ba 100644
--- a/metron-interface/metron-config/src/app/service/grok-validation.service.ts
+++ b/metron-interface/metron-config/src/app/service/grok-validation.service.ts
@@ -50,7 +50,7 @@ export class GrokValidationService {
 
   public getStatement(path: string): Observable<Object> {
     const options: HttpParams = new HttpParams().set('path', path);
-    return this.http.get(this.url + '/get/statement', { params: options }).pipe(
+    return this.http.get(this.url + '/get/statement', { params: options, responseType: 'text'
}).pipe(
       map(HttpUtil.extractString),
       catchError(HttpUtil.handleError)
     );
diff --git a/metron-interface/metron-config/src/app/service/hdfs.service.ts b/metron-interface/metron-config/src/app/service/hdfs.service.ts
index 54e7369..70ad796 100644
--- a/metron-interface/metron-config/src/app/service/hdfs.service.ts
+++ b/metron-interface/metron-config/src/app/service/hdfs.service.ts
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 import { Injectable, Inject } from '@angular/core';
-import { HttpClient, HttpParams } from '@angular/common/http';
+import {HttpClient, HttpParams} from '@angular/common/http';
 import { Observable } from 'rxjs';
 import { map, catchError } from 'rxjs/operators';
 import { HttpUtil } from '../util/httpUtil';
@@ -41,7 +41,7 @@ export class HdfsService {
 
   public read(path: string): Observable<Object> {
     const options: HttpParams = new HttpParams().set('path', path);
-    return this.http.get(this.url, { params: options }).pipe(
+    return this.http.get(this.url, { params: options, responseType: 'text' }).pipe(
       map(HttpUtil.extractString),
       catchError(HttpUtil.handleError)
     );
diff --git a/metron-interface/metron-config/src/app/service/kafka.service.ts b/metron-interface/metron-config/src/app/service/kafka.service.ts
index 62a95a0..a16da8a 100644
--- a/metron-interface/metron-config/src/app/service/kafka.service.ts
+++ b/metron-interface/metron-config/src/app/service/kafka.service.ts
@@ -55,7 +55,7 @@ export class KafkaService {
   }
 
   public sample(name: string): Observable<string | RestError> {
-    return this.http.get(this.url + '/' + name + '/sample').pipe(
+    return this.http.get(this.url + '/' + name + '/sample', {responseType: 'text'}).pipe(
       map(HttpUtil.extractString),
       catchError(HttpUtil.handleError)
     );


Mime
View raw message