I use Logstash with File Input & Http Output to a homegrown service which requires credentials (username:password
) to be sent as Base64 encoded
value. Below is my Logstash configuration. Currently I can send the Base 64 encoded
value via headers
however I am looking for a way to encode a String (which would be available to Logstash via environment variable) to a Base 64 encoded
String value. Would highly appreciate if anyone can throw some light on this.
input {
file {
path => "/home/tom/testData/test2.log"
type => "log"
}
}
filter {
if [type] == "log" {
grok {
match => ["message", "%{TIMESTAMP_ISO8601:time} %{LOG:level} %{GREEDYDATA:lmessage}"]
}
ruby {
code => "require 'base64';
event['pass'] = Base64.encode64('User:Pwd')"
}
}
}
output {
stdout { codec => rubydebug }
http {
http_method => "post"
url => "http://10.1.2.3:1123/HomeService?User=Tom"
format => "message"
headers => {"Authorization" => "Basic %{pass}"}
content_type => "application/json"
message => '{"Outer": { "Inner": [ {"doc": { "Timestamp": "%{time}", "Single": "%{level}","Double": "%{lmessage}" } } ] } }'
}
}