51 lines
2.1 KiB
YAML
51 lines
2.1 KiB
YAML
apiVersion: batch/v1
|
|
kind: CronJob
|
|
metadata:
|
|
name: nxtgauge-openobserve-endpoint-monitor
|
|
namespace: nxtgauge
|
|
spec:
|
|
schedule: "*/1 * * * *"
|
|
concurrencyPolicy: Forbid
|
|
successfulJobsHistoryLimit: 1
|
|
failedJobsHistoryLimit: 3
|
|
jobTemplate:
|
|
spec:
|
|
template:
|
|
spec:
|
|
restartPolicy: OnFailure
|
|
containers:
|
|
- name: endpoint-monitor
|
|
image: curlimages/curl:8.10.1
|
|
imagePullPolicy: IfNotPresent
|
|
envFrom:
|
|
- secretRef:
|
|
name: nxtgauge-openobserve-endpoint-monitor-secret
|
|
command: ["/bin/sh", "-ec"]
|
|
args:
|
|
- |
|
|
post_result() {
|
|
name="$1"
|
|
url="$2"
|
|
checked_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
out="$(curl -sS -o /dev/null -w '%{http_code} %{time_total}' --max-time 15 "$url" || true)"
|
|
code="$(printf '%s' "$out" | awk '{print $1}')"
|
|
total="$(printf '%s' "$out" | awk '{print $2}')"
|
|
[ -n "$code" ] || code="0"
|
|
[ -n "$total" ] || total="0"
|
|
latency_ms="$(awk "BEGIN { printf \"%.0f\", $total * 1000 }")"
|
|
if [ "$code" -ge 200 ] && [ "$code" -lt 400 ]; then
|
|
ok="true"
|
|
else
|
|
ok="false"
|
|
fi
|
|
payload="$(printf '[{"endpoint":"%s","url":"%s","status_code":%s,"ok":%s,"latency_ms":%s,"checked_at":"%s"}]' "$name" "$url" "$code" "$ok" "$latency_ms" "$checked_at")"
|
|
curl -sS -X POST \
|
|
"${OO_ENDPOINT}/api/${OO_ORG}/${OO_STREAM}/_json" \
|
|
-H "Authorization: ${OO_AUTH_HEADER}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload" >/dev/null
|
|
}
|
|
|
|
post_result "frontend" "https://test111.nxtgauge.com/"
|
|
post_result "admin" "https://admin.nxtgauge.com/"
|
|
post_result "api-health" "https://api.nxtgauge.com/health"
|