From 76538d4eebc4292a06c7e8e3914268543227e72e Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 10 Mar 2019 02:28:53 +0000 Subject: [PATCH] etc/profile.d/nb.sh --- bin/nb-update | 2 +- etc/profile.d/nb.sh | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/bin/nb-update b/bin/nb-update index 4967d5fa..4c07af56 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -137,7 +137,7 @@ rm -f /tmp/$NAME.infos /tmp/$NAME.check /run/$NAME-nb_post_sys_infos.lock find /run/$NAME-nb_api_post_sys_infos.lock -mmin +60 -exec rm {} \; >/dev/null 2>&1 if [ ! -e /run/$NAME-nb_api_post_sys_infos.lock ]; then touch /run/$NAME-nb_api_post_sys_infos.lock - nb_api_post_sys_infos 2>/dev/null + nb_api_post_hosts_infos 2>/dev/null fi ##################################################################### diff --git a/etc/profile.d/nb.sh b/etc/profile.d/nb.sh index 577744fd..98f99319 100644 --- a/etc/profile.d/nb.sh +++ b/etc/profile.d/nb.sh @@ -98,34 +98,32 @@ nb_api_table_post() { local debug=0; [ "$1" = "-debug" ] && debug=1 && shift local table="${1:?$usage}"; shift - local curl="nb_api /data/$table/replace.sh" - - local args="$*" + local args=() while [ "$#" -gt "0" ]; do - curl="$curl -d \"$1\"" + args+=(-d) + args+=("$1") shift done - if [ "$debug" = "1" ]; then - echo "$curl"; return - fi - eval "$(eval "$curl")" #&& echo "$table: $rowCount: $args" -# NB 15.02.19 ( -# NB 15.02.19 eval "$(eval "$curl")" #&& echo "$table: $rowCount: $args" -# NB 15.02.19 #eval "$curl" #&& echo "$table: $rowCount: $args" -# NB 15.02.19 ) -} -nb_api_post_sys_infos() { - # To be compatible with other sed that does not support \t - sys_infos | while read -ra i; do - nb_api_post_host_info "sys.${i[0]}" "${i[1]}" - done + nb_api /data/$table/replace.sh "${args[@]}" } nb_api_post_host_info() { + [ $# = 0 ] && echo "Usage: nb_api_post_host_info key=? val=?" && return 1 local host=$(hostname) - [ -z "$*" ] && echo "Usage: nb_api_post_host_info key=? val=?" && return 1 [ -z "$host" ] && host=$(hostname -f) - nb_api_table_post host_info "host=$host" "key=$1" "val=$2" - #nb_api_table_post host_info "host=$host" "$@" + nb_api_table_post host_info "host=$host" "key=$1" "val=${i[*]:1}" +} + +nb_api_post_hosts_infos() { + sys_infos | while read -ra i; do + nb_api_post_host_info "sys.${i[0]}" "${i[*]:1}" + done + + which lshw > /dev/null && lshw -quiet -class system \ + | awk '/^ /{sub("^ *","",$0); sub(": ","\t",$0); print $0}' \ + | while read -ra i \ + ; do + nb_api_post_host_info "sys.${i[0]}" "${i[*]:1}" + done } -- 2.47.3