From cf0af4f078b3db217f7b9c5e2d46a2ccc426f4a6 Mon Sep 17 00:00:00 2001 From: shaowenchen Date: Fri, 13 Sep 2024 12:22:23 +0800 Subject: [PATCH] add task --- tasks/check-conn.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tasks/check-conn.yaml diff --git a/tasks/check-conn.yaml b/tasks/check-conn.yaml new file mode 100644 index 00000000..2a9c17d9 --- /dev/null +++ b/tasks/check-conn.yaml @@ -0,0 +1,27 @@ +apiVersion: crd.chenshaowen.com/v1 +kind: Task +metadata: + name: check-conn + namespace: ops-system +spec: + desc: check connection to specified hosts + typeRef: cluster + variables: + targets: + display: target hosts + example: 1.1.1.1,2.2.2.2 + command: + default: ping -c 2 $target + steps: + - name: Check connection + content: | + targets=$(echo "$targets" | awk -F, '{for (i=1; i<=NF; i++) print $i}') + for target in $targets; do + ${command} > /dev/null + if [ $? -eq 0 ]; then + echo "`hostname` -> $target is ok" + else + echo "`hostname` -> $target is not ok" + fi + done +