blob: 28e861fc21dd129c7c8b25dbb9955ac4beca1771 [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:
16 tost_telegraf.sh: |
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070017 #!/bin/bash
Hung-Wei Chiue3c15972021-04-28 15:52:09 -070018 set -x
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070019 #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 Chiue3c15972021-04-28 15:52:09 -070026
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 Chiu9e5acb12021-05-19 11:32:27 -070037 # Config Pod's ready status indicate the status of ONOS cluster
38 # Assumption: Config Pod has only one instance
Yi Tseng3674e492021-10-19 15:35:27 -070039 ONOS_READY=$(kubectl -n {{ .Values.onos.namespace }} get pods -l {{ .Values.onos.component_label }} --no-headers -o custom-columns=':.status.containerStatuses[*].ready' | grep true | wc -l)
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070040 echo "onos_telegraf active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES},ready=${ONOS_READY}"
Hung-Wei Chiue3c15972021-04-28 15:52:09 -070041 done