EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/
顯示具有 Kibana 標籤的文章。 顯示所有文章
顯示具有 Kibana 標籤的文章。 顯示所有文章

elk oss kibana error docker



 {"type":"log","@timestamp":"2019-01-21T08:57:51Z","tags":["status","plugin:elasticsearch@6.5.2","error"],"pid":1,"state":"red","message":"Status changed from yellow to red - Request Timeout after 3000ms","prevState":"yellow","prevMsg":"Waiting for Elasticsearch"}

1. First use oss
FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.5.2
FROM docker.elastic.co/kibana/kibana-oss:6.5.2

So Not X-pack problem

2. Truly Problem is connect to elasticsearch failed
Even login kibana docker then ping elasticsearch docker that get response. But kibana logs always get this error message.
kibana website message "Kibana server is not ready yet"

Try to get docker elasticsearch ip, change docker kibana.yml like example:


#elasticsearch.url: http://elasticsearch:9200
elasticsearch.url: http://172.19.0.2:9200


docker-compose up --build  # sure image rebuild

elk kibana search geth ethereum

https://blog.csdn.net/qq_38486203/article/details/80817037

Search minedNumber

GET /filebeat-6.*-geth*/_search?q=geth_ip:xxx.xxx.xxx.xxx
{
  "_source": ["name", "minedNumber", "gethdate"],
  "sort": [
    {
      "gethdate": {
        "order": "desc"
      }
    }
  ],
  "from": 1,
  "size": 1
}



Get minedNumber

curl -XGET "http://xxx.xxx.xxx.xxx:9200/filebeat-6.*-geth*/_search?q=geth_ip:xxx.xxx.xxx.xxx" -H 'Content-Type: application/json' -d'
{
  "_source": ["name", "minedNumber", "gethdate"],
  "sort": [
    {
      "gethdate": {
        "order": "desc"
      }
    }
  ],
  "from": 1,
  "size": 1
}' |  jq ".hits.hits[]._source.minedNumber"

kibana geo_point How to Part 6


Kibana Dev Tools


GET _cat
GET _cat/indices?v
GET _cat/indices?v&s=index
GET _cat/segments?v

GET /_settings
GET /_stats
GET /_template
GET _cluster/health

GET filebeat-6.5.1-2019.01.01
POST filebeat-6.5.1-2019.01.01 
PUT filebeat-6.5.1-2019.01.01 
DELETE filebeat-6.5.1-2019.01.01 

GET filebeat-6.5.1-2019.01.*
POST filebeat-6.5.1-2019.01.*
PUT filebeat-6.5.1-2019.01.* 
DELETE filebeat-6.5.1-2019.01.*

GET filebeat-6.5.1-2019.01.01/_stats
GET filebeat-6.5.1-2019.01.01/_mapping

POST /_refresh
POST /_cache/clear
POST /_flush/synced

?v

show column name


Segments Merge

https://my.oschina.net/fufangchun/blog/1541156
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html#forcemerge-multi-index


GET _cat/segments?v

POST /filebeat-6.5.1-2019.01.01/_forcemerge?max_num_segments=1&flush=true



https://my.oschina.net/weiweiblog/blog/2989931

ethereum-etl ethereumetl elk logstash kibana part2



filter {
  if [etltype] == "blocks" { #[fields][srctype]
    csv {
      columns => [
        "number", "hash",  "parent_hash",  "nonce",  "sha3_uncles",  "logs_bloom",  "transactions_root",
        "state_root",  "receipts_root",  "miner",  "difficulty",  "total_difficulty",  "size",  "extra_data",
        "gas_limit",  "gas_used",  "timestamp",  "transaction_count"
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "contracts" { #[fields][srctype]
    csv {
      columns => [
        "address",  "bytecode",  "function_sighashes",  "is_erc20",  "is_erc721"
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "logs" { #[fields][srctype]
    csv {
      columns => [
        "log_index",  "transaction_hash",  "transaction_index",  "block_hash",  "block_number",  
        "address",  "data", "topics"
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "receipts" { #[fields][srctype]
    csv {
      columns => [
        "transaction_hash",  "transaction_index",  "block_hash",  "block_number",  "cumulative_gas_used",  
        "gas_used",  "contract_address",  "root",  "status"
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "token_transfers" { #[fields][srctype]
    csv {
      columns => [
        ""
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "tokens" { #[fields][srctype]
    csv {
      columns => [
        ""
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }else if [etltype] == "transactions" { #[fields][srctype]
    csv {
      columns => [
        "hash",  "nonce",  "block_hash",  "block_number",  "transaction_index",  "from_address",  
        "to_address",  "value",  "gas",  "gas_price",  "inputcontext"
      ]
      separator => ","
      remove_field => ["message"]
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }
}

output {
  if [etltype] == "blocks" {
    elasticsearch {
      hosts => "xxx.xxx.xxx.xxx:9200"
      manage_template => false
      index => "%{[@metadata][beat]}-%{[@metadata][version]}-blocks-%{+YYYY.MM.dd}"
      document_id => "%{[hash]}"
    }
  }else if [etltype] == "logs" {
    elasticsearch {
      hosts => "xxx.xxx.xxx.xxx:9200"
      manage_template => false
      index => "%{[@metadata][beat]}-%{[@metadata][version]}-logs-%{+YYYY.MM.dd}"
    }
  }else if [etltype] == "transactions" {
    elasticsearch {
      hosts => "xxx.xxx.xxx.xxx:9200"
      manage_template => false
      index => "%{[@metadata][beat]}-%{[@metadata][version]}-transactions-%{+YYYY.MM.dd}"
      document_id => "%{[hash]}"
    }
  }else if [etltype] == "contracts" {
    elasticsearch {
      hosts => "xxx.xxx.xxx.xxx:9200"
      manage_template => false
      index => "%{[@metadata][beat]}-%{[@metadata][version]}-contracts-%{+YYYY.MM.dd}"
      document_id => "%{[address]}"
    }
  }else{
  
    elasticsearch {
      hosts => "xxx.xxx.xxx.xxx:9200"
      manage_template => false
      index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    }
  }

 stdout { codec => rubydebug }
}



transactions csv fileds are

hash,nonce,block_hash,block_number,transaction_index,from_address,to_address,value,gas,gas_price,input

input

must change to other name like

inputcontext


like this:

hash,nonce,block_hash,block_number,transaction_index,from_address,to_address,value,gas,gas_price,inputcontext

Fxxxx No change name can't import success, even logstash get correct. But this bug sometime use new docker-compose ELK can import success. So just change name more easy.

===============================

Error No Use

if [etltype] in ["blocks"] 

Correct

if [etltype] == "blocks"


Only more then two args

if [etltype] in ["blocks", "transactions" ...]  
This is ok

[轉]ELK:kibana使用的lucene查询语法

https://segmentfault.com/a/1190000002972420


通配符
? 匹配单个字符
* 匹配0到多个字符

kiba?a, el*search

? * 不能用作第一个字符,例如:?text *text


====================


正则
es支持部分正则功能,性能较差
name:/joh?n(ath[oa]n)/


====================


模糊搜索
quikc~ brwn~ foks~
~:在一个单词后面加上~启用模糊搜索,可以搜到一些拼写错误的单词

first~ 这种也能匹配到 frist

还可以设置编辑距离(整数),指定需要多少相似度
cromm~1 会匹配到 from 和 chrome
默认2,越大越接近搜索的原始值,设置为1基本能搜到80%拼写错误的单词


====================


逻辑操作
AND
OR

+:搜索结果中必须包含此项
-:不能含有此项
+apache -jakarta test aaa bbb:结果中必须存在apache,不能有jakarta,剩余部分尽量都匹配到


====================


分组
(jakarta OR apache) AND jakarta



====================



转义特殊字符
+ - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /
以上字符当作值搜索的时候需要用\转义
\(1\+1\)\=2用来查询(1+1)=2


====================

ethereum-etl ethereumetl elk logstash kibana


all output columns with logstash



filter {
  if [srctype] == "etl" { #[fields][srctype]
    csv {
      columns => [
        "number", "hash",  "parent_hash",  "nonce",  "sha3_uncles",  "logs_bloom",  "transactions_root",
        "state_root",  "receipts_root",  "timestamp",  "extra_data",  "transaction_count",  "gas_limit",
        "size",  "total_difficulty",  "difficulty",  "miner",  "block_hash",  "block_number",
        "transaction_index",  "from_address",  "to_address",  "value",  "gas",  "gas_price",  "input",
        "address",  "bytecode",  "function_sighashes",  "is_erc20",  "is_erc721",  "log_index",
        "transaction_hash",  "data",  "topics",  "cumulative_gas_used",  "gas_used",  "contract_address",
        "root,status"
      ]
      separator => ","
      remove_field => ["message"]
      #autodetect_column_names => true   #have problems
      #autogenerate_column_names => true #have problems
      skip_empty_columns => true
      skip_empty_rows => true
    }
  }

kibana geo_point How to Part 5


Oragin

  geoip {
    source => "filebeatserverip"
    target => "filebeatserveripgeoip"
    add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][longitude]}" ]
    add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][latitude]}" ]
  }

  mutate {
    convert => ["[filebeatserveripgeoip][coordinates]", "float"]
  }

Delete

add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][longitude]}" ]
add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][latitude]}" ]

convert => ["[filebeatserveripgeoip][coordinates]", "float"]


  geoip {
    source => "filebeatserverip"
    target => "filebeatserveripgeoip"
  }

  mutate {
  }

=====


{
  "index_patterns": ["filebeat*", "heartbeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "filebeatserveripgeoip.coordinates": {
          "type": "geo_point"
        }
      }
    }
  }
  
}

Change filebeatserveripgeoip.coordinates -> filebeatserveripgeoip.location


{
  "index_patterns": ["filebeat*", "heartbeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "filebeatserveripgeoip.location": {
          "type": "geo_point"
        }
      }
    }
  }
  
}

template_filebeat.json

curl -v -XPUT elasticsearch:9200/_template/template_filebeat -H 'Content-Type: application/json' -d @/usr/share/config/template_filebeat.json


curl -v -XPUT elasticsearch:9200/_template/template_filebeat -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["filebeat*", "heartbeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "filebeatserveripgeoip.location": {
          "type": "geo_point"
        }
      }
    }
  }
  
}'

location be created by geoip plugin.


MAX Import


GET _cat/indices?v
GET _cat/indices?v&s=index

GET filebeat-6.5.1-2018.12.06

DELETE filebeat-6.5.1-2018.12.06

GET _cat/indices?v

GET filebeat-6.5.1-2018.12.06

AND

refresh chrome (brwoser)

geth log No Year

geth log mined

INFO [12-07|13:04:44] 🔨 mined potential block number=1934700 hash=3f9161…88da7d

only month-day .......



  grok {
    match => ["message", "%{LOGLEVEL:logType} \[%{DATA:gethmm}-%{DATA:gethdd}\|%{DATA:gethtime}\] %{GREEDYDATA:tmessage} number=(?\b\w+\b) hash=(?\b\w+...\w+\b)"]
    add_field => ["gethdate", "%{[gethmm]}-%{[gethdd]} %{[gethtime]}"]
  }

  ruby {
    code => 
      " tstamp = event.get('@timestamp').to_i
        event.set('epoch',tstamp)
        event.set('gethdate', Time.at(tstamp).strftime('%Y')+'-'+event.get('gethdate'))
      "
  }

  date {
    match => [ "gethdate" , "YYYY-MM-dd HH:mm:ss"]
    target => "gethdate"
    timezone => "Asia/Taipei"
  }


Recreate index

GET _cat/indices?v
GET _cat/indices?v&s=index

GET filebeat-6.5.1-2018.12.06

DELETE filebeat-6.5.1-2018.12.06

GET _cat/indices?v

GET filebeat-6.5.1-2018.12.06


If index rebuild, Kibana DISCOVER table will be see.

Kibana export index-pattern visualization import

Export

index-pattern

curl http://xxx.xxx.xxx.xxx:5601/api/saved_objects/index-pattern/f1836c20-e880-11e8-8d66-7d7b4c3a5906 > index-pattern-export.json


visualization

curl http://xxx.xxx.xxx.xxx:5601/api/saved_objects/visualization/1eb85311-f901-11e8-864c-bd4880954537 > visual-export.json



Import


index-pattern

curl -v -XPOST kibana:5601/api/kibana/dashboards/import?force=true -H "kbn-xsrf:true" -H "Content-type:application/json" -d @/usr/share/config/config/index-pattern-export.json

visualization

curl -v -XPOST kibana:5601/api/kibana/dashboards/import?force=true -H "kbn-xsrf:true" -H "Content-type:application/json" -d @/usr/share/config/config/visual-export.json


PS:

visualization can be multi

{
"objects": [
{"id":"0c298010-f901-11e8-864c-bd4880954537",...},
{"id":"1eb85300-f901-11e8-864c-bd4880954537",...}
]}

kibana geo_point How to Part 4

1. Change logstash add fields or grok some fields. Kibana DISCOVER Table can see new fields & !

2. Kibana Management -> Index Patterns can "Fefresh field list"   ! will be disappear.

3. Logstash set some fields Type "geo_point". see Kibana DISCOVER Table field Type still "TEXT". Try to delete index.

GET _cat/indices?v
GET _cat/indices?v&s=index

GET filebeat-6.5.1-2018.12.06

DELETE filebeat-6.5.1-2018.12.06

After DELETE index (real index), index rebuiled. Geo_point usually can see.


4. Every things sure is ok, export index-pattern.json
https://sueboy.blogspot.com/2018/11/kibana-default-index-pattern.html

==========
Mutil geo_ip

logstash


  geoip {
    source => "filebeatserverip"
    target => "filebeatserveripgeoip"
    add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][longitude]}" ]
    add_field => [ "[filebeatserveripgeoip][coordinates]", "%{[filebeatserveripgeoip][latitude]}" ]
  }

  mutate {
    convert => ["[filebeatserveripgeoip][coordinates]", "float"]
  }


filebeatserverip:filebeat server ip

/etc/filebeat.yml


- type: log
  paths:
    - /var/log/*.log
  exclude_files: ['.gz$']
  tags: ["xxx.xxx.xxx.xxx"]
  fields:
    filebeatserverip: "xxx.xxx.xxx.xxx"
  fields_under_root: true

xxx.xxx.xxx.xxx put server ip, then logstash can get "filebeatserverip" field


filebeatserveripgeoip: usually demo is geoip. Some log have src_ip dest_ip client_ip...etc


template_filebeat (template_filebeat.json)


{
  "index_patterns": ["filebeat*", "heartbeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "geoip.location": {
          "type": "geo_point"
        },
        "geoip.coordinates": {
          "type": "geo_point"
        },
        "filebeatserveripgeoip.coordinates": {
          "type": "geo_point"
        }
      }
    }
  }
  
}

send template_filebeat.json to elasticseart

curl -v -XPUT elasticsearch:9200/_template/template_filebeat -H 'Content-Type: application/json' -d @/usr/share/config/template_filebeat.json

Then

GET _cat/indices?v

GET filebeat-6.5.1-2018.12.06

DELETE filebeat-6.5.1-2018.12.06

GET _cat/indices?v

GET filebeat-6.5.1-2018.12.06


If index rebuild, Kibana DISCOVER table will be see.

kibana geo_point How to Part 3

Now check again....


1、template_filebeat.json

Can only


{
  "index_patterns": ["filebeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
  "doc": {
   "properties": {
    "geoip.location": {
     "type": "geo_point"
        },
    "geoip.coordinates": {
     "type": "geo_point"
        }
   }
  }
 }
  
}


Here Import"location" is Error, Must "geoip.location"

But sometime why no use, because my way insert index-pattern, so geoip.location no field, always is
geoip.location.lat  and geoip.location.lon overwrtie.

see 2.

2、index-pattern  index-pattern-export.json

one way just try to put

{\"name\":\"geoip.location\",\"type\":\"geo_point\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}

and remove geoip.location.lat  and geoip.location.lon .


When put template, index in kibana index Patterns delete is NO Use. Must delete in Dev Tools

DELETE filebeat-6.4.2-2018.11.19

GET _cat/indices?v
GET _cat/indices?v&s=index

check exist or not. Then import data again, index recreate, then apply template.








elk ingest plugs pipeline


Filebeat + Elasticsearch + Kibana 轻量日志收集与展示系统

https://wzyboy.im/post/1111.html?utm_source=tuicool&utm_medium=referral



提到

beat -> logstash -> elk

可以

beat -> elk ingest plugs (  Elasticsearch Ingest Node )


Elasticsearch Ingest Node 是 Elasticsearch 5.0 起新增的功能。在 Ingest Node 出现之前,人们通常会在 ES 前置一个 Logstash Indexer,用于对数据进行预处理。有了 Ingest Node 之后,Logstash Indexer 的大部分功能就可以被它替代了,grok, geoip 等 Logstash 用户所熟悉的处理器,在 Ingest Node 里也有。对于数据量较小的 ES 用户来说,省掉一台 Logstash 的开销自然是令人开心的,对于数据量较大的 ES 用户来说,Ingest Node 和 Master Node, Data Node 一样也是可以分配独立节点并横向扩展的,也不用担心性能瓶颈。

目前 Ingest Node 已支持数十种处理器,其中的 script 处理器具有最大的灵活性。

与 /_template 类似,Ingest API 位于 /_ingest 下面。用户将 pipeline 定义提交之后,在 Beats 中即可指定某 pipeline 为数据预处理器。





FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.4.2

已經內建了
https://www.elastic.co/guide/en/elasticsearch/plugins/6.5/ingest-geoip.html
https://www.elastic.co/guide/en/elasticsearch/plugins/6.5/ingest-user-agent.html





===============

.filebeat

filebeat.yml

補上 like example


output.elasticsearch:

  hosts: ["http://localhost:9200/"]

  pipelines:
    - pipeline: nginx.access
      when.equals:
        fields.type: nginx.access
    - pipeline: nginx.error
      when.equals:
        fields.type: nginx.error

OK, use bottom way to make pipeline.


.pipeline

https://www.elastic.co/guide/en/elasticsearch/reference/current/simulate-pipeline-api.html
https://qbox.io/blog/indexing-elastic-stack-5-0-ingest-apis
https://dev.classmethod.jp/server-side/elasticsearch/elasticsearch-ingest-node/
https://qbox.io/blog/how-to-index-geographical-location-of-ip-addresses-to-elasticsearch-5-0-1

Get a pipeline

GET _ingest/pipeline/geoippipeline


write a pipeline

PUT _ingest/pipeline/geoippipeline
{
  "description" : "Add geoip information to the given IP address",
  "processors": [
    {
      "geoip" :  {
        "field" : "ip",
        "ignore_missing": true
      }
    },
    {
      "geoip" :  {
        "field" : "src_ip",
        "ignore_missing": true
      }
    },
    {
      "geoip" :  {
        "field" : "clientip",
        "ignore_missing": true
      }
    },
    {
      "set" : {
        "field" : "location",
        "value" : "{{geoip.location.lon}}, {{geoip.location.lat}}"
      }
    }
  ]
}


real use pipeline with test data, check is ok.

POST _ingest/pipeline/geoippipeline/_simulate
{
  "docs":[
    {
      "_source": {
        "ip": "8.8.0.0",
        "src_ip": "8.8.0.0",
        "clientip": "8.8.0.0"
      }
    }
  ]
}



Developer test


POST _ingest/pipeline/_simulate
{
  "pipeline": {
  "description" : "parse multiple patterns",
  "processors": [
    {
      "geoip" :  {
        "field" : "ip",
        "ignore_missing": true
      }
    },
    {
      "geoip" :  {
        "field" : "src_ip",
        "ignore_missing": true
      }
    },
    {
      "geoip" :  {
        "field" : "clientip",
        "ignore_missing": true
      }
    },
    {
      "set" : {
        "field" : "location",
        "value" : "{{geoip.location.lon}}, {{geoip.location.lat}}"
      }
    }
  ]
},
"docs":[
  {
    "_source": {
      "ip": "8.8.0.0",
      "src_ip": "8.8.0.0",
      "clientip": "8.8.0.0"
    }
  }
  ]
}






logstash kibana ssh log

1、filebeat    /var/log/secure

2、



filter {
  grok {
    #type => "syslog"
    match => ["message", "%{SYSLOGBASE} Failed password for (invalid user |)%{USERNAME:username} from %{IP:src_ip} port %{BASE10NUM:port} ssh2"]
    add_tag => "ssh_brute_force_attack"
  }
  grok {
    #type => "syslog"
    match => ["message", "%{SYSLOGBASE} Accepted password for %{USERNAME:username} from %{IP:src_ip} port %{BASE10NUM:port} ssh2"]
    add_tag => "ssh_sucessful_login"
  }

  geoip {
    source => "src_ip"
    target => "geoip"
    add_tag => [ "ssh-geoip" ]
    add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
    add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]
    add_field => [ "geoipflag", "true" ]
  }

}

kibana geo_point How to Part 2

Step:

.Change Kibana & elk order.  Now elk import template_filebeat, then wait logstash put log to elk. elk can get index EX:filebeat-6.4.2-2018.11.19 filebeat-6.4.2-2018.11.20
Then kibana import index-partten and set default.



#!/bin/bash

echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
apk --no-cache upgrade
apk --no-cache add curl

echo "=====Elk config ========"
until echo | nc -z -v elasticsearch 9200; do
    echo "Waiting Elk Kibana to start..."
    sleep 2
done

code="400"
until [ "$code" != "400" ]; do
    echo "=====Elk importing mappings json ======="
    curl -v -XPUT elasticsearch:9200/_template/template_filebeat -H 'Content-Type: application/json' -d @/usr/share/elkconfig/config/template_filebeat.json 2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
    code=`cat code.txt`
    sleep 2
done


#reload index for geo_point
echo "=====Get kibana idnex lists ======="
indexlists=()
while [ ${#indexlists[@]} -eq 0 ]
do
    sleep 2
    indexlists=($(curl -s elasticsearch:9200/_aliases?pretty=true | awk -F\" '!/aliases/ && $2 != "" {print $2}' | grep filebeat-))
done

sleep 10


#========kibana=========
id="f1836c20-e880-11e8-8d66-7d7b4c3a5906"

echo "=====Kibana default index-pattern ========"
until echo | nc -z -v kibana 5601; do
    echo "Waiting for Kibana to start..."
    sleep 2
done

code="400"
until [ "$code" != "400" ]; do
    echo "=====kibana importing json ======="
    curl -v -XPOST kibana:5601/api/kibana/dashboards/import?force=true -H "kbn-xsrf:true" -H "Content-type:application/json" -d @/usr/share/elkconfig/config/index-pattern-export.json 2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
    code=`cat code.txt`
    sleep 2
done

code="400"
until [ "$code" != "400" ]; do
    curl -v -XPOST kibana:5601/api/kibana/settings/defaultIndex -H "kbn-xsrf:true"  -H "Content-Type: application/json" -d "{\"value\": \"$id\"}"  2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
    code=`cat code.txt`
    sleep 2
done

tail -f /dev/null




template_filebeat template_filebeat.json

* template_filebeat.json  is from

GET _cat/indices?v
you can see some index like //GET _cat/indices?v&s=index



GET filebeat-6.4.2-2018.11.19



ok use your mappings replace this mappings




{
  "index_patterns": ["filebeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },

  ...

}


Only replace mappings. Official website have example.
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

And  Change

"coordinates": {
"type": "float"  => "geo_point"
},
Save file name:template_filebeat.json  

Usually new docker elk logstash already have geoip. add_field like picture and mutate add some item. Here is change type with templates.



So this step mean you must let logstash send log to elk, get fileds to become template.



index-partten index-pattern-export.json

see this url, know how to do
https://sueboy.blogspot.com/2018/11/kibana-default-index-pattern.html

Important:Do this must refresh, then export json that is corrent file.




Now 100% can see map.

[Failed again!!] kibana geo_point How to

Fxxx kibana elk  Now try to do again. But can't get geo_point....
reindex no use

No Use
POST /_refresh
POST /_flush/synced
POST /_cache/clear

Only do this can apply


Wast time Fxxx system.
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................
..................

very bad document, very bad change version............Everythings is BAD for elk kibana



1、 Every time see this "PUT GET or DELETE" command. Use  where ???
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html


Use in Kibana 



AND Question is curl 




2、Please Watch 6.5   Not old version


You maybe see many document on Internet that check version First.



3、Before geo_point

keep this command : (or find Internet know this mean)

GET _cat/
GET _cat/indices?v
GET _cat/indices?v&s=index

GET /_settings

GET filebeat*

GET /_template

PUT _template/template_filebeat

POST _reindex


=================Begin================

Firest Must already have  default index




If want to auto, see  http://sueboy.blogspot.com/2018/11/kibana-default-index-pattern.html


Second



#!/bin/bash

echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
apk --no-cache upgrade
apk --no-cache add curl

echo "=====Elk config ========"
until echo | nc -z -v elasticsearch 9200; do
    echo "Waiting Elk Kibana to start..."
    sleep 2
done

code="400"
until [ "$code" != "400" ]; do
    echo "=====Elk importing mappings json ======="
    curl -v -XPUT elasticsearch:9200/_template/template_filebeat -H 'Content-Type: application/json' -d @/usr/share/elkconfig/config/template_filebeat.json 2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
    code=`cat code.txt`
    sleep 2
done

#reload index for geo_point
echo "=====Get kibana idnex lists ======="
indexlists=()
while [ ${#indexlists[@]} -eq 0 ]
do
    sleep 2
    indexlists=($(curl -s elasticsearch:9200/_aliases?pretty=true | awk -F\" '!/aliases/ && $2 != "" {print $2}' | grep filebeat-))
done

for i in "${indexlists[@]}"
do
    echo "=====reindex filebeat for geo_point ======="
    curl -v -XPOST "http://elasticsearch:9200/_reindex" -H 'Content-Type: application/json' -d'{ "source": { "index": "'$i'" }, "dest": { "index": "'$i-reindex'" } }'
done
    
#curl -XDELETE "http://elasticsearch:9200/filebeat-*"
#curl -XPUT "http://elasticsearch:9200/filebeat"

tail -f /dev/null




* template_filebeat.json  is from

GET _cat/indices?v
you can see some index like



GET filebeat-6.4.2-2018.11.19



ok use your mappings replace this mappings




{
  "index_patterns": ["filebeat*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },

  ...

}


Only replace mappings. Official website have example.
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

And  Change

"coordinates": {
"type": "float"  => "geo_point"
},
Save file name:template_filebeat.json  

Usually new docker elk logstash already have geoip. add_field like picture and mutate add some item. Here is change type with templates.



Back shell, move to  =====Get kibana idnex lists=====

This is get use indexlist now after used late.

Then reindex


Why do this Because reindex let  geo_point  remake.  Already inside index. corrdinates type is float.




If you want to change type, usually get error or maybe success, success is fake.





So only use reindex, let it can do.
https://medium.com/@sami.jan/fundamentals-of-elasticsearch-cbb273160f60


I think use docker elk logstash kibana that want to use quickly. Setting config must set default. Change config only use docker image offer. So docker image No offer and don't change docker image, only use API. But API not everything same use config.

All step

1、elk put template for geo_point

"coordinates": {
   "type": "geo_point"
},

2、get already used idnex

3、reindex  a -> a_reindex

4、Visualize ->  create a visualizaition -> Coordinate Map -> choese Filter  "filebeat-*"  Maybe your different name, by default index

-> Buckets -> Geo Coordinates -> Aggregation -> Geohash -> Field -> Geoip.coordinates  (geo_point)  -> RUN



Now 100% can see map.



logstash kibana geth log ethereum Grok Constructor

filter


json {
  source => "message"
}

This mean is Try to use json format transfer log, then put some data to message filed. So some filed just be setting, and some data set to message.


.Use this to check mach and log
https://grokconstructor.appspot.com/do/match
https://blog.johnwu.cc/article/elk-logstash-grok-filter.html
https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns


This is geth log for example

A:
INFO [11-14|09:58:17.730] Generating DAG in progress epoch=1 percentage=99 elapsed=4m8.643s
INFO [11-15|01:41:33.455] Generating DAG in progress               epoch=1 percentage=9  elapsed=27.614s

B:
INFO [11-15|01:19:44.590] Loaded most recent local fast block      number=0 hash=656134…58fded td=1 age=49y7mo1h, Loaded most recent local fast block

C:
INFO [11-15|02:09:27.980] 🔨 mined potential block number=119 hash=ebaa58…5d8fa1, 🔨 mined potential block



A:

INFO [11-14|09:58:17.730] Generating DAG in progress epoch=1 percentage=99 elapsed=4m8.643s
INFO [11-15|01:41:33.455] Generating DAG in progress               epoch=1 percentage=9  elapsed=27.614s


%{DATA:logType} %{DATA:MONTHDAY} %{GREEDYDATA:message}\s+epoch=(?<epoch>\b\w+\b) percentage=(?<percentage>\b\w+\b)\s+elapsed=(?<elapsed>\b\w+\b)





B:

INFO [11-15|01:19:44.590] Loaded most recent local fast block      number=0 hash=656134…58fded td=1 age=49y7mo1h, Loaded most recent local fast block  


%{DATA:logType} %{DATA:MONTHDAY} %{DATA:message} number=(?<minedNumber>\b\w+\b) hash=(?<minedHashr>\b\w+...\w+\b) td=(?<minedtd>\b\w+\b) age=(?<minedtd>\b\w+\b)%{DATA:message2}





C:

INFO [11-15|02:09:27.980] 🔨 mined potential block number=119 hash=ebaa58…5d8fa1, 🔨 mined potential block




OK~ C is best easy. No any other special. Only need to check is Space. log have Space, rule must have Space. And Space must same count. Have one Space in log, rule must Have Space.


B is Data same and tail how to do.

%{DATA:message}
%{DATA:message2}

let two "Loaded most recent local fast block" to DATA & message、message2


B have one thing is C Space must same. Here firest %{DATA:message} Data:Loaded most recent local fast block.....   This is all Space in message. So %{DATA:message} & number= have space or not, just to test check. Don't think too much.


A \s+ is different. This is for some data have space, but log look just same. So use this \s+ for have more space. Remeber \s+epoch=  no space rule, NOT \s+ epoch= .  Only little different. Just to test check. Don't think too much.




All Architecture is like this

docker-compose  & elk
https://sueboy.blogspot.com/2018/11/docker-compose-ethereum-geth-private.html

Change logstach pipline -> logstash.log





Now very clear.

So some different is add_field that is for check grok is work ok or not. If kibana have value = grok is work.

add_field marked filed just for test, can open then get double smae filed and value.

Grok can multiple.



kibana default index-pattern

先建立index-pattern,匯出index-pattern json檔,然後刪除建立index-pattern後,再由rest api匯入。

1、顯示 index-pattern 列表  (先用web建立一個index-pattern)

curl http://localhost:5601/api/saved_objects/_find?type=index-pattern


2、匯出saved_objects index-pattern

curl http://localhost:5601/api/saved_objects/index-pattern/c0c02200-e6e0-11e8-b183-ebb59b02f871 > export.json

c0c02200-e6e0-11e8-b183-ebb59b02f871 是 1找到的id

json檔匯出後不可以直接用,必需頭尾補上
header補上:

{
"objects": [


end補上:

]}


3、匯入saved_objects index-pattern  (記得先砍了kibana-*)

curl -v -XPOST localhost:5601/api/kibana/dashboards/import?force=true -H 'kbn-xsrf:true' -H 'Content-type:application/json' -d @./export.json

json放在執行curl 同目錄就可以了


4、強制設定預設值 Kibana -> Managment -> Advanced Settings  defaultIndex

curl -XPOST http://localhost:5601/api/kibana/settings/defaultIndex -H "kbn-xsrf: true" -H "Content-Type: application/json" -d '{"value": "id"}'

id from export.json inside have id value

If already open kibana website, use Fresh (F5) page again.



======docker-compose===============



Kibanaconfig:
    image: alpine
    volumes:
      - ./kibana/config/:/usr/share/kibana/config:ro
    command: 
      - /bin/sh 
      - -c 
      - |
        echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories
        echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
        echo '@edge http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
        apk --no-cache upgrade
        apk --no-cache add curl 
        id="c0c02200-e6e0-11e8-b183-ebb59b02f871"
        
        echo "=====Kibana default index-pattern ========"
        echo "=====Wait Kibana======="
        until echo | nc -z -v kibana 5601; do
          echo "Waiting for Kibana to start..."
          sleep 1
        done
        
        echo "=====kibana import json======"
        code=""
        until [ $$code != 400 ]; do
          echo "=====kibana importing json ======="
          curl -v -XPOST kibana:5601/api/kibana/dashboards/import?force=true -H "kbn-xsrf:true" -H "Content-type:application/json" -d @/usr/share/kibana/config/export.json 2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
          code=`cat code.txt`
          echo "=====status code:$$code====="
          sleep 3
        done

        echo "=====kibana setting default index-pattern====="
        code=""
        until [ $$code != 400 ]; do
          echo "=====kibana setting ==================================="
          curl -v -XPOST kibana:5601/api/kibana/settings/defaultIndex -H "kbn-xsrf:true"  -H "Content-Type: application/json" -d '{"value": "$$id"}'  2>/dev/null | head -n 1 | cut -d ':' -f2|cut -d ',' -f1 > code.txt
          code=`cat code.txt`
          echo "=====status code:$$code====="
          sleep 3
        done
    networks:
      - elk
    depends_on:
      - elasticsearch




ELK


elasticsearch:
    build:
      context: elasticsearch/
    volumes:
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - elk

  logstash:
    build:
      context: logstash/
    volumes:
      - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro
    ports:
      - "5000:5000"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - elk
    depends_on:
      - elasticsearch

  kibana:
    build:
      context: kibana/
    volumes:
      - ./kibana/config/:/usr/share/kibana/config:ro
    ports:
      - "5601:5601"
    networks:
      - elk
    depends_on:
      - elasticsearch

elk Elasticsearch Logstash and Kibana fortigate ubuntu

https://www.rosehosting.com/blog/install-and-configure-the-elk-stack-on-ubuntu-16-04/

https://www.elastic.co/guide/en/logstash/current/configuration.html

https://dotblogs.com.tw/supershowwei/2016/05/25/185741


install finish

1、/etc/logstash/conf.d/    put some logstash conf

2、ubuntu have logstash listen error, so nano /etc/logstash/startup.options
LS_USER = root

3、/usr/share/logstash/bin# ./system-install        reuse LS_USER for config


注意:

 mutate {
        add_field => {
            "logTime" => "%{+YYYY-MM-dd} %{time}"
        }