aboutsummaryrefslogtreecommitdiff
path: root/modules/profile/templates/monitoring/send_nrdp.sh.erb
blob: 0e3890881cf7c9d84d1f453ee1b2c6bda739f37a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

TEMPLATE='{
  "cmd": "submitcheck",
  "token": $token,
  "checkresult": [{
    "hostname": $hostname,
    "state": $state,
    "output": $output,
    "type": $type,
    "servicename": $servicename
  }]
}'

url="<%= @naemon_url %>"
token="<%= @naemon_token %>"
while getopts "u:t:H:s:S:o:" option
do
  case $option in
    u) url=$OPTARG ;;
    t) token=$OPTARG ;;
    H) hostname=$OPTARG ;;
    s) servicename=$OPTARG ;;
    S) state=$OPTARG ;;
    o) output=$OPTARG ;;
  esac
done

if [ -n "$servicename" ]; then
  checktype="service"
else
  checktype="host"
fi

payload=$(jq -n \
   --arg type "$checktype" \
   --arg hostname "$hostname" \
   --arg servicename "$servicename" \
   --arg output "$output" \
   --arg token "$token" \
   --arg state "$state" \
   "$TEMPLATE")

rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url")
ret=$?

if [ $ret != 0 ];then
  echo "ERROR: could not connect to NRDP server at $url"
  exit 1
fi

status=$(echo "$rslt" | jq -r .status)
message=$(echo "$rslt" | jq -r .message)

if [ "$status" != "ok" ];then
  echo "ERROR: The NRDP Server said $message"
  exit 2
fi
echo "Sent 1 checks to $url"