Fix compression, allow disabling keep_alive

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

@ -15,7 +15,10 @@ use Net::Domain qw(hostfqdn);
my $conf = {}; my $conf = {};
my $cmd = { 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 $cursor = undef;
my $last_save = 0; 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 global vars
END {
print "Saving current cursor to " . $conf->{state} . "\n";
save_cursor();
}
#### Routines ##### #### 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 * --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 * --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 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 _EOF
} }
@ -48,11 +56,6 @@ sub save_cursor {
} }
} }
sub handle_stop {
print "Saving current cursor to " . $conf->{state} . "\n";
save_cursor();
}
#### End Routines #### #### End Routines ####
GetOptions ( GetOptions (
@ -61,7 +64,8 @@ GetOptions (
'compress!' => \$cmd->{compress}, 'compress!' => \$cmd->{compress},
'url=s' => \$cmd->{url}, 'url=s' => \$cmd->{url},
'username=s' => \$cmd->{username}, 'username=s' => \$cmd->{username},
'password=s' => \$cmd->{password} 'password=s' => \$cmd->{password},
'keep-alive!' => \$cmd->{keep_alive}
); );
# Open config file # Open config file
@ -86,10 +90,6 @@ foreach ( keys %{ $cmd } ){
$conf->{$_} = $cmd->{$_} if ( $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 # Now check config makes sens
if ( if (
not $conf->{url} or not $conf->{url} or
@ -102,13 +102,9 @@ if (
print "Starting the Systemd Journal GELF uploader daemon\n"; 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( my $ua = LWP::UserAgent->new(
env_proxy => 1, env_proxy => 1,
keep_alive => 1 keep_alive => $conf->{keep_alive}
); );
$ua->default_header( 'Content-Type' => 'application/json' ); $ua->default_header( 'Content-Type' => 'application/json' );

Loading…
Cancel
Save