forked from netinsight/edge-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output-show.sh
executable file
·114 lines (102 loc) · 3.02 KB
/
output-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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/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: output ID}"
parse_admin_status() {
if [ "$1" == 1 ]; then
echo -n on
elif [ "$1" == 0 ]; then
echo -n off
else
echo -n unknown
fi
}
parse_redundancy() {
if [ "$1" == 0 ]; then
echo -n none
elif [ "$1" == 1 ]; then
echo -n failover
elif [ "$1" == 2 ]; then
echo -n active
else
echo -n unknown
fi
}
parse_delay_mode() {
if [ "$1" == 1 ]; then
echo -n On Arrival
elif [ "$1" == 2 ]; then
echo -n On Origin
else
echo -n unknown
fi
}
format_ports() {
output="$1"
while IFS=$'\t' read -r \
copies \
physical_port \
mode \
port \
address \
ttl \
source_address
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")
Source address: $source_address
Destination Address: $address:$port
TTL: $ttl
Copies: $copies
EOF
done < <(jq --raw-output '. | map([
.copies,
.physicalPort,
.mode,
.port,
.address,
.ttl,
.sourceAddress
])[] | @tsv' <<<"$output")
}
output=$(curl "$edge_url/api/output/$id" \
--silent \
--get \
--cookie "$cookie_jar")
group=$(curl "$edge_url/api/group/$(jq --raw-output .group <<<"$output")" \
--silent \
--get \
--cookie "$cookie_jar")
input=$(curl "$edge_url/api/input/$(jq --raw-output .input <<<"$output")" \
--silent \
--get \
--cookie "$cookie_jar")
if [ "$(jq --raw-output .health.state <<<"$output")" == "allOk" ]; then
health="\e[32m✓\e[0m"
else
health="\e[31m✗\e[0m $(jq --raw-output .health.title <<<"$output")"
fi
cat <<EOF
ID: $(jq --raw-output .id <<<"$output")
Name: $(jq --raw-output .name <<<"$output")
Input: $(jq --raw-output .name <<<"$input")
Admin status: $(parse_admin_status "$(jq --raw-output .adminStatus <<<"$output")")
Redudancy: $(parse_redundancy "$(jq --raw-output .redundancyMode <<<"$output")")
Group: $(jq --raw-output .name <<<"$group")
Delay: $(jq --raw-output .delay <<<"$output")ms
Delay mode: $(parse_delay_mode "$(jq --raw-output .delayMode <<<"$output")")
Ports:
$(format_ports "$(jq --raw-output .ports <<<"$output")")
Alarms: $(jq --raw-output .alarms <<<"$output")
Appliances: $(jq --raw-output '.appliances | map(.name) | join(", ")' <<<"$output")
Misconfigured: $(jq --raw-output .misconfigured <<<"$output")
Created: $(jq --raw-output .createdAt <<<"$output")
Updated: $(jq --raw-output .updatedAt <<<"$output")
Health: $(echo -e "$health")
EOF