]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - flakes/private/monitoring/plugins/send_nrdp.sh
Squash changes containing private information
[perso/Immae/Config/Nix.git] / flakes / private / monitoring / plugins / send_nrdp.sh
CommitLineData
3bc32d9e 1#!/bin/bash
3bc32d9e 2
b11f0e17
IB
3TEMPLATE='{
4 "cmd": "submitcheck",
5 "token": $token,
6 "checkresult": [{
7 "hostname": $hostname,
8 "state": $state,
9 "output": $output,
10 "type": $type,
11 "servicename": $servicename
12 }]
13}'
14
15while getopts "u:t:H:s:S:o:" option
3bc32d9e
IB
16do
17 case $option in
18 u) url=$OPTARG ;;
19 t) token=$OPTARG ;;
b11f0e17
IB
20 H) hostname=$OPTARG ;;
21 s) servicename=$OPTARG ;;
22 S) state=$OPTARG ;;
3bc32d9e 23 o) output=$OPTARG ;;
3bc32d9e
IB
24 esac
25done
26
b11f0e17
IB
27if [ -n "$servicename" ]; then
28 checktype="service"
29else
30 checktype="host"
3bc32d9e
IB
31fi
32
b11f0e17
IB
33payload=$(jq -n \
34 --arg type "$checktype" \
35 --arg hostname "$hostname" \
36 --arg servicename "$servicename" \
37 --arg output "$output" \
38 --arg token "$token" \
39 --arg state "$state" \
40 "$TEMPLATE")
3bc32d9e 41
b11f0e17
IB
42rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url")
43ret=$?
3bc32d9e 44
b11f0e17
IB
45if [ $ret != 0 ];then
46 echo "ERROR: could not connect to NRDP server at $url"
47 exit 1
3bc32d9e
IB
48fi
49
b11f0e17
IB
50status=$(echo "$rslt" | jq -r .status)
51message=$(echo "$rslt" | jq -r .message)
3bc32d9e 52
b11f0e17
IB
53if [ "$status" != "ok" ];then
54 echo "ERROR: The NRDP Server said $message"
55 exit 2
3bc32d9e 56fi
b11f0e17 57echo "Sent 1 checks to $url"