diff --git a/README.md b/README.md index 8a0a44a..b7b631b 100644 --- a/README.md +++ b/README.md @@ -210,11 +210,25 @@ Supported Databases: It supports any datasource capable of generating a JSON response with a a custom list of locations (the same format that for the JSON enpoint). +## Graylog Geolocation data as the Data Source + +Supported Databases: + +- ElasticSearch + +Graylog's Geolocation plugin stores the geolocation data as a string in the following format: "latitude,longitude" by default. + +Three fields need to be provided by the ElasticSearch query: + +- Location Name (optional - geohash value will be shown if not chosen) +- Geopoint field that provides the coordinates as a string in the following format: "latitude,longitude". +- A metric. This is free text and should match the aggregation used (Count, Average, Sum, Unique Count etc.) + ### Map Data Options #### Location Data -There are four ways to provide data for the worldmap panel: +There are seven ways to provide data for the worldmap panel: - *countries*: This is a list of all the countries in the world. It works by matching a country code (US, FR, AU) to a node alias in a time series query. - *states*: Similar to countries but for the states in USA e.g. CA for California @@ -222,6 +236,7 @@ There are four ways to provide data for the worldmap panel: - *json*: A json endpoint that returns custom json. Examples of the format are the [countries data used in first option](https://github.com/grafana/worldmap-panel/blob/master/src/data/countries.json) or [this list of cities](https://github.com/grafana/worldmap-panel/blob/master/src/data/probes.json). - *jsonp*: A jsonp endpoint that returns custom json wrapped as jsonp. Use this if you are having problems with CORS. - *table*: This expects the metric query to return data points with a field named geohash or two fields/columns named `latitude` and `longitude`. This field should contain a string in the [geohash form](https://www.elastic.co/guide/en/elasticsearch/guide/current/geohashes.html). For example: London -> "gcpvh3zgu992". + - *string*: An ElasticSearch query that returns the coordinates as a single string. #### Aggregation diff --git a/src/data_formatter.ts b/src/data_formatter.ts index 13121f0..9cfef72 100644 --- a/src/data_formatter.ts +++ b/src/data_formatter.ts @@ -239,4 +239,58 @@ export default class DataFormatter { data.valueRange = highestValue - lowestValue; } } + + setStringValues(dataList, data) { + if (!this.ctrl.panel.esGeoPoint || !this.ctrl.panel.esMetric) { + return; + } + + if (dataList && dataList.length > 0) { + let highestValue = 0; + let lowestValue = Number.MAX_VALUE; + + dataList.forEach(result => { + if (result.type === 'table') { + const columnNames = {}; + + result.columns.forEach((column, columnIndex) => { + columnNames[column.text] = columnIndex; + }); + + result.rows.forEach(row => { + const coordinatesField = row[columnNames[this.ctrl.panel.esGeoPoint]]; + const geoPoint = coordinatesField.split(','); + const latitude = geoPoint[0]; + const longitude = geoPoint[1]; + const value = row[columnNames[this.ctrl.panel.esMetric]]; + const locationName = this.ctrl.panel.esLocationName + ? row[columnNames[this.ctrl.panel.esLocationName]] + : latitude + ', ' + longitude; + + const dataValue = { + key: geoPoint, + locationName: locationName, + locationLatitude: latitude, + locationLongitude: longitude, + value: value, + valueFormatted: value, + valueRounded: 0, + }; + if (dataValue.value > highestValue) { + highestValue = dataValue.value; + } + if (dataValue.value < lowestValue) { + lowestValue = dataValue.value; + } + dataValue.valueRounded = kbn.roundValue(dataValue.value, this.ctrl.panel.decimals || 0); + data.push(dataValue); + }); + + data.highestValue = highestValue; + data.lowestValue = lowestValue; + data.valueRange = highestValue - lowestValue; + } + }); + } + } } diff --git a/src/partials/editor.html b/src/partials/editor.html index 63c474e..5c28b48 100644 --- a/src/partials/editor.html +++ b/src/partials/editor.html @@ -52,11 +52,11 @@
The query should be an Elasticsearch query. The "Group by" term should match the field that contains the coordinates.
+