2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 #Counts how long slaves have been online or offline
16 curl -s "https://build.opnfv.org/ci/computer/api/json?tree=computer\[displayName,offline\]" \
17 | awk -v k=":" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' \
19 | awk 'NR%2{printf "%s ",$0;next;}1' \
20 | awk -F":" '{print $2,$3}' \
21 | awk '{print $1,$3}' \
27 curlcommand > /tmp/podoutput-current
29 declare -A slavescurrent
31 while read -r name status ; do
32 slavescurrent["$name"]="$status"
33 done < <(cat /tmp/podoutput-current)
35 #haste bin stopped allowing post :(
37 #for ((i=0; i<${#files[@]}; i+=9)); do
38 #./eplot -d -r [-1:74][-1:30] -m ${files[i]} ${files[i+1]} ${files[i+2]} ${files[i+3]} ${files[i+4]} ${files[i+5]} ${files[i+6]} ${files[i+7]} ${files[i+8]} ${files[i+9]}
43 for slavename in "${!slavescurrent[@]}"; do
45 #Slave is online. Mark it down.
46 if [ "${slavescurrent[$slavename]}" == "false" ]; then
48 if ! [ -f /tmp/"$slavename"-online ]; then
49 echo "1" > /tmp/"$slavename"-online
50 echo "new online slave file created $slavename ${slavescurrent[$slavename]} up for 1 iterations"
53 #read and increment slavename
54 var="$(cat /tmp/"$slavename"-online |tail -n 1)"
55 if [[ "$var" == "0" ]]; then
56 echo "slave $slavename ${slavescurrent[$slavename]} back up for $var iterations"
59 echo "$var" >> /tmp/"$slavename"-online
61 echo "$slavename up $(cat /tmp/$slavename-online | tail -n 10 | xargs)"
65 #slave is offline remove all points
66 if [ "${slavescurrent[$slavename]}" == "true" ]; then
67 if ! [ -f /tmp/"$slavename"-online ]; then
68 echo "0" > /tmp/"$slavename"-online
69 echo "new offline slave file created $slavename ${slavescurrent[$slavename]} up for 0 iterations"
72 var="$(cat /tmp/"$slavename"-online |tail -n 1)"
74 if [[ "$var" != "0" ]]; then
75 echo "slave $slavename ${slavescurrent[$slavename]} was up for $var iterations"
76 echo "slave $slavename ${slavescurrent[$slavename]} has gone offline, was $var iterations now reset to 0"
79 echo "0" >> /tmp/"$slavename"-online
80 echo "$slavename down $(cat /tmp/$slavename-online | tail -n 10 | xargs)"
89 main | sort | column -t