]>
Commit | Line | Data |
---|---|---|
d8f933bd | 1 | #!/bin/bash |
d8f933bd | 2 | |
64d41da7 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 | }' | |
d8f933bd | 14 | |
d8f933bd IB |
15 | url="<%= @naemon_url %>" |
16 | token="<%= @naemon_token %>" | |
64d41da7 | 17 | while getopts "u:t:H:s:S:o:" option |
d8f933bd IB |
18 | do |
19 | case $option in | |
20 | u) url=$OPTARG ;; | |
21 | t) token=$OPTARG ;; | |
64d41da7 IB |
22 | H) hostname=$OPTARG ;; |
23 | s) servicename=$OPTARG ;; | |
24 | S) state=$OPTARG ;; | |
d8f933bd | 25 | o) output=$OPTARG ;; |
d8f933bd IB |
26 | esac |
27 | done | |
28 | ||
64d41da7 IB |
29 | if [ -n "$servicename" ]; then |
30 | checktype="service" | |
31 | else | |
32 | checktype="host" | |
d8f933bd IB |
33 | fi |
34 | ||
64d41da7 IB |
35 | payload=$(jq -n \ |
36 | --arg type "$checktype" \ | |
37 | --arg hostname "$hostname" \ | |
38 | --arg servicename "$servicename" \ | |
39 | --arg output "$output" \ | |
40 | --arg token "$token" \ | |
41 | --arg state "$state" \ | |
42 | "$TEMPLATE") | |
d8f933bd | 43 | |
64d41da7 IB |
44 | rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url") |
45 | ret=$? | |
d8f933bd | 46 | |
64d41da7 IB |
47 | if [ $ret != 0 ];then |
48 | echo "ERROR: could not connect to NRDP server at $url" | |
49 | exit 1 | |
d8f933bd IB |
50 | fi |
51 | ||
64d41da7 IB |
52 | status=$(echo "$rslt" | jq -r .status) |
53 | message=$(echo "$rslt" | jq -r .message) | |
d8f933bd | 54 | |
64d41da7 IB |
55 | if [ "$status" != "ok" ];then |
56 | echo "ERROR: The NRDP Server said $message" | |
57 | exit 2 | |
d8f933bd | 58 | fi |
64d41da7 | 59 | echo "Sent 1 checks to $url" |