Kibana 5.5 is out, and there is a nice new visualizer that lets you colorise a full country depending on the value of the record. It is really interesting for me as I developed such a plugin because I required the exact same functionality here.

That’s sound good but it is not that easy. If you don’t configure anything, nothing will be displayed on the dashboard. Of course, it will probably work if you subscribe to the Elastic Cloud service, but I am more interested in a free version. So what should we do:

1 Find a geo json file

This one is not too difficult. I generated one using the following web site. You end up with a json file. The next part of the story is that this json file must be hosted on a  web server that has the following characteristics:

  • It uses https
  • It is CORS enabled
  • It accepts the kbn-version Access Control Header

Forget the idea to store the file on github or wordpress, you need to modify the way the web server is handling the requests.

The easiest way to go is probably to use nginx. I used the following configuration:

server {
    listen 8080;

    ssl_certificate /etc/nginx/conf.d/server.crt;
    ssl_certificate_key /etc/nginx/conf.d/server.key;
    ssl on;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;


    root /usr/share/nginx/html;

    location / {
     if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';        
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';        
        add_header 'Access-Control-Allow-Headers' 'kbn-version,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        add_header 'Access-Control-Allow-Headers' 'Authorization';
        add_header 'Access-Control-Allow-Credentials' 'true';
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'kbn-version,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'kbn-version,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
    }
}

This server fulfills all the above requirements. The server.crt and server.key files can be generated using the instruction given in this post.

2 Optionally, build a container to deploy the web site

The nginx container can be built using a Dockerfile as shown below:

FROM nginx

RUN rm /etc/nginx/conf.d/default.conf

COPY content /usr/share/nginx/html
COPY conf /etc/nginx
COPY cert /etc/nginx/conf.d

Where:

  • The content folder includes the geo json file
  • The conf folder includes the nginx configuration file
  • The cert folders includes the server.key and server.crt files

3 Configure Kibana in order to use the geo json file

 

regionmap:
  layers:
     - name: "My wonderful map"
       url: "https://myexternaliporname:8080/world.geo.json"
       attribution: "My wonderful map provider"
       fields:
          - name: "iso_a2"
            description: "Two letters Country Name"
          - name: "iso_a3"
            description: "Three letters Country Name"

And there you are…