Feature #13441: Add support to install diagnostics scripts from microservices

This commit is contained in:
Amin Ben Romdhane 2024-01-29 18:50:07 +01:00
parent 33fd1809fc
commit fe8799d0b0
6 changed files with 73 additions and 40 deletions

View file

@ -54,10 +54,20 @@ IF(BBF_TR143)
INSTALL(DIRECTORY DESTINATION usr/share/bbfdm) INSTALL(DIRECTORY DESTINATION usr/share/bbfdm)
INSTALL(DIRECTORY DESTINATION usr/libexec/rpcd) INSTALL(DIRECTORY DESTINATION usr/libexec/rpcd)
FILE(GLOB scripts scripts/*) FILE(GLOB scripts scripts/*)
INSTALL(FILES ${scripts}
PERMISSIONS OWNER_EXECUTE FOREACH(script ${scripts})
DESTINATION usr/share/bbfdm IF(IS_DIRECTORY ${script})
) INSTALL(DIRECTORY ${script}
DESTINATION usr/share/bbfdm
)
ELSE()
INSTALL(FILES ${script}
PERMISSIONS OWNER_EXECUTE
DESTINATION usr/share/bbfdm
)
ENDIF()
ENDFOREACH()
INSTALL(FILES scripts/bbf.diag INSTALL(FILES scripts/bbf.diag
PERMISSIONS OWNER_EXECUTE PERMISSIONS OWNER_EXECUTE
DESTINATION usr/libexec/rpcd DESTINATION usr/libexec/rpcd

View file

@ -1,32 +1,37 @@
#!/bin/sh #!/bin/sh
BBF_SCRIPTS="/usr/share/bbfdm" BBF_DIAG_SCRIPTS="/usr/share/bbfdm/bbf_diag"
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
case "$1" in case "$1" in
list) list)
echo '{ "ipping" : { "host": "str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "proto": "str" }, # Open the JSON object
"nslookup" : { "host": "str", "dns_serevr": "str", "iface": "str", "nbr_of_rep": "str", "timeout": "str", "proto": "str" }, output_json="{"
"udpecho" : { "host": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "inter_trans_time":"str", "proto": "str" },
"serverselection" : { "hostlist": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "protocol_used": "str", "proto": "str" }, first_iteration=true
}'
for file in "${BBF_DIAG_SCRIPTS}"/*; do
[ -f "${file}" ] || continue
file_output=$(sh "${file}" "$1")
# Add a comma for all iterations after the first one
[ "$first_iteration" = true ] || output_json="${output_json},"
first_iteration=false
# Concatenate the output to the result
output_json="${output_json}${file_output}"
done
# Close the JSON object
output_json="${output_json}}"
# Return the concatenated JSON output
echo "$output_json"
;; ;;
call) call)
# read the arguments # Read the arguments
read -r input read -r input
case "$2" in sh "${BBF_DIAG_SCRIPTS}/${2}" "${input}"
ipping)
sh ${BBF_SCRIPTS}/ipping "${input}"
;;
nslookup)
sh ${BBF_SCRIPTS}/nslookup "${input}"
;;
udpecho)
sh ${BBF_SCRIPTS}/udpecho "${input}"
;;
serverselection)
sh ${BBF_SCRIPTS}/serverselection "${input}"
;;
esac
;; ;;
esac esac

View file

@ -5,8 +5,11 @@
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")" . "$(dirname "${0}")/../bbf_api"
. "${ROOT}"/bbf_api
ipping_list() {
echo '"ipping" : { "host": "str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "proto": "str" }'
}
ipping_error() { ipping_error() {
json_init json_init
@ -157,7 +160,9 @@ ipping_launch() {
} }
} }
if [ -n "$1" ]; then if [ "$1" = "list" ]; then
ipping_list
elif [ -n "$1" ]; then
ipping_launch "$1" ipping_launch "$1"
else else
ipping_error "Error_Internal" "1" ipping_error "Error_Internal" "1"

View file

@ -4,8 +4,7 @@
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")" . "$(dirname "${0}")/../bbf_api"
. "${ROOT}"/bbf_api
get_nslookup_log_file() { get_nslookup_log_file() {
IDX=1 IDX=1
@ -19,6 +18,10 @@ get_nslookup_log_file() {
echo ${LOG_FILE} echo ${LOG_FILE}
} }
nslookup_list() {
echo '"nslookup" : { "host": "str", "dns_serevr": "str", "iface": "str", "nbr_of_rep": "str", "timeout": "str", "proto": "str" }'
}
nslookup_error() { nslookup_error() {
json_init json_init
json_add_string "Status" "$1" json_add_string "Status" "$1"
@ -166,8 +169,9 @@ nslookup_launch() {
} }
} }
if [ "$1" = "list" ]; then
if [ -n "$1" ]; then nslookup_list
elif [ -n "$1" ]; then
nslookup_launch "$1" nslookup_launch "$1"
else else
nslookup_error "Error_Internal" nslookup_error "Error_Internal"

View file

@ -4,8 +4,11 @@
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")" . "$(dirname "${0}")/../bbf_api"
. "${ROOT}"/bbf_api
serverselection_list() {
echo '"serverselection" : { "hostlist": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "protocol_used": "str", "proto": "str" }'
}
serverselection_error() { serverselection_error() {
json_init json_init
@ -183,7 +186,9 @@ serverselection_launch() {
} }
} }
if [ -n "$1" ]; then if [ "$1" = "list" ]; then
serverselection_list
elif [ -n "$1" ]; then
serverselection_launch "$1" serverselection_launch "$1"
else else
serverselection_error "Error_Internal" "1" serverselection_error "Error_Internal" "1"

View file

@ -4,11 +4,13 @@
. /usr/share/libubox/jshn.sh . /usr/share/libubox/jshn.sh
ROOT="$(dirname "${0}")" . "$(dirname "${0}")/../bbf_api"
. "${ROOT}"/bbf_api
udpecho_error() udpecho_list() {
{ echo '"udpecho" : { "host": "str", "port":"str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "inter_trans_time":"str", "proto": "str" }'
}
udpecho_error() {
json_init json_init
json_add_string "Status" "$1" json_add_string "Status" "$1"
json_add_string "IPAddressUsed" "" json_add_string "IPAddressUsed" ""
@ -139,7 +141,9 @@ udpecho_launch() {
} }
} }
if [ -n "$1" ]; then if [ "$1" = "list" ]; then
udpecho_list
elif [ -n "$1" ]; then
udpecho_launch "$1" udpecho_launch "$1"
else else
udpecho_error "Error_Internal" "1" udpecho_error "Error_Internal" "1"