1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Logging - VTY code
* Copyright (C) 2019 Cumulus Networks, Inc.
* Stephen Worley
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/log_vty.h"
#include "command.h"
#include "lib/vty.h"
#include "lib/log.h"
#ifndef VTYSH_EXTRACT_PL
#include "lib/log_vty_clippy.c"
#endif
DEFPY (log_filter,
log_filter_cmd,
"[no] log-filter WORD$filter",
NO_STR
FILTER_LOG_STR
"String to filter by\n")
{
int ret = 0;
if (no)
ret = zlog_filter_del(filter);
else
ret = zlog_filter_add(filter);
if (ret == 1) {
vty_out(vty, "%% filter table full\n");
return CMD_WARNING;
} else if (ret != 0) {
vty_out(vty, "%% failed to %s log filter\n",
(no ? "remove" : "apply"));
return CMD_WARNING;
}
vty_out(vty, " %s\n", filter);
return CMD_SUCCESS;
}
/* Clear all log filters */
DEFPY (log_filter_clear,
log_filter_clear_cmd,
"clear log-filter",
CLEAR_STR
FILTER_LOG_STR)
{
zlog_filter_clear();
return CMD_SUCCESS;
}
/* Show log filter */
DEFPY (show_log_filter,
show_log_filter_cmd,
"show log-filter",
SHOW_STR
FILTER_LOG_STR)
{
char log_filters[ZLOG_FILTERS_MAX * (ZLOG_FILTER_LENGTH_MAX + 3)] = "";
int len = 0;
len = zlog_filter_dump(log_filters, sizeof(log_filters));
if (len == -1) {
vty_out(vty, "%% failed to get filters\n");
return CMD_WARNING;
}
if (len != 0)
vty_out(vty, "%s", log_filters);
return CMD_SUCCESS;
}
void log_filter_cmd_init(void)
{
install_element(VIEW_NODE, &show_log_filter_cmd);
install_element(CONFIG_NODE, &log_filter_cmd);
install_element(CONFIG_NODE, &log_filter_clear_cmd);
}
|