Skip to content

Commit 4623dce

Browse files
committed
Rework remote plugin status reporting
Redirected the remote plugin's SIGUSR1 status output to a dedicated /run/audit/remote.state file, logging each metric on its own line and noting glibc memory statistics when available. Updated the audisp-remote manual to document the state report and list its file in the FILES section.
1 parent 79375b5 commit 4623dce

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

audisp/plugins/remote/audisp-remote.8

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
.TH AUDISP-REMOTE "8" "August 2018" "Red Hat" "System Administration Utilities"
1+
.TH AUDISP-REMOTE "8" "May 2024" "Red Hat" "System Administration Utilities"
22
.SH NAME
33
audisp-remote \- plugin for remote logging
44
.SH SYNOPSIS
55
.B audisp-remote
66
.SH DESCRIPTION
77
\fBaudisp-remote\fP is a plugin for the audit event dispatcher that performs remote logging to an aggregate logging server.
8+
When the plugin is sent \fBSIGUSR1\fP, it writes a state report to \fBremote.state\fP.
89

910
.SH TIPS
1011
If you are aggregating multiple machines, you should edit auditd.conf to set the name_format to something meaningful and the log_format to enriched. This way you can tell where the event came from and have the user name and groups resolved locally before it is sent off of the machine.
1112

1213
.SH SIGNALS
1314
.TP
1415
SIGUSR1
15-
Causes the audisp-remote program to write the value of some of its internal flags to syslog. The
16+
Causes the audisp-remote program to write a state report to
17+
.B remote.state
18+
in
19+
.BR /run/audit .
20+
The
1621
.IR suspend
1722
flag tells whether or not logging has been suspended. The
1823
.IR remote_ended
1924
flag tells if the connection was broken by the server saying it can't log events. The
2025
.IR transport_ok
2126
flag tells whether or not the connection to the remote server is healthy. The
22-
.IR queue_size
23-
tells how many records are enqueued to be sent to the remote server.
27+
.IR queue_length
28+
tells how many records are enqueued to be sent to the remote server. The
29+
.IR max_queued_length
30+
shows the peak queue length since startup. The report also records glibc memory
31+
consumption when available.
2432
.TP
2533
SIGUSR2
2634
Causes the audisp-remote program to resume logging if it were suspended due to an error.
@@ -29,6 +37,7 @@ Causes the audisp-remote program to resume logging if it were suspended due to a
2937
/etc/audit/audisp-remote.conf
3038
/etc/audit/plugins.d/au-remote.conf
3139
/etc/audit/auditd.conf
40+
/run/audit/remote.state
3241
.SH "SEE ALSO"
3342
.BR auditd.conf (8),
3443
.BR auditd-plugins (5),

audisp/plugins/remote/audisp-remote.c

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include <stdlib.h>
3333
#include <errno.h>
3434
#include <time.h>
35+
#ifdef HAVE_MALLINFO2
36+
#include <malloc.h>
37+
#endif
3538
#include <fcntl.h>
3639
#include <sys/select.h>
3740
#include <poll.h>
@@ -74,9 +77,14 @@ static volatile int remote_ended = 1, quiet = 0;
7477
static int ifd;
7578
remote_conf_t config;
7679
static int warned = 0;
80+
#ifdef HAVE_MALLINFO2
81+
static struct mallinfo2 last_mi;
82+
#endif
83+
static size_t max_queued_length = 0;
7784

7885
/* Constants */
7986
static const char *SPOOL_FILE = "/var/spool/audit/remote.log";
87+
#define STATE_FILE AUDIT_RUN_DIR"/remote.state"
8088

8189
/* Local function declarations */
8290
static int check_message(void);
@@ -147,22 +155,53 @@ static void reload_config(void)
147155
}
148156

149157
/*
150-
* SIGSUR1 handler: dump stats
158+
* SIGUSR1 handler: write a state report
151159
*/
152160
static void user1_handler( int sig )
153161
{
154162
dump = 1;
155163
}
156164

157-
static void dump_stats(struct queue *queue)
165+
#ifdef HAVE_MALLINFO2
166+
/* Write glibc memory statistics to FILE */
167+
static void write_memory_state(FILE *f)
168+
{
169+
struct mallinfo2 mi = mallinfo2();
170+
171+
fprintf(f, "glibc arena (total memory) is: %zu KiB, was: %zu KiB\n",
172+
(size_t)mi.arena/1024, (size_t)last_mi.arena/1024);
173+
fprintf(f, "glibc uordblks (in use memory) is: %zu KiB, was: %zu KiB\n",
174+
(size_t)mi.uordblks/1024,(size_t)last_mi.uordblks/1024);
175+
fprintf(f,"glibc fordblks (total free space) is: %zu KiB, was: %zu KiB\n",
176+
(size_t)mi.fordblks/1024,(size_t)last_mi.fordblks/1024);
177+
178+
memcpy(&last_mi, &mi, sizeof(struct mallinfo2));
179+
}
180+
#endif
181+
182+
/* Write plugin state to STATE_FILE */
183+
static void write_state_report(struct queue *queue)
158184
{
159-
syslog(LOG_INFO,
160-
"suspend=%s, remote_ended=%s, transport_ok=%s, queued_items=%zu, queue_depth=%u",
161-
suspend ? "yes" : "no",
162-
remote_ended ? "yes" : "no",
163-
transport_ok ? "yes" : "no",
164-
q_queue_length(queue),
165-
config.queue_depth);
185+
char buf[64];
186+
mode_t u = umask(0137); // allow 0640
187+
FILE *f = fopen(STATE_FILE, "w");
188+
umask(u);
189+
if (f == NULL)
190+
return;
191+
192+
time_t now = time(NULL);
193+
strftime(buf, sizeof(buf), "%x %X", localtime(&now));
194+
fprintf(f, "current_time = %s\n", buf);
195+
fprintf(f, "suspend = %s\n", suspend ? "yes" : "no");
196+
fprintf(f, "remote_ended = %s\n", remote_ended ? "yes" : "no");
197+
fprintf(f, "transport_ok = %s\n", transport_ok ? "yes" : "no");
198+
fprintf(f, "queue_length = %zu\n", q_queue_length(queue));
199+
fprintf(f, "max_queued_length = %zu\n", max_queued_length);
200+
fprintf(f, "queue_depth = %u\n", config.queue_depth);
201+
#ifdef HAVE_MALLINFO2
202+
write_memory_state(f);
203+
#endif
204+
fclose(f);
166205
dump = 0;
167206
}
168207

@@ -497,6 +536,7 @@ int main(int argc, char *argv[])
497536
syslog(LOG_ERR, "Error initializing audit record queue: %m");
498537
return 1;
499538
}
539+
max_queued_length = q_queue_length(queue);
500540

501541
#ifdef HAVE_LIBCAP_NG
502542
// Drop capabilities
@@ -521,7 +561,7 @@ int main(int argc, char *argv[])
521561
reload_config();
522562

523563
if (dump)
524-
dump_stats(queue);
564+
write_state_report(queue);
525565

526566
/* Setup select flags */
527567
FD_ZERO(&rfd);
@@ -607,6 +647,10 @@ int main(int argc, char *argv[])
607647
do_overflow_action();
608648
else
609649
queue_error();
650+
} else {
651+
size_t len = q_queue_length(queue);
652+
if (len > max_queued_length)
653+
max_queued_length = len;
610654
}
611655
} else if (auplugin_fgets_eof())
612656
stop = 1;

0 commit comments

Comments
 (0)