#!/bin/bash
#
# config: 2 20
# @brief: Get the fan monitor dump
#

# shellcheck source=tools/dreport.d/include.d/functions
. "$DREPORT_INCLUDE"/functions

if [ ! -e "/usr/bin/phosphor-fan-monitor" ]; then
    exit 0
fi

file_name="/tmp/fan_monitor_dump.json"

rm -f $file_name
killall -s SIGUSR1 phosphor-fan-monitor

seconds=0
while [ ! -e "$file_name" ]; do
    seconds=$(( seconds + 1 ))
    if [ $seconds -eq 5 ]; then
        echo "Timed out waiting for fan monitor dump"
        exit 0
    fi
    sleep 1
done

desc="fan monitor dump"
add_copy_file "$file_name" "$desc"

rm -rf /tmp/fan_monitor_dump.json
