blob: 6469652e78e368cfa8859db1265ed134b73437b3 [file] [log] [blame]
#!/usr/bin/env bash
declare -rx TYPE_FAULTDATA="faultdata"
#Dump originator variables
declare -x ORIGINATOR_TYPE=""
declare -x ORIGINATOR_ID=""
# @brief fetch serial number
# @param serial number
function fetch_serial_number() {
serialNo=$(busctl get-property xyz.openbmc_project.Inventory.Manager \
/xyz/openbmc_project/inventory/system xyz.openbmc_project.Inventory.Decorator.Asset \
SerialNumber | cut -d " " -f 2 | sed "s/^\(\"\)\(.*\)\1\$/\2/g")
if [ -z "$serialNo" ]; then
serialNo="0000000"
fi
}
# @brief Add BMC dump File Name
# @param BMC Dump File Name
function get_bmc_dump_filename() {
fetch_serial_number
dump_id=$(printf %08d $dump_id)
if [ $dump_type = "$TYPE_FAULTDATA" ]; then
header_dump_name="FLTDUMP"
name="NAGDUMP.${serialNo}.${dump_id}.${dDay}"
else
header_dump_name="BMCDUMP"
name="BMCDUMP.${serialNo}.${dump_id}.${dDay}"
fi
}
# @brief Function to get the Originator details
# @param Originator Type and Originator ID
function get_originator_details() {
if [ -z "$dump_dir" ]; then
return
fi
dump_type_received=""
dump_entry_id="$dump_id"
if [ "$1" = "bmc" ] || [ "$1" = "system" ]; then
dump_type_received="$1"
else
echo "Invalid dump type received"
return
fi
if [ "$dump_type_received" = "bmc" ]; then
dump_entry_id=$(echo "$dump_entry_id" | sed "s/^0*//")
fi
local DBUS_DUMP_MANAGER="xyz.openbmc_project.Dump.Manager"
local DBUS_DUMP_PATH="/xyz/openbmc_project/dump/$dump_type_received/entry/$dump_entry_id"
local DBUS_DUMP_ORIGINATOR_IFACE="xyz.openbmc_project.Common.OriginatedBy"
local DBUS_ORIGINATOR_TYPE_STRING="OriginatorType"
local DBUS_ORIGINATOR_ID_STRING="OriginatorId"
ORIGINATOR_TYPE=$(busctl get-property "$DBUS_DUMP_MANAGER" \
"$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \
"$DBUS_ORIGINATOR_TYPE_STRING")
ORIGINATOR_ID=$(busctl get-property "$DBUS_DUMP_MANAGER" \
"$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \
"$DBUS_ORIGINATOR_ID_STRING")
# The following two lines would extract the originator type and id
# from the received long string in response of the above dbus calls
# like <s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal">
# to only <Internal> for the originator type and so on for the originator ID
ORIGINATOR_TYPE=$(echo "$ORIGINATOR_TYPE" | cut -d' ' -f 2 \
| cut -d'.' -f 6 | cut -d'"' -f 1)
ORIGINATOR_ID=$(echo "$ORIGINATOR_ID" | cut -d' ' -f 2 \
| cut -d'"' -f 2)
# This hash map for Originator Type is populated based on
# the info provided by the OriginatedBy.interface.yaml file under
# https://github.com/openbmc/phosphor-dbus-interfaces/
# Feel free to amend the table as per the evolving requirement
local -A originator_type_enum_map
originator_type_enum_map["Client"]=0
originator_type_enum_map["Internal"]=1
originator_type_enum_map["SupportingService"]=2
local originator_type_mapped="$ORIGINATOR_TYPE"
# If the originator type comes something which is not known to
# the enum list/map then make it blank so that can be filled
# with null bytes in gendumpheader script and won't be
# breaking the dump extraction
ORIGINATOR_TYPE=""
for key in "${!originator_type_enum_map[@]}"
do
if [ "$key" = "$originator_type_mapped" ]; then
ORIGINATOR_TYPE="${originator_type_enum_map[$key]}"
break
fi
done
}