EExcel 丞燕快速查詢2

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

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 filebeat logstash FXXX

Use filebeat nginx module send nginx log to logstash or driect to elastick all get error!!

BUT some nginx log record can send success. That success records try to copy to other VM that have filebeat and logstash, try to send again. all get error!!



[轉]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
    }
  }

logstash fileds if



https://sueboy.blogspot.com/2018/11/elk60filebeatdocumenttype.html


filebeat.yml


- type: log
  paths:
    - /var/log/geth.log
  exclude_files: ['.gz$']

  fields:
    srctype: "geth"



pipleline logstah.conf

if [fields][srctype] == "geth" {


BUT fields_under_root: true 


- type: log
  paths:
    - /var/log/geth.log
  exclude_files: ['.gz$']

  fields:
    srctype: "geth"
  fields_under_root: true

if [srctype] == "geth" {

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" ]
  }

}

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.



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}"
        }