From fe8799d0b06dc7a2a8058ba6444f87c59b089f22 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Mon, 29 Jan 2024 18:50:07 +0100 Subject: [PATCH] Feature #13441: Add support to install diagnostics scripts from microservices --- libbbfdm/CMakeLists.txt | 18 +++++-- libbbfdm/scripts/bbf.diag | 47 ++++++++++--------- libbbfdm/scripts/{ => bbf_diag}/ipping | 11 +++-- libbbfdm/scripts/{ => bbf_diag}/nslookup | 12 +++-- .../scripts/{ => bbf_diag}/serverselection | 11 +++-- libbbfdm/scripts/{ => bbf_diag}/udpecho | 14 ++++-- 6 files changed, 73 insertions(+), 40 deletions(-) rename libbbfdm/scripts/{ => bbf_diag}/ipping (95%) rename libbbfdm/scripts/{ => bbf_diag}/nslookup (95%) rename libbbfdm/scripts/{ => bbf_diag}/serverselection (95%) rename libbbfdm/scripts/{ => bbf_diag}/udpecho (93%) diff --git a/libbbfdm/CMakeLists.txt b/libbbfdm/CMakeLists.txt index 46ac54bc..b64e91ba 100644 --- a/libbbfdm/CMakeLists.txt +++ b/libbbfdm/CMakeLists.txt @@ -54,10 +54,20 @@ IF(BBF_TR143) INSTALL(DIRECTORY DESTINATION usr/share/bbfdm) INSTALL(DIRECTORY DESTINATION usr/libexec/rpcd) FILE(GLOB scripts scripts/*) - INSTALL(FILES ${scripts} - PERMISSIONS OWNER_EXECUTE - DESTINATION usr/share/bbfdm - ) + + FOREACH(script ${scripts}) + 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 PERMISSIONS OWNER_EXECUTE DESTINATION usr/libexec/rpcd diff --git a/libbbfdm/scripts/bbf.diag b/libbbfdm/scripts/bbf.diag index e459e6a5..a8c7a05e 100755 --- a/libbbfdm/scripts/bbf.diag +++ b/libbbfdm/scripts/bbf.diag @@ -1,32 +1,37 @@ #!/bin/sh -BBF_SCRIPTS="/usr/share/bbfdm" +BBF_DIAG_SCRIPTS="/usr/share/bbfdm/bbf_diag" . /usr/share/libubox/jshn.sh case "$1" in list) - echo '{ "ipping" : { "host": "str", "iface": "str", "ip_proto": "str", "nbr_of_rep": "str", "timeout": "str", "data_size": "str", "dscp": "str", "proto": "str" }, - "nslookup" : { "host": "str", "dns_serevr": "str", "iface": "str", "nbr_of_rep": "str", "timeout": "str", "proto": "str" }, - "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" }, - }' + # Open the JSON object + output_json="{" + + 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) - # read the arguments + # Read the arguments read -r input - case "$2" in - 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 + sh "${BBF_DIAG_SCRIPTS}/${2}" "${input}" ;; esac diff --git a/libbbfdm/scripts/ipping b/libbbfdm/scripts/bbf_diag/ipping similarity index 95% rename from libbbfdm/scripts/ipping rename to libbbfdm/scripts/bbf_diag/ipping index 18171a25..057ada1f 100755 --- a/libbbfdm/scripts/ipping +++ b/libbbfdm/scripts/bbf_diag/ipping @@ -5,8 +5,11 @@ . /usr/share/libubox/jshn.sh -ROOT="$(dirname "${0}")" -. "${ROOT}"/bbf_api +. "$(dirname "${0}")/../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() { 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" else ipping_error "Error_Internal" "1" diff --git a/libbbfdm/scripts/nslookup b/libbbfdm/scripts/bbf_diag/nslookup similarity index 95% rename from libbbfdm/scripts/nslookup rename to libbbfdm/scripts/bbf_diag/nslookup index a6729186..eaacf0f3 100755 --- a/libbbfdm/scripts/nslookup +++ b/libbbfdm/scripts/bbf_diag/nslookup @@ -4,8 +4,7 @@ . /usr/share/libubox/jshn.sh -ROOT="$(dirname "${0}")" -. "${ROOT}"/bbf_api +. "$(dirname "${0}")/../bbf_api" get_nslookup_log_file() { IDX=1 @@ -19,6 +18,10 @@ get_nslookup_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() { json_init json_add_string "Status" "$1" @@ -166,8 +169,9 @@ nslookup_launch() { } } - -if [ -n "$1" ]; then +if [ "$1" = "list" ]; then + nslookup_list +elif [ -n "$1" ]; then nslookup_launch "$1" else nslookup_error "Error_Internal" diff --git a/libbbfdm/scripts/serverselection b/libbbfdm/scripts/bbf_diag/serverselection similarity index 95% rename from libbbfdm/scripts/serverselection rename to libbbfdm/scripts/bbf_diag/serverselection index a6c508b2..9ea4cef0 100755 --- a/libbbfdm/scripts/serverselection +++ b/libbbfdm/scripts/bbf_diag/serverselection @@ -4,8 +4,11 @@ . /usr/share/libubox/jshn.sh -ROOT="$(dirname "${0}")" -. "${ROOT}"/bbf_api +. "$(dirname "${0}")/../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() { 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" else serverselection_error "Error_Internal" "1" diff --git a/libbbfdm/scripts/udpecho b/libbbfdm/scripts/bbf_diag/udpecho similarity index 93% rename from libbbfdm/scripts/udpecho rename to libbbfdm/scripts/bbf_diag/udpecho index 14b6c267..95acb8be 100755 --- a/libbbfdm/scripts/udpecho +++ b/libbbfdm/scripts/bbf_diag/udpecho @@ -4,11 +4,13 @@ . /usr/share/libubox/jshn.sh -ROOT="$(dirname "${0}")" -. "${ROOT}"/bbf_api +. "$(dirname "${0}")/../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_add_string "Status" "$1" 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" else udpecho_error "Error_Internal" "1"