blob: 055b50e09fc00db0d85ad2fb6092dc376af4e2f6 [file]
#!/bin/bash
set -eu
HELP_MSG="
Usage: power-rail-event-logger <event> <board>-<gpio_name>
<event> is the power rail event to log,
e.g. assert / deassert.
<board>-<gpio_name> is defined in json file,
e.g. Yosemite5_MB-ALERT_INA230_DIMM_0_N
"
if [ "$#" -ne 2 ]; then
echo "$HELP_MSG"
exit 1
fi
message="$2"
ASSERT_MSG_ID="xyz.openbmc_project.State.Power.PowerRailFault"
DEASSERT_MSG_ID="xyz.openbmc_project.State.Power.PowerRailFaultRecovered"
board="${message%%-*}"
gpio_name="${message#*-}"
device_path="/xyz/openbmc_project/inventory/system/board/${board}/${gpio_name}"
stash_file="/run/${message}.log_entry"
case "$1" in
assert)
if [ ! -s "$stash_file" ]; then
/usr/bin/log-create "$ASSERT_MSG_ID" --json \
"{ \"POWER_RAIL\": \"${device_path}\", \"FAILURE_DATA\": \"${gpio_name}\"}" \
> "${stash_file}"
fi
;;
deassert)
if [ -s "${stash_file}" ]; then
log-resolve -p "$(< "${stash_file}")" || true
rm -f "${stash_file}"
fi
/usr/bin/log-create "$DEASSERT_MSG_ID" --json \
"{ \"POWER_RAIL\": \"${device_path}\"}"
;;
*)
echo "Not supported event: $1" >&2
exit 1
;;
esac
exit 0