Fix compression, allow disabling keep_alive

master
Daniel Berteaud 6 years ago
parent 7fe03ce1a5
commit d8460423ec
  1. 38
      systemd-journal-gelf

@ -15,7 +15,10 @@ use Net::Domain qw(hostfqdn);
my $conf = {};
my $cmd = {
config => '/etc/systemd/journal-gelf.yml'
config => '/etc/systemd/journal-gelf.yml',
compress => 1,
state => '/var/lib/systemd-journal-gelf/state',
keep_alive => 1
};
my $cursor = undef;
my $last_save = 0;
@ -23,6 +26,10 @@ my $cursor_re = qr{^s=[a-z\d]+;i=[a-z\d]+;b=[a-z\d]+;m=[a-z\d]+;t=[a-z\d]+;x=[a-
#### End global vars
END {
print "Saving current cursor to " . $conf->{state} . "\n";
save_cursor();
}
#### Routines #####
@ -36,6 +43,7 @@ Usage: $0 --url=<URL> [--compress|--no-compress] [--user=production --password=s
* --username and --password may be used if URL is protected with a basic auth mecanism. Either both or none must be provided
* --state can be used to specify where to record the last correctly sent message, so we can start from here when
systemd-journal-gelf is restarted or if there's a network problem. Default value is /var/lib/systemd-journal-gelf/state
* --no-keep-alive turns off Keep Alive, which might be needed for some remote server not handling it correctly
_EOF
}
@ -48,20 +56,16 @@ sub save_cursor {
}
}
sub handle_stop {
print "Saving current cursor to " . $conf->{state} . "\n";
save_cursor();
}
#### End Routines ####
GetOptions (
'c|config=s' => \$cmd->{config},
'state=s' => \$cmd->{state},
'compress!' => \$cmd->{compress},
'url=s' => \$cmd->{url},
'username=s' => \$cmd->{username},
'password=s' => \$cmd->{password}
'c|config=s' => \$cmd->{config},
'state=s' => \$cmd->{state},
'compress!' => \$cmd->{compress},
'url=s' => \$cmd->{url},
'username=s' => \$cmd->{username},
'password=s' => \$cmd->{password},
'keep-alive!' => \$cmd->{keep_alive}
);
# Open config file
@ -86,10 +90,6 @@ foreach ( keys %{ $cmd } ){
$conf->{$_} = $cmd->{$_} if ( $cmd->{$_} );
}
# Set some defaults is missing
$conf->{state} //= '/var/lib/systemd-journal-gelf/state';
$conf->{compress} //= 1;
# Now check config makes sens
if (
not $conf->{url} or
@ -102,13 +102,9 @@ if (
print "Starting the Systemd Journal GELF uploader daemon\n";
# Catch SIGTERM and save the cursor !
$SIG{TERM} = 'handle_stop';
$SIG{INT} = 'handle_stop';
my $ua = LWP::UserAgent->new(
env_proxy => 1,
keep_alive => 1
keep_alive => $conf->{keep_alive}
);
$ua->default_header( 'Content-Type' => 'application/json' );

Loading…
Cancel
Save