0

Ich versuche, index meine json Datei wie unten zu machen. Ich muss einen groben Ausdruck schreiben. Aber ich konnte das nicht tun? kannst du mir helfen?Wie kann ich Index-JSON-Datei mit Logstash machen?

{"level":"Information","ClientIP":"10.201.21.188","Test":"10.210.21.188"} 
 
{"level":"Information","ClientIP":"10.202.21.187","Test":"10.220.21.188"} 
 
{"level":"Information","ClientIP":"10.203.21.186","Test":"10.230.21.188"} 
 
{"level":"Information","ClientIP":"10.204.21.185","Test":"10.240.21.188"}

Mein logstash.conf ist unten:

input { 
 
    file { 
 
    type => "json" 
 
    path => ["C:/logs/test-20170933.json"] 
 
    start_position => "beginning" 
 
    } 
 
} 
 
filter { 
 
    grok { 
 
     match => [ "message","%{WORD:level} I HAVE TO WRITE OTHER ELEMENTS BUT HOW????"] 
 
    } 
 
    json { 
 
      source => "message" 
 
     } 
 
} 
 
output { 
 
\t stdout { 
 
    codec => rubydebug 
 
    } 
 
    elasticsearch { 
 
     hosts => [ "localhost:9200" ] 
 
     index => "logstash-%{+YYYY.MM.dd}" 
 
    } 
 
}

Ich denke, dass wir ein Ausdruck, die achive brauchen grok. Auch ich bin offen für neue kreative Lösung dafür.

Antwort

2

Sie brauchen nichts grok, Ihre file Eingang muss einfach einen JSON-Codec und du bist gut zu gehen:

input { 
    file { 
    type => "json" 
    path => ["C:/logs/test-20170933.json"] 
    start_position => "beginning" 
    codec => "json"     <-- add this 
    } 
} 
filter { 
} 
output { 
    stdout { 
     codec => rubydebug 
    } 
    elasticsearch { 
     hosts => [ "localhost:9200" ] 
     index => "logstash-%{+YYYY.MM.dd}" 
    } 
}