Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion metron-interface/metron-alerts/src/app/pcap/model/pdml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class PdmlProto {
public fields: PdmlField[]

public static findField(p: PdmlProto, name: string): PdmlField {
return p.fields.find(f => f['name'] == name)
if (p && p.fields) {
return p.fields.find(f => f['name'] == name)
} else {
return new PdmlField();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,38 @@ export class PcapPanelComponent {
this.pagination.selectedPage = 1;
this.pdml = null;
this.progressWidth = 0;
this.pcapService.submitRequest(pcapRequest).subscribe(id => {
this.queryId = id;
this.queryRunning = true;
this.errorMsg = null;
this.statusSubscription = this.pcapService.pollStatus(id).subscribe((statusResponse: PcapStatusResponse) => {
if ('SUCCEEDED' === statusResponse.jobStatus) {
this.pagination.total = statusResponse.pageTotal;
this.errorMsg = null;
this.pcapService.submitRequest(pcapRequest).subscribe((statusResponse: PcapStatusResponse) => {
let id = statusResponse.jobId;
if (!id) {
this.errorMsg = statusResponse.description;
} else {
this.queryId = id;
this.queryRunning = true;
this.errorMsg = null;
this.statusSubscription = this.pcapService.pollStatus(id).subscribe((statusResponse: PcapStatusResponse) => {
if ('SUCCEEDED' === statusResponse.jobStatus) {
this.pagination.total = statusResponse.pageTotal;
this.statusSubscription.unsubscribe();
this.queryRunning = false;
this.pcapService.getPackets(id, this.pagination.selectedPage).toPromise().then(pdml => {
this.pdml = pdml;
});
} else if ('FAILED' === statusResponse.jobStatus) {
this.statusSubscription.unsubscribe();
this.queryRunning = false;
this.errorMsg = `Query status: ${statusResponse.jobStatus}. Check your filter criteria and try again!`;
} else if (this.progressWidth < 100) {
this.progressWidth = Math.trunc(statusResponse.percentComplete);
}
}, (error: any) => {
this.statusSubscription.unsubscribe();
this.queryRunning = false;
this.pcapService.getPackets(id, this.pagination.selectedPage).toPromise().then(pdml => {
this.pdml = pdml;
});
} else if ('FAILED' === statusResponse.jobStatus) {
this.statusSubscription.unsubscribe();
this.queryRunning = false;
this.errorMsg = `Query status: ${statusResponse.jobStatus}. Check your filter criteria and try again!`;
} else if (this.progressWidth < 100) {
this.progressWidth = Math.trunc(statusResponse.percentComplete);
}
}, (error: any) => {
this.statusSubscription.unsubscribe();
this.queryRunning = false;
this.errorMsg = `Response status: ${error.responseCode}. Something went wrong with your status request!`;
});
this.errorMsg = `Response message: ${error.message}. Something went wrong with your status request!`;
});
}
}, (error: any) => {
this.errorMsg = `Response message: ${error.message}. Something went wrong with your query submission!`;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {PcapRequest} from '../model/pcap.request';
import {Pdml} from '../model/pdml';

export class PcapStatusResponse {
jobId: string;
jobStatus: string;
description: string;
percentComplete: number;
pageTotal: number;
}
Expand All @@ -46,11 +48,10 @@ export class PcapService {
});
}

public submitRequest(pcapRequest: PcapRequest): Observable<string> {
public submitRequest(pcapRequest: PcapRequest): Observable<PcapStatusResponse> {
return this.http.post('/api/v1/pcap/fixed', pcapRequest, new RequestOptions({headers: new Headers(this.defaultHeaders)}))
.map(result => JSON.parse(result.text()).jobId)
.catch(HttpUtil.handleError)
.onErrorResumeNext();
.map(HttpUtil.extractData)
.catch(HttpUtil.handleError);
}

public getStatus(id: string): Observable<PcapStatusResponse> {
Expand Down