mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[add data] adds the geoip processor
This commit is contained in:
parent
2ec8900293
commit
96cbe8997b
8 changed files with 169 additions and 0 deletions
|
@ -2,5 +2,6 @@ import './processor_ui_container';
|
|||
import './processor_ui_append';
|
||||
import './processor_ui_convert';
|
||||
import './processor_ui_date';
|
||||
import './processor_ui_geoip';
|
||||
import './processor_ui_gsub';
|
||||
import './processor_ui_set';
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import uiModules from 'ui/modules';
|
||||
import _ from 'lodash';
|
||||
import keysDeep from '../lib/keys_deep';
|
||||
import template from '../views/processor_ui_geoip.html';
|
||||
|
||||
const app = uiModules.get('kibana');
|
||||
|
||||
//scope.processor, scope.pipeline are attached by the process_container.
|
||||
app.directive('processorUiGeoip', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: template,
|
||||
controller : function ($scope) {
|
||||
const processor = $scope.processor;
|
||||
const pipeline = $scope.pipeline;
|
||||
|
||||
function consumeNewInputObject() {
|
||||
$scope.fields = keysDeep(processor.inputObject);
|
||||
refreshFieldData();
|
||||
}
|
||||
|
||||
function refreshFieldData() {
|
||||
$scope.fieldData = _.get(processor.inputObject, processor.sourceField);
|
||||
}
|
||||
|
||||
function processorUiChanged() {
|
||||
pipeline.setDirty();
|
||||
}
|
||||
|
||||
$scope.$watch('processor.inputObject', consumeNewInputObject);
|
||||
|
||||
$scope.$watch('processor.sourceField', () => {
|
||||
refreshFieldData();
|
||||
processorUiChanged();
|
||||
});
|
||||
|
||||
$scope.$watch('processor.targetField', processorUiChanged);
|
||||
}
|
||||
};
|
||||
});
|
|
@ -101,6 +101,29 @@ export class Date extends Processor {
|
|||
}
|
||||
};
|
||||
|
||||
export class GeoIp extends Processor {
|
||||
constructor(processorId) {
|
||||
super(processorId, 'geoip', 'Geo IP');
|
||||
this.sourceField = '';
|
||||
this.targetField = 'geoip';
|
||||
}
|
||||
|
||||
get description() {
|
||||
const source = this.sourceField || '?';
|
||||
const target = this.targetField || '?';
|
||||
return `[${source}] -> [${target}]`;
|
||||
}
|
||||
|
||||
get model() {
|
||||
return {
|
||||
processorId: this.processorId,
|
||||
typeId: this.typeId,
|
||||
sourceField: this.sourceField || '',
|
||||
targetField: this.targetField || ''
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export class Gsub extends Processor {
|
||||
constructor(processorId) {
|
||||
super(processorId, 'gsub', 'Gsub');
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<div class="form-group">
|
||||
<label>Field:</label>
|
||||
<select
|
||||
class="form-control"
|
||||
ng-options="field as field for field in fields"
|
||||
ng-model="processor.sourceField">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Field Data:</label>
|
||||
<pre>{{ fieldData }}</pre>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Target Field:</label>
|
||||
<input type="text" class="form-control" ng-model="processor.targetField">
|
||||
</div>
|
|
@ -57,6 +57,16 @@ export function date(processorApiDocument) {
|
|||
};
|
||||
}
|
||||
|
||||
export function geoip(processorApiDocument) {
|
||||
return {
|
||||
geoip: {
|
||||
tag: processorApiDocument.processor_id,
|
||||
source_field: processorApiDocument.source_field,
|
||||
target_field: processorApiDocument.target_field
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function gsub(processorApiDocument) {
|
||||
return {
|
||||
gsub: {
|
||||
|
|
|
@ -27,6 +27,12 @@ export const date = base.keys({
|
|||
custom_format: Joi.string().allow('')
|
||||
});
|
||||
|
||||
export const geoip = base.keys({
|
||||
type_id: Joi.string().only('geoip').required(),
|
||||
source_field: Joi.string().allow(''),
|
||||
target_field: Joi.string().allow('')
|
||||
});
|
||||
|
||||
export const gsub = base.keys({
|
||||
type_id: Joi.string().only('gsub').required(),
|
||||
source_field: Joi.string().allow(''),
|
||||
|
|
71
test/unit/api/ingest/processors/_geoip.js
Normal file
71
test/unit/api/ingest/processors/_geoip.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
const testPipeline = {
|
||||
processors: [{
|
||||
processor_id: 'processor1',
|
||||
type_id: 'geoip',
|
||||
source_field: 'ip',
|
||||
target_field: 'geoip'
|
||||
}],
|
||||
input: { ip: '74.125.21.103' }
|
||||
};
|
||||
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('simulate - geoip processor', () => {
|
||||
//TODO: These tests can be re-added when we address
|
||||
// installing plugins for integration tests
|
||||
// https://github.com/elastic/kibana/issues/6852
|
||||
|
||||
// bdd.it('should return 400 for an invalid payload', () => {
|
||||
// return Promise.all([
|
||||
// // Geo IP processor requires source_field property
|
||||
// request.post('/kibana/ingest/simulate')
|
||||
// .send({
|
||||
// input: { ip: '74.125.21.103' },
|
||||
// processors: [{
|
||||
// processor_id: 'processor1',
|
||||
// type_id: 'geoip',
|
||||
// source_field: 42,
|
||||
// target_field: 'geoip'
|
||||
// }]
|
||||
// })
|
||||
// .expect(400)
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// bdd.it('should return 200 for a valid simulate request', () => {
|
||||
// return request.post('/kibana/ingest/simulate')
|
||||
// .send(testPipeline)
|
||||
// .expect(200);
|
||||
// });
|
||||
|
||||
// bdd.it('should return a simulated output with the correct result for the given processor', () => {
|
||||
// return request.post('/kibana/ingest/simulate')
|
||||
// .send(testPipeline)
|
||||
// .expect(200)
|
||||
// .then(function (response) {
|
||||
// expect(response.body[0].output.geoip.city_name).to.be('Mountain View');
|
||||
// });
|
||||
// });
|
||||
|
||||
// bdd.it('should enforce snake case', () => {
|
||||
// return request.post('/kibana/ingest/simulate')
|
||||
// .send({
|
||||
// processors: [{
|
||||
// processorId: 'processor1',
|
||||
// typeId: 'geoip',
|
||||
// sourceField: 'ip',
|
||||
// targetField: 'geoip'
|
||||
// }],
|
||||
// input: { ip: '74.125.21.103' }
|
||||
// })
|
||||
// .expect(400);
|
||||
// });
|
||||
|
||||
});
|
||||
};
|
||||
});
|
|
@ -2,6 +2,7 @@ define(function (require) {
|
|||
var append = require('./_append');
|
||||
var convert = require('./_convert');
|
||||
var date = require('./_date');
|
||||
var geoip = require('./_geoip');
|
||||
var gsub = require('./_gsub');
|
||||
var set = require('./_set');
|
||||
|
||||
|
@ -9,6 +10,7 @@ define(function (require) {
|
|||
append(bdd, scenarioManager, request);
|
||||
convert(bdd, scenarioManager, request);
|
||||
date(bdd, scenarioManager, request);
|
||||
geoip(bdd, scenarioManager, request);
|
||||
gsub(bdd, scenarioManager, request);
|
||||
set(bdd, scenarioManager, request);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue