blob: 908f04f0bc9d967e6c4db2e3e90e35d744945252 [file] [log] [blame]
Hung-Wei Chiue3c15972021-04-28 15:52:09 -07001{{/*
2# Copyright 2021-present Open Networking Foundation
3
4# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
5*/}}
6
7apiVersion: v1
8kind: ConfigMap
9metadata:
10 name: "tost-telegraf-config-script"
11 labels:
12 chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
13 release: "{{ .Release.Name }}"
14 app: tost-telegraf
15data:
Yi Tseng0e78d9d2021-10-21 18:15:03 -070016 sdfabric_telegraf.sh: |
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070017 #!/bin/bash
Yi Tseng3e5a15f2021-10-22 17:58:36 -070018 # Install kubectl and jq
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070019 curl -sLO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl
Yi Tseng3e5a15f2021-10-22 17:58:36 -070020 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 Chiue3c15972021-04-28 15:52:09 -070039
40 while IFS= read -r LINE; do
Yi Tseng3e5a15f2021-10-22 17:58:36 -070041 # 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 Chiue3c15972021-04-28 15:52:09 -070063 done