From 6204911ac6d99d9f2321267b8c947f2682b9f2d7 Mon Sep 17 00:00:00 2001 From: merrimanr Date: Fri, 22 Jun 2018 15:25:32 -0500 Subject: [PATCH 1/2] initial commit --- .../alert-details/alert-details.component.ts | 68 ++++++++----------- .../src/app/service/alerts.service.ts | 2 +- 2 files changed, 31 insertions(+), 39 deletions(-) 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 c939f04849..773106b8c6 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 @@ -93,20 +93,20 @@ export class AlertDetailsComponent implements OnInit { return false; } - getData(fireToggleEditor = false) { + getData() { this.alertCommentStr = ''; this.searchService.getAlert(this.alertSourceType, this.alertId).subscribe(alertSource => { - this.alertSource = alertSource; - this.selectedAlertState = this.getAlertState(alertSource['alert_status']); - this.alertSources = (alertSource.metron_alert && alertSource.metron_alert.length > 0) ? alertSource.metron_alert : [alertSource]; + this.setAlert(alertSource); this.setComments(alertSource); - - if (fireToggleEditor) { - this.toggleNameEditor(); - } }); } + setAlert(alertSource) { + this.alertSource = alertSource; + this.alertSources = (alertSource.metron_alert && alertSource.metron_alert.length > 0) ? alertSource.metron_alert : [alertSource]; + this.selectedAlertState = this.getAlertState(alertSource['alert_status']); + } + setComments(alert) { let alertComments = alert['comments'] ? alert['comments'] : []; this.alertCommentsWrapper = alertComments.map(alertComment => @@ -150,53 +150,39 @@ export class AlertDetailsComponent implements OnInit { } processOpen() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.OPEN; - this.updateService.updateAlertState([tAlert], 'OPEN').subscribe(results => { - this.getData(); - }); + this.updateAlertState('OPEN'); } processNew() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.NEW; - this.updateService.updateAlertState([tAlert], 'NEW').subscribe(results => { - this.getData(); - }); + this.updateAlertState('NEW'); } processEscalate() { + this.updateAlertState('ESCALATE'); + let tAlert = new Alert(); tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.ESCALATE; - this.updateService.updateAlertState([tAlert], 'ESCALATE').subscribe(results => { - this.getData(); - }); this.alertsService.escalate([tAlert]).subscribe(); } processDismiss() { - let tAlert = new Alert(); - tAlert.source = this.alertSource; - - this.selectedAlertState = AlertState.DISMISS; - this.updateService.updateAlertState([tAlert], 'DISMISS').subscribe(results => { - this.getData(); - }); + this.updateAlertState('DISMISS'); } processResolve() { + this.updateAlertState('RESOLVE'); + } + + updateAlertState(state: string) { let tAlert = new Alert(); tAlert.source = this.alertSource; - this.selectedAlertState = AlertState.RESOLVE; - this.updateService.updateAlertState([tAlert], 'RESOLVE').subscribe(results => { - this.getData(); + let previousAlertStatus = this.alertSource['alert_status']; + this.alertSource['alert_status'] = state; + this.setAlert(this.alertSource); + this.updateService.updateAlertState([tAlert], state).subscribe(() => {}, () => { + this.alertSource['alert_status'] = previousAlertStatus; + this.setAlert(this.alertSource); }); } @@ -215,8 +201,14 @@ export class AlertDetailsComponent implements OnInit { patchRequest.index = META_ALERTS_INDEX; patchRequest.patch = [new Patch('add', '/name', this.alertName)]; + let previousName = this.alertSource['name']; + this.alertSource['name'] = this.alertName; this.updateService.patch(patchRequest).subscribe(rep => { - this.getData(true); + this.toggleNameEditor(); + }, () => { + this.alertSource['name'] = previousName; + this.alertName = previousName; + this.toggleNameEditor(); }); } } diff --git a/metron-interface/metron-alerts/src/app/service/alerts.service.ts b/metron-interface/metron-alerts/src/app/service/alerts.service.ts index 7324a7275e..56939d8f9b 100644 --- a/metron-interface/metron-alerts/src/app/service/alerts.service.ts +++ b/metron-interface/metron-alerts/src/app/service/alerts.service.ts @@ -30,7 +30,7 @@ export class AlertsService { } public escalate(alerts: Alert[]): Observable { - return this.http.post('/api/v1/alert/escalate', alerts, new RequestOptions({headers: new Headers(this.defaultHeaders)})) + return this.http.post('/api/v1/alerts/ui/escalate', alerts, new RequestOptions({headers: new Headers(this.defaultHeaders)})) .catch(HttpUtil.handleError); } } From 36b3254a9d50ac7b052e8c7dd7d51f5251f7f5fa Mon Sep 17 00:00:00 2001 From: merrimanr Date: Mon, 25 Jun 2018 16:20:11 -0500 Subject: [PATCH 2/2] initial commit --- .../metron-alerts/src/app/service/alerts.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metron-interface/metron-alerts/src/app/service/alerts.service.ts b/metron-interface/metron-alerts/src/app/service/alerts.service.ts index 7324a7275e..56939d8f9b 100644 --- a/metron-interface/metron-alerts/src/app/service/alerts.service.ts +++ b/metron-interface/metron-alerts/src/app/service/alerts.service.ts @@ -30,7 +30,7 @@ export class AlertsService { } public escalate(alerts: Alert[]): Observable { - return this.http.post('/api/v1/alert/escalate', alerts, new RequestOptions({headers: new Headers(this.defaultHeaders)})) + return this.http.post('/api/v1/alerts/ui/escalate', alerts, new RequestOptions({headers: new Headers(this.defaultHeaders)})) .catch(HttpUtil.handleError); } }