]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame_incremental - modules/profile/templates/monitoring/send_nrdp.sh.erb
Use json for send_nrdp
[perso/Immae/Projets/Puppet.git] / modules / profile / templates / monitoring / send_nrdp.sh.erb
... / ...
CommitLineData
1#!/bin/bash
2
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
15url="<%= @naemon_url %>"
16token="<%= @naemon_token %>"
17while getopts "u:t:H:s:S:o:" option
18do
19 case $option in
20 u) url=$OPTARG ;;
21 t) token=$OPTARG ;;
22 H) hostname=$OPTARG ;;
23 s) servicename=$OPTARG ;;
24 S) state=$OPTARG ;;
25 o) output=$OPTARG ;;
26 esac
27done
28
29if [ -n "$servicename" ]; then
30 checktype="service"
31else
32 checktype="host"
33fi
34
35payload=$(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")
43
44rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url")
45ret=$?
46
47if [ $ret != 0 ];then
48 echo "ERROR: could not connect to NRDP server at $url"
49 exit 1
50fi
51
52status=$(echo "$rslt" | jq -r .status)
53message=$(echo "$rslt" | jq -r .message)
54
55if [ "$status" != "ok" ];then
56 echo "ERROR: The NRDP Server said $message"
57 exit 2
58fi
59echo "Sent 1 checks to $url"