Hi all!
Im working on foreman 3.6.2 and i’ve installed monitoring plugin and work great, also i’ve installed the hooks plugin and im trying to automate some process when the monitoring status of a host change, but not able to catch in the script the incoming event:
foreman log:
/var/log/foreman/production.log
2023-09-29T10:55:59 [I|app|09ec3fe1] Started POST "/api/v2/monitoring_results" for 192.168.91.123 at 2023-09-29 10:55:59 +0000
2023-09-29T10:55:59 [I|app|09ec3fe1] Processing by Api::V2::MonitoringResultsController#create as JSON
2023-09-29T10:55:59 [I|app|09ec3fe1] Parameters: {"result"=>2, "host"=>"foreman-dev-01.remotemanagement.internal", "service"=>"ram_status", "timestamp"=>1695984959.651513, "apiv"=>"v2", "monitoring_result"=>{"service"=>"ram_status", "result"=>2, "timestamp"=>1695984959.651513}}
2023-09-29T10:55:59 [I|app|09ec3fe1] Processing monitoring result for foreman-dev-01.remotemanagement.internal
2023-09-29T10:55:59 [I|app|09ec3fe1] Imported monitoring result for foreman-dev-01.remotemanagement.internal in 0.01 seconds
2023-09-29T10:55:59 [W|app|09ec3fe1] Unable to render Critical (HostStatus::MonitoringStatus) using RABL: Cannot find rabl template 'api/v2/hoststatus/monitoringstatuses/show' within registered (["/usr/share/foreman/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/foreman_puppet-5.1.2/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/foreman_monitoring-3.0.0/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/foreman_remote_execution-9.1.0/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/foreman-tasks-7.2.1/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/apipie-dsl-2.5.0/app/views", "/usr/share/foreman/vendor/ruby/2.7.0/gems/apipie-rails-0.8.2/app/views", "/usr/share/foreman/app/views"]) view paths!
2023-09-29T10:55:59 [I|app|09ec3fe1] Completed 200 OK in 44ms (Views: 0.2ms | ActiveRecord: 22.0ms | Allocations: 5258)
the bash script i testing
#!/bin/bash
HOOK_EVENT=$1
# to_s representation of the object, e.g. host's fqdn
HOOK_OBJECT=$2
HOOK_OBJECT_FILE=$(mktemp -t foreman_hooks.$RANDOM)
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
}
HOST_STATUS=$(hook_data)
echo $HOST_STATUS > /usr/share/foreman/change_monitoring.txt
echo $@ >> /usr/share/foreman/change_monitoring.txt
the file were the output is redirected contain :
after_update Critical
i’ve try to handling other event, example host/base/after_update and work fine, in the output file i see the expected json.
thanks in advance for support