Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 1 | {{/* |
| 2 | # Copyright 2021-present Open Networking Foundation |
| 3 | |
| 4 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| 5 | */}} |
| 6 | |
| 7 | apiVersion: v1 |
| 8 | kind: ConfigMap |
| 9 | metadata: |
| 10 | name: "tost-telegraf-config-script" |
| 11 | labels: |
| 12 | chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" |
| 13 | release: "{{ .Release.Name }}" |
| 14 | app: tost-telegraf |
| 15 | data: |
Yi Tseng | 0e78d9d | 2021-10-21 18:15:03 -0700 | [diff] [blame] | 16 | sdfabric_telegraf.sh: | |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 17 | #!/bin/bash |
Yi Tseng | 3e5a15f | 2021-10-22 17:58:36 -0700 | [diff] [blame^] | 18 | # Install kubectl and jq |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 19 | curl -sLO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl |
Yi Tseng | 3e5a15f | 2021-10-22 17:58:36 -0700 | [diff] [blame^] | 20 | install -m 755 kubectl /usr/local/bin/kubectl |
| 21 | apt update |
| 22 | apt install -y jq |
| 23 | |
| 24 | # Utility for jq |
| 25 | cat <<EOF > ~/.jq |
| 26 | def count(s): reduce s as \$_ (0;.+1); |
| 27 | EOF |
| 28 | |
| 29 | get-onos-server() { |
| 30 | ONOS_SERVER={{ .Values.onos.server }} |
| 31 | CONTROLLERS=( $(kubectl get -n tost --output json pods | \ |
| 32 | jq '.items[] | select(.status.containerStatuses[].ready==true and .status.containerStatuses[].name=="onos-classic")' | \ |
| 33 | jq -r .status.podIP) ) |
| 34 | if (( ${#CONTROLLERS[@]} )); then |
| 35 | CONTROLLERS=( $(shuf -e "${CONTROLLERS[@]}") ) |
| 36 | ONOS_SERVER=${CONTROLLERS[0]} |
| 37 | fi |
| 38 | } |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 39 | |
| 40 | while IFS= read -r LINE; do |
Yi Tseng | 3e5a15f | 2021-10-22 17:58:36 -0700 | [diff] [blame^] | 41 | # Topology matrix |
| 42 | get-onos-server |
| 43 | ACTIVE_LINKS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy $ONOS_SERVER:{{ .Values.onos.port }} -X GET -H 'Accept: application/json' \ |
| 44 | http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/links | \ |
| 45 | jq 'count(.links[]?.state | select(. == "ACTIVE"))') |
| 46 | get-onos-server |
| 47 | DEVICES=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy $ONOS_SERVER:{{ .Values.onos.port }} -X GET -H 'Accept: application/json' \ |
| 48 | http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/devices | \ |
| 49 | jq 'count(.devices[]? | select(.available and .type=="SWITCH"))') |
| 50 | get-onos-server |
| 51 | ENABLE_DEVICE_PORTS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy $ONOS_SERVER:{{ .Values.onos.port }} -X GET -H 'Accept: application/json' \ |
| 52 | http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/devices/ports | \ |
| 53 | jq 'count(.ports[]?.isEnabled | select(.))') |
| 54 | ACTIVE_LINKS=${ACTIVE_LINKS:-0} |
| 55 | DEVICES=${DEVICES:-0} |
| 56 | ENABLED_DEVICE_PORTS=${ENABLED_DEVICE_PORTS:-0} |
| 57 | echo "onos_telegraf active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES}" |
| 58 | # Readiness for each ONOS instance and the config loader(overall readiness) |
| 59 | kubectl get po -n {{ .Values.onos.namespace }} -l '{{ .Values.onos.onos_classic_label }}' -o json | \ |
| 60 | jq -r '.items[]? | "onos_telegraf,pod=" + (.metadata.name) + " ready=" + (count(select(.status.containerStatuses[].ready)) | tostring)' |
| 61 | kubectl get po -n {{ .Values.onos.namespace }} -l '{{ .Values.onos.onos_config_loader_label }}' -o json | \ |
| 62 | jq -r '"onos_telegraf,pod=onos-config-loader ready=" + (count(select(.items[0].status.containerStatuses[].ready)) | tostring)' |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 63 | done |