You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by rm...@apache.org on 2017/09/08 22:57:21 UTC
metron git commit: METRON-1077 Use column meta data end point in
alerts ui (iraghumitra via merrimanr) closes apache/metron#700
Repository: metron
Updated Branches:
refs/heads/master 6ff39ae38 -> ea65a37c0
METRON-1077 Use column meta data end point in alerts ui (iraghumitra via merrimanr) closes apache/metron#700
Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/ea65a37c
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/ea65a37c
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/ea65a37c
Branch: refs/heads/master
Commit: ea65a37c04c2e0d8fad1f1ea024af39ae56049ca
Parents: 6ff39ae
Author: iraghumitra <ra...@gmail.com>
Authored: Fri Sep 8 17:56:39 2017 -0500
Committer: merrimanr <me...@apache.org>
Committed: Fri Sep 8 17:56:39 2017 -0500
----------------------------------------------------------------------
.../metron-alerts/alerts-server-e2e.js | 20 ++--
.../metron-alerts/scripts/alerts-server.js | 14 +--
.../alert-details/alert-details.component.ts | 16 +--
.../alerts/alerts-list/alerts-list.component.ts | 26 ++---
.../alerts/alerts-list/alerts-list.module.ts | 4 +-
.../configure-table.component.ts | 10 +-
.../metron-alerts/src/app/app.module.ts | 4 +-
.../src/app/model/alerts-search-response.ts | 23 ----
.../src/app/model/search-request.ts | 3 +-
.../src/app/model/search-response.ts | 23 ++++
.../src/app/service/alert.service.ts | 72 ------------
.../src/app/service/cluster-metadata.service.ts | 7 +-
.../src/app/service/data-source.ts | 4 +-
.../service/elasticsearch-localstorage-impl.ts | 4 +-
.../src/app/service/rest-api-impl.ts | 46 --------
.../src/app/service/search.service.ts | 112 +++++++++++++++++++
.../metron-alerts/src/app/utils/constants.ts | 2 +
.../src/app/utils/elasticsearch-utils.ts | 6 +-
18 files changed, 196 insertions(+), 200 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/alerts-server-e2e.js
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/alerts-server-e2e.js b/metron-interface/metron-alerts/alerts-server-e2e.js
index 2a5f80b..f1b6410 100644
--- a/metron-interface/metron-alerts/alerts-server-e2e.js
+++ b/metron-interface/metron-alerts/alerts-server-e2e.js
@@ -30,7 +30,7 @@ var favicon = require('serve-favicon');
var proxy = require('http-proxy-middleware');
var argv = require('optimist')
.demand(['p', 'r'])
- .usage('Usage: server.js -p [port]')
+ .usage('Usage: alerts-server-e2e.js -p [port]')
.describe('p', 'Port to run metron alerts ui')
.describe('r', 'Url where metron rest application is available')
.argv;
@@ -40,7 +40,7 @@ var metronUIAddress = '';
var ifaces = os.networkInterfaces();
var restUrl = argv.r || argv.resturl;
var conf = {
- "elastic": {
+ "restapi": {
"target": restUrl,
"secure": false
}
@@ -134,24 +134,28 @@ var clusterState = function(req, res){
app.use(compression());
-app.use(bodyParser.json());
+
app.use(favicon(path.join(__dirname, 'dist/favicon.ico')));
app.use(serveStatic(path.join(__dirname, 'dist'), {
maxAge: '1d',
setHeaders: setCustomCacheControl
}));
-app.use('/api/v1/user', proxy(conf.elastic));
-app.use('/logout', proxy(conf.elastic));
-app.post('/api/v1/search/search', searchResult);
-app.use('/_cluster', clusterState);
+app.use('/logout', proxy(conf.restapi));
+app.use('/api/v1/user', proxy(conf.restapi));
+app.use('/api/v1/search/findOne', proxy(conf.restapi));
+app.use('/api/v1/search/column/metadata', proxy(conf.restapi));
+
app.get('/alerts-list', indexHTML);
app.get('', indexHTML);
+
+app.use(bodyParser.json());
+app.post('/api/v1/search/search', searchResult);
+
app.use(function(req, res, next){
res.status(404).sendStatus(304);
});
-
app.listen(port, function(){
console.log("Metron alerts ui is listening on " + metronUIAddress);
});
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/scripts/alerts-server.js
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/scripts/alerts-server.js b/metron-interface/metron-alerts/scripts/alerts-server.js
index 6fb35c9..6a999f2 100644
--- a/metron-interface/metron-alerts/scripts/alerts-server.js
+++ b/metron-interface/metron-alerts/scripts/alerts-server.js
@@ -22,15 +22,13 @@
var os = require('os');
var app = require('express')();
var path = require('path');
-var compression = require('compression')
+var compression = require('compression');
var serveStatic = require('serve-static');
var favicon = require('serve-favicon');
var proxy = require('http-proxy-middleware');
var argv = require('optimist')
- .demand(['p', 'r', 'e'])
- .alias('r', 'resturl')
- .alias('e', 'elasticurl')
- .usage('Usage: server.js -p [port] -r [restUrl] -e [elasticURL]')
+ .demand(['p', 'r'])
+ .usage('Usage: alert-server.js -p [port] -r [restUrl]')
.describe('p', 'Port to run metron management ui')
.describe('r', 'Url where metron rest application is available')
.argv;
@@ -39,12 +37,7 @@ var port = argv.p;
var metronUIAddress = '';
var ifaces = os.networkInterfaces();
var restUrl = argv.r || argv.resturl;
-var elasticUrl = argv.e || argv.elasticurl;
var conf = {
- "elastic": {
- "target": elasticUrl,
- "secure": false
- },
"rest": {
"target": restUrl,
"secure": false
@@ -78,7 +71,6 @@ var rewriteSearchProxy = proxy({
app.use(compression());
app.use('/api', proxy(conf.rest));
-app.use('/_cluster', proxy(conf.elastic));
app.use(favicon(path.join(__dirname, '../alerts-ui/favicon.ico')));
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
index 915c0c1..2e7884e 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alert-details/alert-details.component.ts
@@ -17,7 +17,7 @@
*/
import { Component, OnInit } from '@angular/core';
import {Router, ActivatedRoute} from '@angular/router';
-import {AlertService} from '../../service/alert.service';
+import {SearchService} from '../../service/search.service';
import {Alert} from '../../model/alert';
import {WorkflowService} from '../../service/workflow.service';
import {AlertSource} from '../../model/alert-source';
@@ -42,7 +42,7 @@ export class AlertDetailsComponent implements OnInit {
constructor(private router: Router,
private activatedRoute: ActivatedRoute,
- private alertsService: AlertService,
+ private searchService: SearchService,
private workflowService: WorkflowService) { }
goBack() {
@@ -51,7 +51,7 @@ export class AlertDetailsComponent implements OnInit {
}
getData() {
- this.alertsService.getAlert(this.alertSourceType, this.alertId).subscribe(alert => {
+ this.searchService.getAlert(this.alertSourceType, this.alertId).subscribe(alert => {
this.alertSource = alert;
this.alertFields = Object.keys(alert).filter(field => !field.includes(':ts') && field !== 'original_string').sort();
});
@@ -70,7 +70,7 @@ export class AlertDetailsComponent implements OnInit {
tAlert.source = this.alertSource;
this.selectedAlertState = AlertState.OPEN;
- this.alertsService.updateAlertState([tAlert], 'OPEN', '').subscribe(results => {
+ this.searchService.updateAlertState([tAlert], 'OPEN', '').subscribe(results => {
this.getData();
});
}
@@ -80,7 +80,7 @@ export class AlertDetailsComponent implements OnInit {
tAlert.source = this.alertSource;
this.selectedAlertState = AlertState.NEW;
- this.alertsService.updateAlertState([tAlert], 'NEW', '').subscribe(results => {
+ this.searchService.updateAlertState([tAlert], 'NEW', '').subscribe(results => {
this.getData();
});
}
@@ -91,7 +91,7 @@ export class AlertDetailsComponent implements OnInit {
this.selectedAlertState = AlertState.ESCALATE;
this.workflowService.start([tAlert]).subscribe(workflowId => {
- this.alertsService.updateAlertState([tAlert], 'ESCALATE', workflowId).subscribe(results => {
+ this.searchService.updateAlertState([tAlert], 'ESCALATE', workflowId).subscribe(results => {
this.getData();
});
});
@@ -102,7 +102,7 @@ export class AlertDetailsComponent implements OnInit {
tAlert.source = this.alertSource;
this.selectedAlertState = AlertState.DISMISS;
- this.alertsService.updateAlertState([tAlert], 'DISMISS', '').subscribe(results => {
+ this.searchService.updateAlertState([tAlert], 'DISMISS', '').subscribe(results => {
this.getData();
});
}
@@ -112,7 +112,7 @@ export class AlertDetailsComponent implements OnInit {
tAlert.source = this.alertSource;
this.selectedAlertState = AlertState.RESOLVE;
- this.alertsService.updateAlertState([tAlert], 'RESOLVE', '').subscribe(results => {
+ this.searchService.updateAlertState([tAlert], 'RESOLVE', '').subscribe(results => {
this.getData();
});
}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
index 35cbeff..72046fc 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.component.ts
@@ -20,7 +20,7 @@ import {Router, NavigationStart} from '@angular/router';
import {Observable, Subscription} from 'rxjs/Rx';
import {Alert} from '../../model/alert';
-import {AlertService} from '../../service/alert.service';
+import {SearchService} from '../../service/search.service';
import {QueryBuilder} from './query-builder';
import {ConfigureTableService} from '../../service/configure-table.service';
import {WorkflowService} from '../../service/workflow.service';
@@ -35,7 +35,7 @@ import {SaveSearch} from '../../model/save-search';
import {TableMetadata} from '../../model/table-metadata';
import {MetronDialogBox, DialogType} from '../../shared/metron-dialog-box';
import {AlertSearchDirective} from '../../shared/directives/alert-search.directive';
-import {AlertsSearchResponse} from '../../model/alerts-search-response';
+import {SearchResponse} from '../../model/search-response';
import {ElasticsearchUtils} from '../../utils/elasticsearch-utils';
@Component({
@@ -65,7 +65,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
queryBuilder: QueryBuilder = new QueryBuilder();
constructor(private router: Router,
- private alertsService: AlertService,
+ private searchService: SearchService,
private configureTableService: ConfigureTableService,
private workflowService: WorkflowService,
private clusterMetaDataService: ClusterMetaDataService,
@@ -204,7 +204,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
}
onConfigRowsChange() {
- this.alertsService.interval = this.refreshInterval;
+ this.searchService.interval = this.refreshInterval;
this.search();
}
@@ -253,26 +253,26 @@ export class AlertsListComponent implements OnInit, OnDestroy {
processEscalate() {
this.workflowService.start(this.selectedAlerts).subscribe(workflowId => {
- this.alertsService.updateAlertState(this.selectedAlerts, 'ESCALATE', workflowId).subscribe(results => {
+ this.searchService.updateAlertState(this.selectedAlerts, 'ESCALATE', workflowId).subscribe(results => {
this.updateSelectedAlertStatus('ESCALATE');
});
});
}
processDismiss() {
- this.alertsService.updateAlertState(this.selectedAlerts, 'DISMISS', '').subscribe(results => {
+ this.searchService.updateAlertState(this.selectedAlerts, 'DISMISS', '').subscribe(results => {
this.updateSelectedAlertStatus('DISMISS');
});
}
processOpen() {
- this.alertsService.updateAlertState(this.selectedAlerts, 'OPEN', '').subscribe(results => {
+ this.searchService.updateAlertState(this.selectedAlerts, 'OPEN', '').subscribe(results => {
this.updateSelectedAlertStatus('OPEN');
});
}
processResolve() {
- this.alertsService.updateAlertState(this.selectedAlerts, 'RESOLVE', '').subscribe(results => {
+ this.searchService.updateAlertState(this.selectedAlerts, 'RESOLVE', '').subscribe(results => {
this.updateSelectedAlertStatus('RESOLVE');
});
}
@@ -313,10 +313,10 @@ export class AlertsListComponent implements OnInit, OnDestroy {
this.saveSearchService.saveAsRecentSearches(savedSearch).subscribe(() => {});
}
- this.alertsService.search(this.queryBuilder.searchRequest).subscribe(results => {
+ this.searchService.search(this.queryBuilder.searchRequest).subscribe(results => {
this.setData(results);
}, error => {
- this.setData(new AlertsSearchResponse());
+ this.setData(new SearchResponse());
this.metronDialogBox.showConfirmationMessage(ElasticsearchUtils.extractESErrorMessage(error), DialogType.Error);
});
@@ -331,7 +331,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
}
}
- setData(results: AlertsSearchResponse) {
+ setData(results: SearchResponse) {
this.alerts = results.results;
this.pagingData.total = results.total;
}
@@ -370,7 +370,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
tryStartPolling() {
if (!this.pauseRefresh) {
this.tryStopPolling();
- this.refreshTimer = this.alertsService.pollSearch(this.queryBuilder.searchRequest).subscribe(results => {
+ this.refreshTimer = this.searchService.pollSearch(this.queryBuilder.searchRequest).subscribe(results => {
this.setData(results);
});
}
@@ -383,7 +383,7 @@ export class AlertsListComponent implements OnInit, OnDestroy {
}
updateConfigRowsSettings() {
- this.alertsService.interval = this.refreshInterval;
+ this.searchService.interval = this.refreshInterval;
this.queryBuilder.setFromAndSize(this.pagingData.from, this.pagingData.size);
}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.module.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.module.ts b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.module.ts
index adc8cbb..e6adae3 100644
--- a/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.module.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/alerts-list/alerts-list.module.ts
@@ -20,7 +20,7 @@ import {NgModule} from '@angular/core';
import {AlertsListComponent} from './alerts-list.component';
import {routing} from './alerts-list.routing';
import {SharedModule} from '../../shared/shared.module';
-import {AlertService} from '../../service/alert.service';
+import {SearchService} from '../../service/search.service';
import {MetronSorterModule} from '../../shared/metron-table/metron-sorter/metron-sorter.module';
import {ListGroupModule} from '../../shared/list-group/list-grup.module';
import {CollapseModule} from '../../shared/collapse/collapse.module';
@@ -32,7 +32,7 @@ import {ConfigureRowsModule} from '../configure-rows/configure-rows.module';
ListGroupModule, CollapseModule],
exports: [AlertsListComponent],
declarations: [AlertsListComponent],
- providers: [AlertService],
+ providers: [SearchService],
})
export class AlertsListModule {
}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/alerts/configure-table/configure-table.component.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/alerts/configure-table/configure-table.component.ts b/metron-interface/metron-alerts/src/app/alerts/configure-table/configure-table.component.ts
index 941343e..0c0117b 100644
--- a/metron-interface/metron-alerts/src/app/alerts/configure-table/configure-table.component.ts
+++ b/metron-interface/metron-alerts/src/app/alerts/configure-table/configure-table.component.ts
@@ -24,6 +24,7 @@ import {ClusterMetaDataService} from '../../service/cluster-metadata.service';
import {ColumnMetadata} from '../../model/column-metadata';
import {ColumnNamesService} from '../../service/column-names.service';
import {ColumnNames} from '../../model/column-names';
+import {SearchService} from '../../service/search.service';
export enum AlertState {
NEW, OPEN, ESCALATE, DISMISS, RESOLVE
@@ -51,8 +52,11 @@ export class ConfigureTableComponent implements OnInit {
allColumns: ColumnMetadataWrapper[] = [];
- constructor(private router: Router, private activatedRoute: ActivatedRoute, private configureTableService: ConfigureTableService,
- private clusterMetaDataService: ClusterMetaDataService, private columnNamesService: ColumnNamesService) { }
+ constructor(private router: Router, private activatedRoute: ActivatedRoute,
+ private configureTableService: ConfigureTableService,
+ private clusterMetaDataService: ClusterMetaDataService,
+ private columnNamesService: ColumnNamesService,
+ private searchService: SearchService) { }
goBack() {
this.router.navigateByUrl('/alerts-list');
@@ -80,7 +84,7 @@ export class ConfigureTableComponent implements OnInit {
ngOnInit() {
Observable.forkJoin(
this.clusterMetaDataService.getDefaultColumns(),
- this.clusterMetaDataService.getColumnMetaData(),
+ this.searchService.getColumnMetaData(),
this.configureTableService.getTableMetadata()
).subscribe((response: any) => {
this.prepareData(response[0], response[1], response[2].tableColumns);
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/app.module.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/app.module.ts b/metron-interface/metron-alerts/src/app/app.module.ts
index 295c748..f16b2d1 100644
--- a/metron-interface/metron-alerts/src/app/app.module.ts
+++ b/metron-interface/metron-alerts/src/app/app.module.ts
@@ -36,7 +36,7 @@ import {ConfigureRowsModule} from './alerts/configure-rows/configure-rows.module
import {SwitchModule} from './shared/switch/switch.module';
import {ColumnNamesService} from './service/column-names.service';
import {DataSource} from './service/data-source';
-import {RestApiImpl} from './service/rest-api-impl';
+import {ElasticSearchLocalstorageImpl} from './service/elasticsearch-localstorage-impl';
import {LoginModule} from './login/login.module';
import {AuthGuard} from './shared/auth-guard';
import {AuthenticationService} from './service/authentication.service';
@@ -67,7 +67,7 @@ export function initConfig(config: ColumnNamesService) {
SwitchModule
],
providers: [{ provide: APP_INITIALIZER, useFactory: initConfig, deps: [ColumnNamesService], multi: true },
- { provide: DataSource, useClass: RestApiImpl },
+ { provide: DataSource, useClass: ElasticSearchLocalstorageImpl },
AuthenticationService,
AuthGuard,
LoginGuard,
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/model/alerts-search-response.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/model/alerts-search-response.ts b/metron-interface/metron-alerts/src/app/model/alerts-search-response.ts
deleted file mode 100644
index 265f66b..0000000
--- a/metron-interface/metron-alerts/src/app/model/alerts-search-response.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import {Alert} from './alert';
-
-export class AlertsSearchResponse {
- total = 0;
- results: Alert[] = [];
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/model/search-request.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/model/search-request.ts b/metron-interface/metron-alerts/src/app/model/search-request.ts
index 2150f2b..a37bd8d 100644
--- a/metron-interface/metron-alerts/src/app/model/search-request.ts
+++ b/metron-interface/metron-alerts/src/app/model/search-request.ts
@@ -1,4 +1,5 @@
import {SortField} from './sort-field';
+import {INDEXES} from '../utils/constants';
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,7 +20,7 @@ import {SortField} from './sort-field';
export class SearchRequest {
// _source: string[]; //TODO: This needs to be removed
from: number;
- indices: string[] = ['websphere', 'snort', 'asa', 'bro', 'yaf'];
+ indices: string[] = INDEXES;
query: string;
size: number;
sort: SortField[];
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/model/search-response.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/model/search-response.ts b/metron-interface/metron-alerts/src/app/model/search-response.ts
new file mode 100644
index 0000000..c3fea27
--- /dev/null
+++ b/metron-interface/metron-alerts/src/app/model/search-response.ts
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import {Alert} from './alert';
+
+export class SearchResponse {
+ total = 0;
+ results: Alert[] = [];
+}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/alert.service.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/alert.service.ts b/metron-interface/metron-alerts/src/app/service/alert.service.ts
deleted file mode 100644
index 7dabc4f..0000000
--- a/metron-interface/metron-alerts/src/app/service/alert.service.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import {Injectable, NgZone} from '@angular/core';
-import {Observable} from 'rxjs/Rx';
-import 'rxjs/add/observable/interval';
-import 'rxjs/add/operator/switchMap';
-import 'rxjs/add/operator/onErrorResumeNext';
-
-import {Alert} from '../model/alert';
-import {Http} from '@angular/http';
-import {DataSource} from './data-source';
-import {AlertsSearchResponse} from '../model/alerts-search-response';
-import {SearchRequest} from '../model/search-request';
-import {AlertSource} from '../model/alert-source';
-
-@Injectable()
-export class AlertService {
-
- interval = 80000;
- defaultHeaders = {'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'};
-
- constructor(private http: Http,
- private dataSource: DataSource,
- private ngZone: NgZone) { }
-
- public search(searchRequest: SearchRequest): Observable<AlertsSearchResponse> {
- return this.dataSource.getAlerts(searchRequest);
- }
-
- public pollSearch(searchRequest: SearchRequest): Observable<AlertsSearchResponse> {
- return this.ngZone.runOutsideAngular(() => {
- return this.ngZone.run(() => {
- return Observable.interval(this.interval * 1000).switchMap(() => {
- return this.dataSource.getAlerts(searchRequest);
- });
- });
- });
- }
-
- public getAlert(sourceType: string, alertId: string): Observable<AlertSource> {
- return this.dataSource.getAlert(sourceType, alertId);
- }
-
- public updateAlertState(alerts: Alert[], state: string, workflowId: string) {
- let request = '';
- for (let alert of alerts) {
- request += '{ "update" : { "sensorType" : "' + alert.source['source:type'] + '", "guid" : "' + alert.source.guid + '" } }\n' +
- '{ "doc": { "alert_status": "' + state + '"';
- if (workflowId) {
- request += ', "workflow_id": "' + workflowId + '"';
- }
- request += ' }}\n';
- }
-
- return this.dataSource.updateAlertState(request);
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/cluster-metadata.service.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/cluster-metadata.service.ts b/metron-interface/metron-alerts/src/app/service/cluster-metadata.service.ts
index 4077f30..ffd4ec1 100644
--- a/metron-interface/metron-alerts/src/app/service/cluster-metadata.service.ts
+++ b/metron-interface/metron-alerts/src/app/service/cluster-metadata.service.ts
@@ -18,11 +18,14 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {Http} from '@angular/http';
+
+
import {ColumnMetadata} from '../model/column-metadata';
import {DataSource} from './data-source';
@Injectable()
export class ClusterMetaDataService {
+ defaultHeaders: {'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'};
constructor(private http: Http,
private dataSource: DataSource) {
@@ -31,8 +34,4 @@ export class ClusterMetaDataService {
getDefaultColumns(): Observable<ColumnMetadata[]> {
return this.dataSource.getDefaultAlertTableColumnNames();
}
-
- getColumnMetaData(): Observable<ColumnMetadata[]> {
- return this.dataSource.getAllFieldNames();
- }
}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/data-source.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/data-source.ts b/metron-interface/metron-alerts/src/app/service/data-source.ts
index 28ee384..f4f90ed 100644
--- a/metron-interface/metron-alerts/src/app/service/data-source.ts
+++ b/metron-interface/metron-alerts/src/app/service/data-source.ts
@@ -22,7 +22,7 @@ import {ColumnMetadata} from '../model/column-metadata';
import {ColumnNames} from '../model/column-names';
import {TableMetadata} from '../model/table-metadata';
import {SaveSearch} from '../model/save-search';
-import {AlertsSearchResponse} from '../model/alerts-search-response';
+import {SearchResponse} from '../model/search-response';
import {SearchRequest} from '../model/search-request';
import {AlertSource} from '../model/alert-source';
@@ -33,7 +33,7 @@ export abstract class DataSource {
constructor(protected http: Http) {}
// Calls to fetch alerts
- abstract getAlerts(searchRequest: SearchRequest): Observable<AlertsSearchResponse>
+ abstract getAlerts(searchRequest: SearchRequest): Observable<SearchResponse>
abstract getAlert(sourceType: string, alertId: string): Observable<AlertSource>
abstract updateAlertState(request: any): Observable<{}>
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/elasticsearch-localstorage-impl.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/elasticsearch-localstorage-impl.ts b/metron-interface/metron-alerts/src/app/service/elasticsearch-localstorage-impl.ts
index f4e43d5..7982102 100644
--- a/metron-interface/metron-alerts/src/app/service/elasticsearch-localstorage-impl.ts
+++ b/metron-interface/metron-alerts/src/app/service/elasticsearch-localstorage-impl.ts
@@ -30,7 +30,7 @@ import {ColumnNames} from '../model/column-names';
import {ColumnNamesService} from './column-names.service';
import {TableMetadata} from '../model/table-metadata';
import {SaveSearch} from '../model/save-search';
-import {AlertsSearchResponse} from '../model/alerts-search-response';
+import {SearchResponse} from '../model/search-response';
import {SearchRequest} from '../model/search-request';
import {AlertSource} from '../model/alert-source';
@@ -47,7 +47,7 @@ export class ElasticSearchLocalstorageImpl extends DataSource {
new ColumnMetadata('alert_status', 'string')
];
- getAlerts(searchRequest: SearchRequest): Observable<AlertsSearchResponse> {
+ getAlerts(searchRequest: SearchRequest): Observable<SearchResponse> {
let url = '/search/*' + ElasticsearchUtils.excludeIndexName + '/_search';
let request: any = JSON.parse(JSON.stringify(searchRequest));
request.query = { query_string: { query: searchRequest.query } };
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/rest-api-impl.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/rest-api-impl.ts b/metron-interface/metron-alerts/src/app/service/rest-api-impl.ts
deleted file mode 100644
index 061708d..0000000
--- a/metron-interface/metron-alerts/src/app/service/rest-api-impl.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import {Observable} from 'rxjs/Rx';
-import {Headers, RequestOptions} from '@angular/http';
-
-import {HttpUtil} from '../utils/httpUtil';
-import {AlertsSearchResponse} from '../model/alerts-search-response';
-import {SearchRequest} from '../model/search-request';
-import {ElasticSearchLocalstorageImpl} from './elasticsearch-localstorage-impl';
-import {AlertSource} from '../model/alert-source';
-
-export class RestApiImpl extends ElasticSearchLocalstorageImpl {
-
- getAlerts(searchRequest: SearchRequest): Observable<AlertsSearchResponse> {
- let url = '/api/v1/search/search';
- return this.http.post(url, searchRequest, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
- .map(HttpUtil.extractData)
- .catch(HttpUtil.handleError)
- .onErrorResumeNext();
- }
-
- getAlert(sourceType: string, alertId: string): Observable<AlertSource> {
- let url = '/api/v1/search/findOne';
- let requestSchema = { guid: alertId, sensorType: sourceType};
-
- return this.http.post(url, requestSchema, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
- .map(HttpUtil.extractData)
- .catch(HttpUtil.handleError)
- .onErrorResumeNext();
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/service/search.service.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/service/search.service.ts b/metron-interface/metron-alerts/src/app/service/search.service.ts
new file mode 100644
index 0000000..be3b1f6
--- /dev/null
+++ b/metron-interface/metron-alerts/src/app/service/search.service.ts
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import {Injectable, NgZone} from '@angular/core';
+import {Headers, RequestOptions} from '@angular/http';
+import {Observable} from 'rxjs/Rx';
+import 'rxjs/add/observable/interval';
+import 'rxjs/add/operator/switchMap';
+import 'rxjs/add/operator/onErrorResumeNext';
+
+import {HttpUtil} from '../utils/httpUtil';
+import {Alert} from '../model/alert';
+import {Http} from '@angular/http';
+import {DataSource} from './data-source';
+import {SearchResponse} from '../model/search-response';
+import {SearchRequest} from '../model/search-request';
+import {AlertSource} from '../model/alert-source';
+import {INDEXES} from '../utils/constants';
+import {ColumnMetadata} from '../model/column-metadata';
+
+@Injectable()
+export class SearchService {
+
+ interval = 80000;
+ defaultHeaders = {'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'};
+
+ private static extractColumnNameDataFromRestApi(res: Response): ColumnMetadata[] {
+ let response: any = res || {};
+ let processedKeys: string[] = [];
+ let columnMetadatas: ColumnMetadata[] = [];
+
+ for (let index of Object.keys(response)) {
+ let indexMetaData = response[index];
+ for (let key of Object.keys(indexMetaData)) {
+ if (processedKeys.indexOf(key) === -1) {
+ processedKeys.push(key);
+ columnMetadatas.push(new ColumnMetadata(key, indexMetaData[key]));
+ }
+ }
+ }
+
+ return columnMetadatas;
+ }
+
+ constructor(private http: Http,
+ private dataSource: DataSource,
+ private ngZone: NgZone) { }
+
+ public getAlert(sourceType: string, alertId: string): Observable<AlertSource> {
+ let url = '/api/v1/search/findOne';
+ let requestSchema = { guid: alertId, sensorType: sourceType};
+
+ return this.http.post(url, requestSchema, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
+ .map(HttpUtil.extractData)
+ .catch(HttpUtil.handleError)
+ .onErrorResumeNext();
+ }
+
+ public getColumnMetaData(): Observable<ColumnMetadata[]> {
+ let url = '/api/v1/search/column/metadata';
+ return this.http.post(url, INDEXES, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
+ .map(HttpUtil.extractData)
+ .map(SearchService.extractColumnNameDataFromRestApi)
+ .catch(HttpUtil.handleError);
+ }
+
+ public pollSearch(searchRequest: SearchRequest): Observable<SearchResponse> {
+ return this.ngZone.runOutsideAngular(() => {
+ return this.ngZone.run(() => {
+ return Observable.interval(this.interval * 1000).switchMap(() => {
+ return this.search(searchRequest);
+ });
+ });
+ });
+ }
+
+ public search(searchRequest: SearchRequest): Observable<SearchResponse> {
+ let url = '/api/v1/search/search';
+ return this.http.post(url, searchRequest, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
+ .map(HttpUtil.extractData)
+ .catch(HttpUtil.handleError)
+ .onErrorResumeNext();
+ }
+
+ public updateAlertState(alerts: Alert[], state: string, workflowId: string) {
+ let request = '';
+ for (let alert of alerts) {
+ request += '{ "update" : { "sensorType" : "' + alert.source['source:type'] + '", "guid" : "' + alert.source.guid + '" } }\n' +
+ '{ "doc": { "alert_status": "' + state + '"';
+ if (workflowId) {
+ request += ', "workflow_id": "' + workflowId + '"';
+ }
+ request += ' }}\n';
+ }
+
+ return this.dataSource.updateAlertState(request);
+ }
+}
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/utils/constants.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/utils/constants.ts b/metron-interface/metron-alerts/src/app/utils/constants.ts
index da6d50c..a738a1d 100644
--- a/metron-interface/metron-alerts/src/app/utils/constants.ts
+++ b/metron-interface/metron-alerts/src/app/utils/constants.ts
@@ -20,3 +20,5 @@ export const ALERTS_RECENT_SEARCH = 'metron-alerts-recent-saved-search';
export const ALERTS_SAVED_SEARCH = 'metron-alerts-saved-search';
export const ALERTS_TABLE_METADATA = 'metron-alerts-table-metadata';
export const ALERTS_COLUMN_NAMES = 'metron-alerts-column-names';
+
+export let INDEXES = ['websphere', 'snort', 'asa', 'bro', 'yaf'];
http://git-wip-us.apache.org/repos/asf/metron/blob/ea65a37c/metron-interface/metron-alerts/src/app/utils/elasticsearch-utils.ts
----------------------------------------------------------------------
diff --git a/metron-interface/metron-alerts/src/app/utils/elasticsearch-utils.ts b/metron-interface/metron-alerts/src/app/utils/elasticsearch-utils.ts
index a86907b..0896f32 100644
--- a/metron-interface/metron-alerts/src/app/utils/elasticsearch-utils.ts
+++ b/metron-interface/metron-alerts/src/app/utils/elasticsearch-utils.ts
@@ -16,7 +16,7 @@
* limitations under the License.
*/
import {ColumnMetadata} from '../model/column-metadata';
-import {AlertsSearchResponse} from '../model/alerts-search-response';
+import {SearchResponse} from '../model/search-response';
export class ElasticsearchUtils {
@@ -54,9 +54,9 @@ export class ElasticsearchUtils {
return columnMetadata;
}
- public static extractAlertsData(res: Response): AlertsSearchResponse {
+ public static extractAlertsData(res: Response): SearchResponse {
let response: any = res || {};
- let alertsSearchResponse: AlertsSearchResponse = new AlertsSearchResponse();
+ let alertsSearchResponse: SearchResponse = new SearchResponse();
alertsSearchResponse.total = response['hits']['total'];
alertsSearchResponse.results = response['hits']['hits'];
return alertsSearchResponse;