summaryrefslogtreecommitdiff
path: root/vtysh
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2019-07-03 14:39:59 +0200
committerGitHub <noreply@github.com>2019-07-03 14:39:59 +0200
commit1df04926871d9c9029fc22037db799526b691e02 (patch)
tree578c50cb3e575b2f0c002f2d5893218246b4fa5a /vtysh
parentdb9f2ddde2f2e0f131c2f7299642c777c5aeb043 (diff)
parent018fa5f85dad6324c08b3f1fddf7553bc63819dd (diff)
Run-time log filtering via vtysh commands (#4524)
Run-time log filtering via vtysh commands
Diffstat (limited to 'vtysh')
-rw-r--r--vtysh/vtysh.c186
1 files changed, 140 insertions, 46 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index c3aeb27eb9..053848bfc3 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -140,6 +140,21 @@ struct vtysh_client vtysh_client[] = {
{.fd = -1, .name = "vrrpd", .flag = VTYSH_VRRPD, .next = NULL},
};
+/* Searches for client by name, returns index */
+static int vtysh_client_lookup(const char *name)
+{
+ int idx = -1;
+
+ for (unsigned int i = 0; i < array_size(vtysh_client); i++) {
+ if (strmatch(vtysh_client[i].name, name)) {
+ idx = i;
+ break;
+ }
+ }
+
+ return idx;
+}
+
enum vtysh_write_integrated vtysh_write_integrated =
WRITE_INTEGRATED_UNSPECIFIED;
@@ -394,6 +409,23 @@ static int vtysh_client_execute(struct vtysh_client *head_client,
return vtysh_client_run_all(head_client, line, 0, NULL, NULL);
}
+/* Execute by name */
+static int vtysh_client_execute_name(const char *name, const char *line)
+{
+ int ret = CMD_SUCCESS;
+ int idx_client = -1;
+
+ idx_client = vtysh_client_lookup(name);
+ if (idx_client != -1)
+ ret = vtysh_client_execute(&vtysh_client[idx_client], line);
+ else {
+ vty_out(vty, "Client not found\n");
+ ret = CMD_WARNING;
+ }
+
+ return ret;
+}
+
/*
* Retrieve all running config from daemons and parse it with the vtysh config
* parser. Returned output is not displayed to the user.
@@ -2269,33 +2301,15 @@ DEFUN (vtysh_show_work_queues,
DEFUN (vtysh_show_work_queues_daemon,
vtysh_show_work_queues_daemon_cmd,
- "show work-queues <zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd|fabricd|pimd|staticd>",
+ "show work-queues " DAEMONS_LIST,
SHOW_STR
"Work Queue information\n"
- "For the zebra daemon\n"
- "For the rip daemon\n"
- "For the ripng daemon\n"
- "For the ospf daemon\n"
- "For the ospfv6 daemon\n"
- "For the bgp daemon\n"
- "For the isis daemon\n"
- "For the pbr daemon\n"
- "For the fabricd daemon\n"
- "For the pim daemon\n"
- "For the static daemon\n")
+ DAEMONS_STR)
{
int idx_protocol = 2;
- unsigned int i;
- int ret = CMD_SUCCESS;
-
- for (i = 0; i < array_size(vtysh_client); i++) {
- if (strmatch(vtysh_client[i].name, argv[idx_protocol]->text))
- break;
- }
- ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n");
-
- return ret;
+ return vtysh_client_execute_name(argv[idx_protocol]->text,
+ "show work-queues\n");
}
DEFUNSH(VTYSH_ZEBRA, vtysh_link_params, vtysh_link_params_cmd, "link-params",
@@ -2627,22 +2641,109 @@ DEFUNSH(VTYSH_ALL, no_vtysh_config_enable_password,
return CMD_SUCCESS;
}
+/* Log filter */
+DEFUN (vtysh_log_filter,
+ vtysh_log_filter_cmd,
+ "[no] log-filter WORD ["DAEMONS_LIST"]",
+ NO_STR
+ FILTER_LOG_STR
+ "String to filter by\n"
+ DAEMONS_STR)
+{
+ char *filter = NULL;
+ char *daemon = NULL;
+ int found = 0;
+ int idx = 0;
+ int daemon_idx = 2;
+ int total_len = 0;
+ int len = 0;
+
+ char line[ZLOG_FILTER_LENGTH_MAX + 20];
+
+ found = argv_find(argv, argc, "no", &idx);
+ if (found == 1) {
+ len = snprintf(line, sizeof(line), "no log-filter");
+ daemon_idx += 1;
+ } else
+ len = snprintf(line, sizeof(line), "log-filter");
+
+ total_len += len;
+
+ idx = 1;
+ found = argv_find(argv, argc, "WORD", &idx);
+ if (found != 1) {
+ vty_out(vty, "%% No filter string given\n");
+ return CMD_WARNING;
+ }
+ filter = argv[idx]->arg;
+
+ if (strnlen(filter, ZLOG_FILTER_LENGTH_MAX + 1)
+ > ZLOG_FILTER_LENGTH_MAX) {
+ vty_out(vty, "%% Filter is too long\n");
+ return CMD_WARNING;
+ }
+
+ len = snprintf(line + total_len, sizeof(line) - total_len, " %s\n",
+ filter);
+
+ if ((len < 0) || (size_t)(total_len + len) > sizeof(line)) {
+ vty_out(vty, "%% Error buffering filter to daemons\n");
+ return CMD_ERR_INCOMPLETE;
+ }
+
+ if (argc >= (daemon_idx + 1))
+ daemon = argv[daemon_idx]->text;
+
+ if (daemon != NULL) {
+ vty_out(vty, "Applying log filter change to %s:\n", daemon);
+ return vtysh_client_execute_name(daemon, line);
+ } else
+ return show_per_daemon(line,
+ "Applying log filter change to %s:\n");
+}
+
+/* Clear log filters */
+DEFUN (vtysh_log_filter_clear,
+ vtysh_log_filter_clear_cmd,
+ "log-filter clear ["DAEMONS_LIST"]",
+ FILTER_LOG_STR
+ CLEAR_STR
+ DAEMONS_STR)
+{
+ char *daemon = NULL;
+ int daemon_idx = 2;
+
+ char line[] = "clear log-filter\n";
+
+ if (argc >= (daemon_idx + 1))
+ daemon = argv[daemon_idx]->text;
+
+ if (daemon != NULL) {
+ vty_out(vty, "Clearing all filters applied to %s:\n", daemon);
+ return vtysh_client_execute_name(daemon, line);
+ } else
+ return show_per_daemon(line,
+ "Clearing all filters applied to %s:\n");
+}
+
+/* Show log filter */
+DEFUN (vtysh_show_log_filter,
+ vtysh_show_log_filter_cmd,
+ "show log-filter",
+ SHOW_STR
+ FILTER_LOG_STR)
+{
+ char line[] = "do show log-filter\n";
+
+ return show_per_daemon(line, "Log filters applied to %s:\n");
+}
+
DEFUN (vtysh_write_terminal,
vtysh_write_terminal_cmd,
- "write terminal [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
+ "write terminal ["DAEMONS_LIST"]",
"Write running configuration to memory, network, or terminal\n"
"Write to terminal\n"
- "For the zebra daemon\n"
- "For the rip daemon\n"
- "For the ripng daemon\n"
- "For the ospf daemon\n"
- "For the ospfv6 daemon\n"
- "For the ldpd daemon\n"
- "For the bgp daemon\n"
- "For the isis daemon\n"
- "For the fabricd daemon\n"
- "For the pim daemon\n"
- "For the static daemon\n")
+ DAEMONS_STR)
{
unsigned int i;
char line[] = "do write terminal\n";
@@ -2668,20 +2769,10 @@ DEFUN (vtysh_write_terminal,
DEFUN (vtysh_show_running_config,
vtysh_show_running_config_cmd,
- "show running-config [<zebra|ripd|ripngd|ospfd|ospf6d|ldpd|bgpd|isisd|fabricd|pimd|staticd>]",
+ "show running-config ["DAEMONS_LIST"]",
SHOW_STR
"Current operating configuration\n"
- "For the zebra daemon\n"
- "For the rip daemon\n"
- "For the ripng daemon\n"
- "For the ospf daemon\n"
- "For the ospfv6 daemon\n"
- "For the ldp daemon\n"
- "For the bgp daemon\n"
- "For the isis daemon\n"
- "For the fabricd daemon\n"
- "For the pim daemon\n"
- "For the static daemon\n")
+ DAEMONS_STR)
{
return vtysh_write_terminal(self, vty, argc, argv);
}
@@ -3871,6 +3962,9 @@ void vtysh_init_vty(void)
/* Logging */
install_element(VIEW_NODE, &vtysh_show_logging_cmd);
+ install_element(VIEW_NODE, &vtysh_show_log_filter_cmd);
+ install_element(CONFIG_NODE, &vtysh_log_filter_cmd);
+ install_element(CONFIG_NODE, &vtysh_log_filter_clear_cmd);
install_element(CONFIG_NODE, &vtysh_log_stdout_cmd);
install_element(CONFIG_NODE, &vtysh_log_stdout_level_cmd);
install_element(CONFIG_NODE, &no_vtysh_log_stdout_cmd);