From 32e3167f805980aa806061947905e36db6599064 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Fri, 23 May 2025 11:49:10 +0200 Subject: [PATCH 1/2] Try a smarter usage script --- templates/script/usage.erb.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/templates/script/usage.erb.sh b/templates/script/usage.erb.sh index 89583b0..4f112df 100644 --- a/templates/script/usage.erb.sh +++ b/templates/script/usage.erb.sh @@ -3,16 +3,20 @@ date=$(date "+%Y%m%d") hdate=$(date "+%Y-%m-%d") htime=$(date "+%H:%M") -remotes=$(rclone listremotes | grep -E '^sto[3-4]') location="<%= @location %>" if [[ -n "${1}" ]]; then customer="${1}" - location="${customer}-<%= @environment %>" + location="${customer}-<%= @environment %>" allowmixedcustomers=yes else customer="<%= @customer %>" allowmixedcustomers=no fi +yaml="/etc/hiera/data/common.yaml" +remotes=($(yq -r ".project_mapping.${customer}.prod.primary_project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.prod.mirror_project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].mirror_project" ${yaml})) userjson=$(rclone cat --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies "statistics:drive-server-coms/${location}/users.json") users=$(echo ${userjson} | jq -r '.| keys | .[] | test("^((?!(^admin|^[_])).)*$")' | grep true | wc -l) outfile1="${customer}-${date}-detailed.csv" @@ -33,13 +37,13 @@ for remote in ${remotes}; do status=${?} if [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "no" ]]; then ((foundwrongcustomer += 1)) - echo "Found ${project}${bucket} not maching ${customer}" + echo "Found ${project}:${bucket} not maching ${customer}" continue elif [[ ${status} -ne 0 ]] && [[ "${allowmixedcustomers}" == "yes" ]]; then - echo "Found ${project}${bucket} not maching ${customer}" + echo "Found ${project}:${bucket} not maching ${customer}" continue fi - bucketinfo=$(rclone --config /root/.rclone.conf size "${project}${bucket}" --json) + bucketinfo=$(rclone --config /root/.rclone.conf size "${project}:${bucket}" --json) numfiles=$(jq '.count' <<<"${bucketinfo}") ((totalFiles += numfiles)) bytes=$(jq '.bytes' <<<"${bucketinfo}") From f56c5fb69231786f222c5beea97b9568845a481a Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Fri, 23 May 2025 12:08:52 +0200 Subject: [PATCH 2/2] Fix environment --- templates/script/usage.erb.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/script/usage.erb.sh b/templates/script/usage.erb.sh index 4f112df..4c8ea58 100644 --- a/templates/script/usage.erb.sh +++ b/templates/script/usage.erb.sh @@ -13,10 +13,10 @@ else allowmixedcustomers=no fi yaml="/etc/hiera/data/common.yaml" -remotes=($(yq -r ".project_mapping.${customer}.prod.primary_project" ${yaml})) -remotes+=($(yq -r ".project_mapping.${customer}.prod.mirror_project" ${yaml})) -remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].project" ${yaml})) -remotes+=($(yq -r ".project_mapping.${customer}.prod.assigned | .[].mirror_project" ${yaml})) +remotes=( $(yq -r ".project_mapping.${customer}.<% @=environment %>.primary_project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.<% @=environment %>.mirror_project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.<% @=environment %>.assigned | .[].project" ${yaml})) +remotes+=($(yq -r ".project_mapping.${customer}.<% @=environment %>.assigned | .[].mirror_project" ${yaml})) userjson=$(rclone cat --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies "statistics:drive-server-coms/${location}/users.json") users=$(echo ${userjson} | jq -r '.| keys | .[] | test("^((?!(^admin|^[_])).)*$")' | grep true | wc -l) outfile1="${customer}-${date}-detailed.csv"