blob: 7c5652bba4690acd773f05759d75f4d437d6182c [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
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
Yi Tseng0e78d9d2021-10-21 18:15:03 -070037 ONOS_PODS=$(kubectl get po -l app=onos-classic -o name)
38 for POD in $ONOS_PODS; do
39 ONOS_READY=$(kubectl -n {{ .Values.onos.namespace }} get ${POD} --no-headers -o custom-columns=':.status.containerStatuses[*].ready' | grep true | wc -l)
40 echo "onos_telegraf,type=onos,onos_pod=${POD} ready=${ONOS_READY}"
41 done
Hung-Wei Chiu9e5acb12021-05-19 11:32:27 -070042 # Config Pod's ready status indicate the status of ONOS cluster
43 # Assumption: Config Pod has only one instance
Yi Tseng3674e492021-10-19 15:35:27 -070044 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)
Yi Tseng0e78d9d2021-10-21 18:15:03 -070045 echo "onos_telegraf,type=cluster active_links=${ACTIVE_LINKS},enable_device_ports=${ENABLE_DEVICE_PORTS},devices=${DEVICES},ready=${ONOS_READY}"
Hung-Wei Chiue3c15972021-04-28 15:52:09 -070046 done