Skip to content

Commit

Permalink
syslog-ng-ctl: add get size of internal logs command.
Browse files Browse the repository at this point in the history
Signed-off-by: Mehul Prajapati <mehul.encs@gmail.com>
  • Loading branch information
Mehul Prajapati committed Sep 16, 2024
1 parent 1e70245 commit 4a14f59
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/afinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ afinter_stop_live_collection(void)
}
}

void
afinter_get_size_of_internal_logs(GString *result)
{
g_string_append_printf(result, "Size of internal logs: %d", g_queue_get_length(internal_msg_queue));
}

void
afinter_get_collected_messages(GString *result)
{
Expand Down
1 change: 1 addition & 0 deletions lib/afinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ AFInterLive afinter_start_live_collection(void);
void afinter_stop_live_collection(void);
void afinter_reset_live_collection(void);
void afinter_get_collected_messages(GString *result);
void afinter_get_size_of_internal_logs(GString *result);
#endif
4 changes: 4 additions & 0 deletions lib/mainloop-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ control_internal_logs(ControlConnection *cc, GString *command, gpointer user_dat
afinter_stop_live_collection();
afinter_get_collected_messages(result);
}
else if (g_str_equal(arguments[1], "SIZE"))
{
afinter_get_size_of_internal_logs(result);
}
else
{
g_string_assign(result, "FAIL Invalid arguments received");
Expand Down
4 changes: 4 additions & 0 deletions syslog-ng-ctl/syslog-ng-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ slng_reload(int argc, char *argv[], const gchar *mode, GOptionContext *ctx)

static gboolean config_options_start = FALSE;
static gboolean config_options_stop = FALSE;
static gboolean config_options_size = FALSE;

static GOptionEntry internal_options[] =
{
{ "start", 's', 0, G_OPTION_ARG_NONE, &config_options_start, "start live collection of internal logs", NULL },
{ "stop", 'x', 0, G_OPTION_ARG_NONE, &config_options_stop, "stop live collection of internal logs", NULL },
{ "size", 'l', 0, G_OPTION_ARG_NONE, &config_options_size, "get size of internal logs", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};

Expand All @@ -82,6 +84,8 @@ slng_internal(int argc, char *argv[], const gchar *mode, GOptionContext *ctx)
g_string_assign(cmd, "INTERLOGS START");
else if (config_options_stop)
g_string_assign(cmd, "INTERLOGS STOP");
else if (config_options_size)
g_string_assign(cmd, "INTERLOGS SIZE");
else
{
fprintf(stderr, "Error: Unknown command\n");
Expand Down

0 comments on commit 4a14f59

Please sign in to comment.