]>
Commit | Line | Data |
---|---|---|
3bc32d9e | 1 | #!/bin/bash |
3bc32d9e | 2 | |
b11f0e17 IB |
3 | TEMPLATE='{ |
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 | ||
15 | while getopts "u:t:H:s:S:o:" option | |
3bc32d9e IB |
16 | do |
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 |
25 | done | |
26 | ||
b11f0e17 IB |
27 | if [ -n "$servicename" ]; then |
28 | checktype="service" | |
29 | else | |
30 | checktype="host" | |
3bc32d9e IB |
31 | fi |
32 | ||
b11f0e17 IB |
33 | payload=$(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 |
42 | rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url") |
43 | ret=$? | |
3bc32d9e | 44 | |
b11f0e17 IB |
45 | if [ $ret != 0 ];then |
46 | echo "ERROR: could not connect to NRDP server at $url" | |
47 | exit 1 | |
3bc32d9e IB |
48 | fi |
49 | ||
b11f0e17 IB |
50 | status=$(echo "$rslt" | jq -r .status) |
51 | message=$(echo "$rslt" | jq -r .message) | |
3bc32d9e | 52 | |
b11f0e17 IB |
53 | if [ "$status" != "ok" ];then |
54 | echo "ERROR: The NRDP Server said $message" | |
55 | exit 2 | |
3bc32d9e | 56 | fi |
b11f0e17 | 57 | echo "Sent 1 checks to $url" |