Skip to content

Commit

Permalink
Add NTCE and hotspots summary commands (#23)
Browse files Browse the repository at this point in the history
* Add new ntce and hotspot summary commands

* Bump version

* Add tests for get_time_period function

* Update src/lib/functions/get_time_period.sh

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix yamllint errors, regenerate keencli

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
tolkonepiu and github-actions[bot] authored Apr 14, 2024
1 parent b7c8907 commit 973799c
Show file tree
Hide file tree
Showing 8 changed files with 1,051 additions and 57 deletions.
894 changes: 851 additions & 43 deletions keencli

Large diffs are not rendered by default.

125 changes: 113 additions & 12 deletions src/bashly.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: keencli
help: Keenetic command-line interface written in Bash
version: 0.3.4
version: 0.4.0

dependencies:
curl: https://curl.se/
Expand All @@ -16,10 +16,8 @@ environment_variables:
`https://myrouter01.keenetic.link`)
- name: KEENETIC_USERNAME
help: Keenetic username
required: true
- name: KEENETIC_PASSWORD
help: Keenetic password
required: true

commands:
- name: request
Expand Down Expand Up @@ -122,24 +120,118 @@ commands:
stat - interface statistics
allowed:
- stat
examples:
- keencli show interface GigabitEthernet0
- keencli show interface GigabitEthernet0 stat
- name: ip
help: IP information
commands:
- name: hotspot
help: Hotspot hosts
flags:
- *baseurl
- *output
- *format
args:
- name: mac_address
help: MAC address (example `b0:c2:b9:aa:0d:dd`)
help: Hotspots
commands:
- name: list
help: Hotspot list
flags:
- long: --mac_address
arg: mac_address
help: >
MAC address (example `b0:c2:b9:aa:0d:dd`)
- *baseurl
- *output
- *format
examples:
- keencli show ip hotspot list
- keencli show ip hotspot list --mac_address b0:c2:b9:aa:0d:dd
- name: summary
help: Hotspot summary
flags:
- &metric_type
long: --metric_type
arg: metric_type
default: sumbytes
allowed:
- sumbytes
- sumspeed
help: >
Specifies the type of metric
Available options:
sumbytes - total number of bytes transferred within the
network client over a specified period
sumspeed - average speed within the network client over a
specified period
- &count
long: --count
arg: count
default: "5"
help: Number of items
- &time_period
long: --time_period
arg: time_period
default: "3m"
allowed:
- "3m"
- "1h"
- "3h"
- "24h"
help: |
Time period
Available options:
3m - last 3 minutes
1h - last 1 hour
3h - last 3 hours
24h - last 24 hours
- *baseurl
- *output
- *format
examples:
- keencli show ip hotspot summary
- >-
keencli show ip hotspot summary --metric_type sumspeed
--time_period 24h --count 20
- name: internet
help: Internet check status
flags:
- *baseurl
- *output
- *format
examples:
- keencli show internet
- name: ntce
help: Show NTCE information
commands:
- name: summary
help: Show NTCE summary
flags:
- long: --traffic_type
arg: traffic_type
default: application
allowed:
- application
- group
help: >
Specifies the type of traffic segmentation
Available options:
application - segmentation of traffic based on applications
group - Segmentation of traffic based on general types,
such as calling, surfing, file transferring, etc.
- *metric_type
- *count
- *time_period
- *baseurl
- *output
- *format
examples:
- keencli show ntce summary
- >-
keencli show ntce summary --time_period 24h --metric_type
sumspeed --traffic_type group --count 20
- name: config
help: Configuration files
flags:
Expand All @@ -148,7 +240,7 @@ commands:
args:
- name: configuration_file
help: >
System configuration file
System configuration files
Available options:
Expand All @@ -163,13 +255,22 @@ commands:
- startup-config
- default-config
- running-config
examples:
- keencli config startup-config
- keencli config default-config --output default-config.txt
- name: log
help: System event log for system diagnostics
flags:
- *baseurl
- *output
examples:
- keencli log
- keencli log --output log.txt
- name: self-test
help: Full diagnostic information about this device
flags:
- *baseurl
- *output
examples:
- keencli self-test
- keencli self-test --output self-test.txt
2 changes: 1 addition & 1 deletion src/config_command.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# shellcheck disable=SC2154
http_command \
"${args[--baseurl]}" \
"/ci/${args[system_filename]}.txt" \
"/ci/${args[configuration_file]}.txt" \
"${args[request_data]}" \
"${args[--output]}" \
"${args[--format]}"
19 changes: 19 additions & 0 deletions src/lib/functions/get_time_period.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function get_time_period() {
case "${1:?time_period must be set}" in
3m)
echo 0
;;
1h)
echo 1
;;
3h)
echo 2
;;
24h)
echo 3
;;
*)
error "Unknown time period ${1}"
;;
esac
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# shellcheck disable=SC2154
url_path="/rci/show/ip/hotspot"

mac_address="${args[mac_address]}"
mac_address="${args[--mac_address]}"
if [[ -n "${mac_address}" ]]; then
url_path="${url_path}?mac=${mac_address}"
fi
Expand Down
13 changes: 13 additions & 0 deletions src/show_ip_hotspot_summary_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# shellcheck disable=SC2154
metric_type="${args[--metric_type]}"
count="${args[--count]}"
time_period=$(get_time_period "${args[--time_period]}")

url_path="/rci/show/ip/hotspot/summary?attribute=${metric_type}&count=${count}&detail=${time_period}"

http_command \
"${args[--baseurl]}" \
"${url_path}" \
"${args[request_data]}" \
"${args[--output]}" \
"${args[--format]}"
14 changes: 14 additions & 0 deletions src/show_ntce_summary_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# shellcheck disable=SC2154
traffic_type="${args[--traffic_type]}"
metric_type="${args[--metric_type]}"
count="${args[--count]}"
time_period=$(get_time_period "${args[--time_period]}")

url_path="/rci/show/ntce/summary?${traffic_type}=true&attrib=${metric_type}&count=${count}&detail=${time_period}"

http_command \
"${args[--baseurl]}" \
"${url_path}" \
"${args[request_data]}" \
"${args[--output]}" \
"${args[--format]}"
39 changes: 39 additions & 0 deletions test/get_time_period.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bats

load test_helper.bash

# shellcheck source=../src/lib/functions/logging.sh
source "src/lib/functions/logging.sh"
# shellcheck source=../src/lib/functions/get_time_period.sh
source "src/lib/functions/get_time_period.sh"

@test "without parameters" {
run get_time_period
[ "$status" -ne 0 ]
}

@test "with correct parameter" {
run get_time_period 3m
[ "$status" -eq 0 ]
[ "$output" = "0" ]

run get_time_period 1h
[ "$status" -eq 0 ]
[ "$output" = "1" ]

run get_time_period 3h
[ "$status" -eq 0 ]
[ "$output" = "2" ]

run get_time_period 24h
[ "$status" -eq 0 ]
[ "$output" = "3" ]
}

@test "with uncorrect parameter" {
run get_time_period 25h
[ "$status" -ne 0 ]

run get_time_period adsadasdasd
[ "$status" -ne 0 ]
}

0 comments on commit 973799c

Please sign in to comment.