Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "telegraf acl" command to cli to dump acl hitcount values #267

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions autotest/units/001_one_port/078_hitcount_one/autotest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ steps:
[
c1: 1, 104
]
- cli_check: |
telegraf acl
acl,name=counters,rule=c1 packets=1u,bytes=104u

- sendPackets:
- port: kni0
Expand All @@ -31,6 +34,9 @@ steps:
[
c1: 2, 208
]
- cli_check: |
telegraf acl
acl,name=counters,rule=c1 packets=2u,bytes=208u

- sendPackets:
- port: kni0
Expand All @@ -43,3 +49,6 @@ steps:
[
c1: 3, 312
]
- cli_check: |
telegraf acl
acl,name=counters,rule=c1 packets=3u,bytes=312u
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ steps:
expect: 003-expect.pcap

- cli: "hitcount dump acl | diff - TESTDIR/hitcount_expected.txt"
- cli: "telegraf acl | diff - TESTDIR/telegraf_expected.txt"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
acl,name=counters,rule=allow_tcp_from_11_0_0_0_24_to_any_53 packets=1u,bytes=108u
acl,name=counters,rule=check_state_ip_from_any_to_any packets=3u,bytes=322u
acl,name=counters,rule=allow_tcp_from_any_to_2111_aaa_ff1c_2030_60_53 packets=1u,bytes=138u
acl,name=counters,rule=deny_ip_from_any_to_any packets=1u,bytes=116u
1 change: 1 addition & 0 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ std::vector<std::tuple<std::string,
{"telegraf bus", "", [](const auto& args) { Call(bus::bus_telegraf, args); }},
{"telegraf route", "", [](const auto& args) { Call(telegraf::route, args); }},
{"telegraf route tunnel", "", [](const auto& args) { Call(telegraf::route_tunnel, args); }},
{"telegraf acl", "", [](const auto& args) { Call(telegraf::acl, args); }},
{},
{"reload", "", [](const auto& args) { Call(config::reload, args); }},
{"version", "", [](const auto& args) { Call(show::version, args); }},
Expand Down
15 changes: 15 additions & 0 deletions cli/telegraf.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,19 @@ void route_tunnel()
influxdb_format::print("route_tunnel_counters", {{"link", link}, {"nexthop", nexthop}}, {{"counts", counts}, {"size", size}});
}
}

inline void acl()
{
interface::dataPlane dataplane;
const auto& response = dataplane.hitcount_dump();

for (const auto& [id, data] : response)
{
influxdb_format::print("acl",
{{"name", "counters"},
{"rule", id}},
{{"packets", data.count, "u"},
{"bytes", data.bytes, "u"}});
}
}
}
Loading