Skip to content

Instantly share code, notes, and snippets.

@studio3104
Created September 22, 2012 15:46
Show Gist options
  • Save studio3104/3766571 to your computer and use it in GitHub Desktop.
Save studio3104/3766571 to your computer and use it in GitHub Desktop.
add `hostname key` to message from fluent-agent-lite
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use JSON::XS;
use Data::MessagePack;
$| = 1;
my $mp = Data::MessagePack->new();
my $message_from = $ARGV[0];
while ( my $json = <STDIN> ) {
my $decode = eval { decode_json($json); };
next if ($@);
$decode->{hostname} = $message_from;
print $mp->pack($decode);
}
<source>
type forward
</source>
<match hoge.**>
type forest
subtype exec_filter
remove_prefix hoge
<template>
command /home/satoshi/perl5/perlbrew/perls/perl-5.16.1/bin/perl /etc/td-agent/scripts/add_hostname.pl ${tag}
in_format json
out_format msgpack
tag foo.out
flush_interval 1s
</template>
</match>
<match foo.out>
type file
path /tmp/hoge.out
flush_interval 1s
</match>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment