-
Notifications
You must be signed in to change notification settings - Fork 1
/
input-show.sh
executable file
·89 lines (79 loc) · 2.42 KB
/
input-show.sh
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
#!/usr/bin/env bash
set -euo pipefail
edge_url="${EDGE_URL?:missing environment variable: EDGE_URL}"
cookie_jar="$("$(dirname -- "${BASH_SOURCE[0]}")/login.sh" "$edge_url")"
id="${1?missing argument: input ID}"
parse_thumbnail_mode() {
if [ "$1" == 0 ]; then
echo -n none
elif [ "$1" == 2 ]; then
echo -n core
else
echo -n unknown
fi
}
parse_admin_status() {
if [ "$1" == 1 ]; then
echo -n on
elif [ "$1" == 0 ]; then
echo -n off
else
echo -n unknown
fi
}
format_ports() {
port="$1"
while IFS=$'\t' read -r \
copies \
physical_port \
mode
do
port_info=$(curl "$edge_url/api/port/$physical_port" \
--silent \
--get \
--cookie "$cookie_jar")
cat <<EOF
- Mode: $mode
Source interface: $(jq --raw-output .name <<<"$port_info")
Copies: $copies
EOF
done < <(jq --raw-output '. | map([
.copies,
.physicalPort,
.mode,
.port,
.address,
.ttl,
.sourceAddress
])[] | @tsv' <<<"$port")
}
input=$(curl "$edge_url/api/input/$id" \
--silent \
--get \
--cookie "$cookie_jar")
group=$(curl "$edge_url/api/group/$(jq --raw-output .owner <<<"$input")" \
--silent \
--get \
--cookie "$cookie_jar")
if [ "$(jq --raw-output .health.state <<<"$input")" == "allOk" ]; then
health="\e[32m✓\e[0m"
else
health="\e[31m✗\e[0m $(jq --raw-output .health.title <<<"$input")"
fi
cat <<EOF
ID: $(jq --raw-output .id <<<"$input")
Name: $(jq --raw-output .name <<<"$input")
Admin status: $(parse_admin_status "$(jq --raw-output .adminStatus <<<"$input")")
Owner: $(jq --raw-output .name <<<"$group")
Buffer: $(jq --raw-output .bufferSize <<<"$input")ms
Preview: $(jq --raw-output .previewSettings.mode <<<"$input")
Thumbnail mode: $(parse_thumbnail_mode "$(jq --raw-output .thumbnailMode <<<"$input")")
TR 101 290: $(jq --raw-output .tr101290Enabled <<<"$input")
Can subscribe: $(jq --raw-output .canSubscribe <<<"$input")
Appliances: $(jq --raw-output '(.appliances | map(.name) | join(", "))' <<<"$input")
Ports:
$(format_ports "$(jq --raw-output .ports <<<"$input")")
Created: $(jq --raw-output .createdAt <<<"$input")
Updated: $(jq --raw-output .updatedAt <<<"$input")
Health: $(echo -e "$health")
EOF