| {{/* |
| # Copyright 2021-present Open Networking Foundation |
| |
| # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| */}} |
| |
| apiVersion: v1 |
| kind: ConfigMap |
| metadata: |
| name: "tost-telegraf-config-script" |
| labels: |
| chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" |
| release: "{{ .Release.Name }}" |
| app: tost-telegraf |
| data: |
| sdfabric_telegraf.sh: | |
| #!/bin/bash |
| # Install kubectl and jq |
| curl -sLO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl |
| install -m 755 kubectl /usr/local/bin/kubectl |
| apt update |
| apt install -y jq |
| |
| # Utility for jq |
| cat <<EOF > ~/.jq |
| def count(s): reduce s as \$_ (0;.+1); |
| EOF |
| |
| get-onos-server() { |
| ONOS_SERVER={{ .Values.onos.server }} |
| CONTROLLERS=( $(kubectl get -n tost --output json pods | \ |
| jq '.items[] | select(.status.containerStatuses[].ready==true and .status.containerStatuses[].name=="onos-classic")' | \ |
| jq -r .status.podIP) ) |
| if (( ${#CONTROLLERS[@]} )); then |
| CONTROLLERS=( $(shuf -e "${CONTROLLERS[@]}") ) |
| ONOS_SERVER=${CONTROLLERS[0]} |
| fi |
| } |
| |
| while IFS= read -r LINE; do |
| # Topology matrix |
| get-onos-server |
| ACTIVE_LINKS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy $ONOS_SERVER:{{ .Values.onos.port }} -X GET -H 'Accept: application/json' \ |
| http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/links | \ |
| jq 'count(.links[]?.state | select(. == "ACTIVE"))') |
| get-onos-server |
| DEVICES=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy $ONOS_SERVER:{{ .Values.onos.port }} -X GET -H 'Accept: application/json' \ |
| http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/devices | \ |
| jq 'count(.devices[]? | select(.available and .type=="SWITCH"))') |
| get-onos-server |
| 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' \ |
| http://$ONOS_SERVER:{{ .Values.onos.port }}/onos/v1/devices/ports | \ |
| jq 'count(.ports[]?.isEnabled | select(.))') |
| ACTIVE_LINKS=${ACTIVE_LINKS:-0} |
| DEVICES=${DEVICES:-0} |
| ENABLED_DEVICE_PORTS=${ENABLED_DEVICE_PORTS:-0} |
| echo "onos_telegraf active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES}" |
| # Readiness for each ONOS instance and the config loader(overall readiness) |
| kubectl get po -n {{ .Values.onos.namespace }} -l '{{ .Values.onos.onos_classic_label }}' -o json | \ |
| jq -r '.items[]? | "onos_telegraf,pod=" + (.metadata.name) + " ready=" + (count(select(.status.containerStatuses[].ready)) | tostring)' |
| kubectl get po -n {{ .Values.onos.namespace }} -l '{{ .Values.onos.onos_config_loader_label }}' -o json | \ |
| jq -r '"onos_telegraf,pod=onos-config-loader ready=" + (count(select(.items[0].status.containerStatuses[].ready)) | tostring)' |
| done |