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: |
| 16 | tost_telegraf.sh: | |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 17 | #!/bin/bash |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 18 | set -x |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 19 | #Locale setting for json_pp |
| 20 | export LC_CTYPE="POSIX" |
| 21 | export LC_NUMERIC="POSIX" |
| 22 | |
| 23 | #Install kubectl |
| 24 | curl -sLO https://dl.k8s.io/release/v1.21.0/bin/linux/amd64/kubectl |
| 25 | install -m 755 kubectl /usr/local/bin/kubectl |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 26 | |
| 27 | while IFS= read -r LINE; do |
| 28 | ACTIVE_LINKS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 29 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/links | json_pp | grep "\"state\" : \"ACTIVE\"" | wc -l) |
| 30 | |
| 31 | ENABLE_DEVICE_PORTS=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 32 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices/ports | json_pp | grep "\"isEnabled\" : true" | wc -l) |
| 33 | |
| 34 | DEVICES=$(curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} --noproxy {{ .Values.onos.server }} -X GET -H 'Accept: application/json' \ |
| 35 | http://{{ .Values.onos.server }}:{{ .Values.onos.port }}/onos/v1/devices | json_pp | grep "\"type\" : \"SWITCH\"" | wc -l) |
| 36 | |
Hung-Wei Chiu | 9e5acb1 | 2021-05-19 11:32:27 -0700 | [diff] [blame] | 37 | # Config Pod's ready status indicate the status of ONOS cluster |
| 38 | # Assumption: Config Pod has only one instance |
| 39 | ONOS_READY=$(kubectl -n {{ .Values.onos.namespace }} get pods -lcomponent={{ .Values.onos.component_label }} --no-headers -o custom-columns=':.status.containerStatuses[*].ready' | grep true | wc -l) |
| 40 | echo "onos_telegraf active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES},ready=${ONOS_READY}" |
Hung-Wei Chiu | e3c1597 | 2021-04-28 15:52:09 -0700 | [diff] [blame] | 41 | done |