Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit 7971b5c

Browse files
author
Chris Wiechmann
committed
Added more fields to the search result
#103
1 parent 60f77a2 commit 7971b5c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

apibuilder4elastic/flows/trafficMonitorApi-search.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@
124124
"metaName": "Unsafe mode",
125125
"metaDescription": "USE WITH CAUTION. When enabled, JavaScript is not executed in a sandboxed environment and all globals are available."
126126
},
127-
{
128-
"name": "code",
129-
"type": "string",
130-
"value": "\"var result = {};\\n var hits = data.elasticsearch.result.body.hits.hits;\\n var protocol = data.params.protocol;\\n result.processId = \\\"\\\";\\n result.data = [];\\n hits.map(function(entry) {\\n var dataObject = {};\\n var _source = entry._source;\\n dataObject.correlationId = _source.correlationId;\\n dataObject.timestamp = Date.parse(_source['@timestamp']);\\n if(_source.serviceContext) {\\n dataObject.serviceName = _source.serviceContext.service;\\n dataObject.operation = _source.serviceContext.method;\\n }\\n dataObject.type = protocol;\\n switch (protocol) {\\n case \\\"http\\\":\\n formatHttpFields(dataObject, _source);\\n break;\\n case \\\"fileTransfer\\\":\\n formatFiletransferFields(dataObject, _source);\\n break;\\n }\\n result.data.push(dataObject);\\n });\\n \\n function formatHttpFields(dataObject, _source) { \\n dataObject.statustext = _source.http.statusText;\\n dataObject.method = _source.http.method;\\n dataObject.status = _source.http.status;\\n dataObject.wafStatus = _source.http.wafStatus;\\n dataObject.subject = _source.http.authSubjectId;\\n dataObject.localPort = _source.http.localPort;\\n dataObject.uri = _source.http.uri;\\n dataObject.vhost = _source.http.vhost;\\n dataObject.duration = _source.duration;\\n dataObject.finalStatus = _source.finalStatus;\\n }\\n \\n function formatFiletransferFields(dataObject, _source) {\\n dataObject.remoteAddr = _source.fileTransfer.remoteAddr;\\n dataObject.uploadFile = _source.fileTransfer.uploadFile;\\n dataObject.direction = _source.fileTransfer.direction;\\n dataObject.servicetype = _source.fileTransfer.serviceType;\\n dataObject.size = _source.fileTransfer.size;\\n dataObject.duration = _source.duration;\\n dataObject.subject = _source.fileTransfer.authSubjectId;\\n dataObject.finalStatus = _source.finalStatus;\\n }\\n\\n \\n return result;\"",
131-
"metaName": "code",
132-
"metaDescription": "A JavaScript function body. Supports `await` and returning promises."
133-
},
134127
{
135128
"name": "data",
136129
"type": "jsonpath",
137130
"value": "$",
138131
"metaName": "data",
139132
"metaDescription": "The value to apply as the `data` argument to the JavaScript code. For objects and arrays, `data` is passed by reference."
133+
},
134+
{
135+
"name": "code",
136+
"type": "string",
137+
"value": "\"var result = {};\\n var hits = data.elasticsearch.result.body.hits.hits;\\n var protocol = data.params.protocol;\\n result.processId = \\\"\\\";\\n result.data = [];\\n hits.map(function(entry) {\\n var dataObject = {};\\n var _source = entry._source;\\n dataObject.correlationId = _source.correlationId;\\n dataObject.timestamp = Date.parse(_source['@timestamp']);\\n if(_source.serviceContext) {\\n dataObject.serviceName = _source.serviceContext.service;\\n dataObject.operation = _source.serviceContext.method;\\n }\\n dataObject.type = protocol;\\n switch (protocol) {\\n case \\\"http\\\":\\n formatHttpFields(dataObject, _source);\\n break;\\n case \\\"fileTransfer\\\":\\n formatFiletransferFields(dataObject, _source);\\n break;\\n }\\n result.data.push(dataObject);\\n });\\n \\n function formatHttpFields(dataObject, _source) { \\n dataObject.statustext = _source.http.statusText;\\n dataObject.method = _source.http.method;\\n dataObject.status = _source.http.status;\\n dataObject.wafStatus = _source.http.wafStatus;\\n dataObject.subject = _source.http.authSubjectId;\\n dataObject.localPort = _source.http.localPort;\\n dataObject.uri = _source.http.uri;\\n dataObject.vhost = _source.http.vhost;\\n dataObject.duration = _source.duration;\\n dataObject.finalStatus = _source.finalStatus;\\n dataObject.bytesReceived = _source.http.bytesReceived;\\n dataObject.bytesSent = _source.http.bytesSent;\\n dataObject.remoteName = _source.http.remoteName;\\n dataObject.remoteAddr = _source.http.remoteAddr;\\n dataObject.remotePort = _source.http.remotePort;\\n dataObject.localAddr = _source.http.localAddr;\\n dataObject.localPort = _source.http.localPort;\\n }\\n \\n function formatFiletransferFields(dataObject, _source) {\\n dataObject.remoteAddr = _source.fileTransfer.remoteAddr;\\n dataObject.uploadFile = _source.fileTransfer.uploadFile;\\n dataObject.direction = _source.fileTransfer.direction;\\n dataObject.servicetype = _source.fileTransfer.serviceType;\\n dataObject.size = _source.fileTransfer.size;\\n dataObject.duration = _source.duration;\\n dataObject.subject = _source.fileTransfer.authSubjectId;\\n dataObject.finalStatus = _source.finalStatus;\\n }\\n\\n \\n return result;\"",
138+
"metaName": "code",
139+
"metaDescription": "A JavaScript function body. Supports `await` and returning promises."
140140
}
141141
],
142142
"outputs": {

apibuilder4elastic/test/trafficMonitorAPI/asAdmin/http/test_search_endpoint_AsAdmin.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Endpoints', function () {
5252
after(() => stopApiBuilder(server));
5353

5454
describe('Search', async () => {
55-
it('[Search-0001] Execute a search without a limit including all requests from instance-1', async () => {
55+
it.only('[Search-0001] Execute a search without a limit including all requests from instance-1', async () => {
5656
return await requestAsync({
5757
method: 'GET',
5858
uri: `http://localhost:${server.apibuilder.port}/api/elk/v1/api/router/service/instance-1/ops/search`,
@@ -633,6 +633,13 @@ function checkFields(data, hasServiceContext) {
633633
expect(entry).to.have.property('uri');
634634
expect(entry).to.have.property('duration');
635635
expect(entry).to.have.property('type');
636+
expect(entry).to.have.property('bytesSent');
637+
expect(entry).to.have.property('bytesReceived');
638+
expect(entry).to.have.property('remoteName');
639+
expect(entry).to.have.property('remoteAddr');
640+
expect(entry).to.have.property('remotePort');
641+
expect(entry).to.have.property('localAddr');
642+
expect(entry).to.have.property('vhost');
636643
if(entry.method!='OPTIONS') {
637644
expect(entry).to.have.property('finalStatus');
638645
}

0 commit comments

Comments
 (0)