Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not get json data. #15

Open
chrisLeeTW opened this issue Apr 15, 2014 · 2 comments
Open

Can not get json data. #15

chrisLeeTW opened this issue Apr 15, 2014 · 2 comments
Labels

Comments

@chrisLeeTW
Copy link

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
Copy link

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

@domcleal domcleal added the bug label Apr 26, 2016
@bortek
Copy link

bortek commented Sep 26, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants