]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - 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
d8f933bd 1#!/bin/bash
d8f933bd 2
64d41da7
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}'
d8f933bd 14
d8f933bd
IB
15url="<%= @naemon_url %>"
16token="<%= @naemon_token %>"
64d41da7 17while getopts "u:t:H:s:S:o:" option
d8f933bd
IB
18do
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
27done
28
64d41da7
IB
29if [ -n "$servicename" ]; then
30 checktype="service"
31else
32 checktype="host"
d8f933bd
IB
33fi
34
64d41da7
IB
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")
d8f933bd 43
64d41da7
IB
44rslt=$(curl -f --silent --insecure -d "$payload" -H "Content-Type: application/json" "$url")
45ret=$?
d8f933bd 46
64d41da7
IB
47if [ $ret != 0 ];then
48 echo "ERROR: could not connect to NRDP server at $url"
49 exit 1
d8f933bd
IB
50fi
51
64d41da7
IB
52status=$(echo "$rslt" | jq -r .status)
53message=$(echo "$rslt" | jq -r .message)
d8f933bd 54
64d41da7
IB
55if [ "$status" != "ok" ];then
56 echo "ERROR: The NRDP Server said $message"
57 exit 2
d8f933bd 58fi
64d41da7 59echo "Sent 1 checks to $url"