xref: /openbmc/phosphor-debug-collector/tools/dreport.d/plugins.d/hoststate (revision e5af9c67d266812e4099a20cd318c2e3c6e013c9)
1#!/bin/bash
2#
3# config: 1234 5
4# @brief: Collect Host state information.
5#
6
7# shellcheck source=tools/dreport.d/include.d/functions
8. "$DREPORT_INCLUDE"/functions
9
10# Discover all services managing host states
11services=$(busctl list | awk '{print $1}' | grep -E "xyz.openbmc_project.State.Host([0-9]*)?$")
12for service in ${services}; do
13    objpath=$(busctl tree --list "$service" | tail -n 1)
14    index=$(echo "$service" | grep -o '[0-9]*$')
15    if [ -z "$index" ]; then
16        file_name="host-state.log"
17        desc="Host State"
18    else
19        file_name="host${index}-state.log"
20        desc="Host${index} State"
21    fi
22    command="busctl get-property ${service} ${objpath} \
23              xyz.openbmc_project.State.Host CurrentHostState"
24    add_cmd_output "$command" "$file_name" "$desc"
25done
26