line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# server::syslogng Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Server::Syslogng; |
7
|
1
|
|
|
1
|
|
823
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1048
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable syslog log logging syslog-ng) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
datadir => [ qw(datadir) ], |
20
|
|
|
|
|
|
|
output => [ qw(file) ], |
21
|
|
|
|
|
|
|
listen => [ qw(address) ], |
22
|
|
|
|
|
|
|
port => [ qw(port) ], |
23
|
|
|
|
|
|
|
conf_file => [ qw(file) ], |
24
|
|
|
|
|
|
|
to_remote => [ qw(host) ], |
25
|
|
|
|
|
|
|
to_port => [ qw(port) ], |
26
|
|
|
|
|
|
|
use_ssl => [ qw(0|1) ], |
27
|
|
|
|
|
|
|
ca_dir => [ qw(directory) ], |
28
|
|
|
|
|
|
|
key_file => [ qw(file) ], |
29
|
|
|
|
|
|
|
cert_file => [ qw(file) ], |
30
|
|
|
|
|
|
|
version => [ qw(version) ], |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
attributes_default => { |
33
|
|
|
|
|
|
|
listen => '127.0.0.1', |
34
|
|
|
|
|
|
|
port => 6300, |
35
|
|
|
|
|
|
|
output => 'local.log', |
36
|
|
|
|
|
|
|
use_ssl => 0, |
37
|
|
|
|
|
|
|
version => '3.5', |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
commands => { |
40
|
|
|
|
|
|
|
install => [ ], # Inherited |
41
|
|
|
|
|
|
|
generate_conf => [ qw(conf_file|OPTIONAL) ], |
42
|
|
|
|
|
|
|
start => [ qw(conf_file|OPTIONAL) ], |
43
|
|
|
|
|
|
|
stop => [ qw(pidfile|OPTIONAL) ], |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
require_modules => { |
46
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
47
|
|
|
|
|
|
|
'Metabrik::System::File' => [ ], |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
require_binaries => { |
50
|
|
|
|
|
|
|
'syslog-ng' => [ ], |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
need_packages => { |
53
|
|
|
|
|
|
|
ubuntu => [ qw(syslog-ng) ], |
54
|
|
|
|
|
|
|
debian => [ qw(syslog-ng) ], |
55
|
|
|
|
|
|
|
kali => [ qw(syslog-ng) ], |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub brik_use_properties { |
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return { |
66
|
0
|
|
|
|
|
|
attributes_default => { |
67
|
|
|
|
|
|
|
conf_file => "$datadir/syslogng.conf", |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
# https://www.balabit.com/documents/syslog-ng-ose-3.5-guides/en/syslog-ng-ose-guide-admin/html-single/index.html |
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub generate_conf { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my ($conf_file) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
83
|
0
|
|
0
|
|
|
|
my $user = defined($self->global) && $self->global->username || 'username'; |
84
|
0
|
|
0
|
|
|
|
my $hostname = defined($self->global) && $self->global->hostname || 'hostname'; |
85
|
0
|
|
|
|
|
|
my $group = $user; |
86
|
0
|
|
|
|
|
|
my $listen = $self->listen; |
87
|
0
|
|
|
|
|
|
my $port = $self->port; |
88
|
0
|
|
|
|
|
|
my $output = $self->output; |
89
|
0
|
|
|
|
|
|
my $remote_host = $self->to_remote; |
90
|
0
|
|
|
|
|
|
my $remote_port = $self->to_port; |
91
|
0
|
|
|
|
|
|
my $use_ssl = $self->use_ssl; |
92
|
0
|
|
|
|
|
|
my $ca_dir = $self->ca_dir; |
93
|
0
|
|
|
|
|
|
my $key_file = $self->key_file; |
94
|
0
|
|
|
|
|
|
my $cert_file = $self->cert_file; |
95
|
0
|
|
|
|
|
|
my $version = $self->version; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
my $sf = Metabrik::System::File->new_from_brik_init($self) or return; |
98
|
0
|
0
|
|
|
|
|
if ($sf->is_relative($output)) { |
99
|
0
|
|
|
|
|
|
$output = "$datadir/$output"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $conf = '@version:'."$version\n"; |
103
|
0
|
0
|
|
|
|
|
if (-f '/etc/syslog-ng/scl.conf') { |
104
|
0
|
|
|
|
|
|
$conf .= '@include "scl.conf"'."\n"; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
$conf .= "\n"; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$conf .=<
|
109
|
|
|
|
|
|
|
options { |
110
|
|
|
|
|
|
|
use-dns(no); |
111
|
|
|
|
|
|
|
use-fqdn(no); |
112
|
|
|
|
|
|
|
keep-hostname(yes); |
113
|
|
|
|
|
|
|
chain-hostnames(no); |
114
|
|
|
|
|
|
|
owner("$user"); |
115
|
|
|
|
|
|
|
group("$group"); |
116
|
|
|
|
|
|
|
perm(0644); |
117
|
|
|
|
|
|
|
stats-freq(120); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Performance optimizations |
120
|
|
|
|
|
|
|
# From: https://pzolee.blogs.balabit.com/2011/02/syslog-ng-performance-tuning/ |
121
|
|
|
|
|
|
|
flush-lines(100); |
122
|
|
|
|
|
|
|
log-fifo-size(1000); |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
source s_internal { |
126
|
|
|
|
|
|
|
internal(); |
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
destination d_local_syslogng { |
130
|
|
|
|
|
|
|
file("$datadir/syslogng.log"); |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
log { source(s_internal); destination(d_local_syslogng); }; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
source s_listen_udp { |
136
|
|
|
|
|
|
|
udp(ip($listen) port($port) |
137
|
|
|
|
|
|
|
host-override("$hostname") |
138
|
|
|
|
|
|
|
log-iw-size(100) |
139
|
|
|
|
|
|
|
log-fetch-limit(100) |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
}; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
destination d_local_file { |
144
|
|
|
|
|
|
|
file("$output"); |
145
|
|
|
|
|
|
|
}; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
EOF |
148
|
|
|
|
|
|
|
; |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
0
|
|
|
|
if (defined($remote_host) && $use_ssl) { |
|
|
0
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$conf .=<
|
152
|
|
|
|
|
|
|
destination d_remote_host { |
153
|
|
|
|
|
|
|
tcp("$remote_host" port($remote_port) |
154
|
|
|
|
|
|
|
tls( |
155
|
|
|
|
|
|
|
ca-dir("$ca_dir") |
156
|
|
|
|
|
|
|
key-file("$key_file") |
157
|
|
|
|
|
|
|
cert-file("$cert_file") |
158
|
|
|
|
|
|
|
) |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
log { source(s_listen_udp); destination(d_remote_host); flags(flow-control); }; |
163
|
|
|
|
|
|
|
EOF |
164
|
|
|
|
|
|
|
; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
elsif (defined($remote_host)) { |
167
|
0
|
|
|
|
|
|
$conf .=<
|
168
|
|
|
|
|
|
|
destination d_remote_host { tcp("$remote_host" port($remote_port) ); }; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
log { source(s_listen_udp); destination(d_remote_host); flags(flow-control); }; |
171
|
|
|
|
|
|
|
EOF |
172
|
|
|
|
|
|
|
; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
else { |
175
|
0
|
|
|
|
|
|
$conf .=<
|
176
|
|
|
|
|
|
|
log { source(s_listen_udp); destination(d_local_file); }; |
177
|
|
|
|
|
|
|
EOF |
178
|
|
|
|
|
|
|
; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
182
|
0
|
|
|
|
|
|
$ft->append(0); |
183
|
0
|
|
|
|
|
|
$ft->overwrite(1); |
184
|
0
|
0
|
|
|
|
|
$ft->write($conf, $conf_file) or return; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $conf_file; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub start { |
190
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
191
|
0
|
|
|
|
|
|
my ($conf_file) = @_; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
194
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('start', $conf_file) or return; |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
197
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('start', $conf_file) or return; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $ctlfile = $datadir.'/syslogng.ctl'; |
200
|
0
|
|
|
|
|
|
my $persistfile = $datadir.'/syslogng.persist'; |
201
|
0
|
|
|
|
|
|
my $pidfile = $datadir.'/syslogng.pidfile'; |
202
|
|
|
|
|
|
|
|
203
|
0
|
0
|
|
|
|
|
if (-f $pidfile) { |
204
|
0
|
|
|
|
|
|
return $self->log->error("start: syslogng already started with pidfile [$pidfile]"); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $cmd = "syslog-ng -f \"$conf_file\" -c \"$ctlfile\" -R \"$persistfile\" --pidfile \"$pidfile\""; |
208
|
0
|
|
|
|
|
|
$self->ignore_error(0); |
209
|
0
|
0
|
|
|
|
|
my $r = $self->system($cmd) or return; |
210
|
0
|
0
|
|
|
|
|
if ($r == 256) { |
|
|
0
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
return $self->log->error("start: unable to start syslogng: code [$r]"); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
elsif ($r > 0) { |
214
|
0
|
|
|
|
|
|
$self->log->warning("start: some errors found while starting syslogng: code [$r]"); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
return $pidfile; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub stop { |
221
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
222
|
0
|
|
|
|
|
|
my ($pidfile) = @_; |
223
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
|
if (! defined($pidfile)) { |
225
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
226
|
0
|
|
|
|
|
|
$pidfile = $datadir.'/syslogng.pidfile'; |
227
|
|
|
|
|
|
|
} |
228
|
0
|
0
|
|
|
|
|
if (! -f $pidfile) { |
229
|
0
|
|
|
|
|
|
return $self->log->error("start: syslogng NOT started with pidfile [$pidfile]"); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
my $sp = Metabrik::System::Process->new_from_brik_init($self) or return; |
233
|
0
|
|
|
|
|
|
return $sp->kill_from_pidfile($pidfile); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |