Skip to content

Instantly share code, notes, and snippets.

@ShawInnes
Last active August 29, 2015 14:16
Show Gist options
  • Save ShawInnes/16a8c67548ebc1e0a400 to your computer and use it in GitHub Desktop.
Save ShawInnes/16a8c67548ebc1e0a400 to your computer and use it in GitHub Desktop.
logstash api importer
.DS_Store
data/
input {
file {
path => "/Users/shaw/apilogs/data/API-*/*.log"
tags => [ "api" ]
start_position => "beginning"
}
}
filter{
if [message] =~ "^#" {
drop {}
}
grok {
match => ["path", "data/(?<log_host>[^/]+)/(?<log_file>.*).log"]
}
grok {
match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{IPORHOST:ip} %{WORD:method} %{URIPATH:uri} %{NOTSPACE:username} %{IPORHOST:cip} %{NOTSPACE:httpversion} %{NOTSPACE:useragent} %{NOTSPACE:cookie} %{NOTSPACE:referer} (%{URIHOST:chost}|%{NOTSPACE:chost}) %{INT:scstatus} %{INT:scsubstatus} %{INT:scbytes} %{INT:csbytes} %{INT:timetaken}"]
}
date {
match => [ "log_timestamp", "YYYY-MM-dd HH:mm:ss" ]
timezone => "Etc/UTC"
}
useragent {
source => "useragent"
prefix => "browser"
}
mutate {
remove_field => ["log_timestamp"]
gsub => [ "log_host", "-", "" ]
}
if [uri] =~ /v(2.7|2.8|2.9|3.0|max)/ {
ruby {
code => "event['api_version'] = /v(2.7|2.8|2.9|3.0|max)/.match(event['uri'])[1]"
}
}
}
output {
elasticsearch {
host => localhost
protocol => http
}
}
#!/bin/sh
curl -XDELETE 'http://127.0.0.1:9200/metrics/'
curl -XDELETE 'http://127.0.0.1:9200/logstash-*/'
#!/bin/sh
sudo elasticsearch --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml
#!/bin/sh
logstash agent -f iis.config --verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment