theforeman / foreman_hooks

Run custom hook scripts on Foreman events
http://m0dlx.com/blog/Extending_Foreman_quickly_with_hook_scripts.html
GNU General Public License v3.0
56 stars 50 forks source link

Can not get json data. #15

Open chrisLeeTW opened 10 years ago

chrisLeeTW commented 10 years ago

my foreman version = 1.4.2

and i already tested foreman_hooks tag = 0.3.4 & 0.3.7

and also reference hook_functions.sh & jgrep ruby gem already installed.

but I can not get json data, here is my hook script.

#!/bin/bash

HOOK_EVENT=$1
HOOK_OBJECT=$2
HOOK_OBJECT_FILE=$(mktemp -t foreman_hooks.XXXXXXXXXX)
trap "rm -f $HOOK_OBJECT_FILE" EXIT
cat > $HOOK_OBJECT_FILE

hook_data() {
  if [ $# -eq 1 ]; then
    jgrep -s "$1" < $HOOK_OBJECT_FILE
  else
    jgrep "$*" < $HOOK_OBJECT_FILE
  fi
}

echo "current path = $(dirname $0)" >> /tmp/hook.log

# event name (create, before_destroy etc.)
# orchestration hooks must obey this to support rollbacks (create/update/destroy)
event=${HOOK_EVENT}

# to_s representation of the object, e.g. host's fqdn
object=${HOOK_OBJECT}

# Example of using hook_data to query the JSON representation of the object
# passed by foreman_hooks.  `cat $HOOK_OBJECT_FILE` to see the contents.
hostname=$(hook_data host.name)

echo "$(date): received ${event} on ${object}" >> /tmp/hook.log
echo "hostname = ${hostname}" >> /tmp/hook.log

# exit code is important on orchestration tasks
exit 0

I can correct get $event & $object variable in output log. but my $hostname is always empty.

is it a bug? or just my mismatch configuration?

soumentrivedi commented 9 years ago

hi @chrisLeeTW did you get any resolution for this? I am also getting the same issue with Foreman v1.6 and not getting any JSON data

bortek commented 7 years ago

Any updates on this? I have the same issue here.