xref: /openbmc/ipmitool/contrib/log_bmc.sh (revision e8450850)
1#!/bin/sh
2#############################################################################
3#
4# log_bmc.sh: Add SEL entries to indicate OS Boot/Install status.
5#
6# version:      0.1
7#
8# Authors:      Charles Rose <charles_rose@dell.com>
9#               Jordan Hargrave <jordan_hargrave@dell.com>
10#
11# Description:  Script to log OS boot/install status to the BMC. Primarily
12#		meant for use in automated installs and start up scripts.
13#		Will provide administrators with OS boot/install status in
14#		BMC and aid with debugging.
15#
16#               Example usage:
17#               # ./log_bmc.sh inst_start
18#               # ipmitool sel list
19#		b | 05/07/2014 | 12:07:32 | OS Boot | Installation started
20#
21#               See here for details:
22#               https://fedoraproject.org/wiki/Features/AgentFreeManagement
23#
24#############################################################################
25IPMI_CMD="/usr/bin/ipmitool"
26
27#############################################################################
28# SEL Event types from ipmi_sel.h
29OS_STOP="0x20"
30OS_BOOT="0x1f"
31# SEL Event data from ipmi_sel.h
32GRACEFUL_SHUTDOWN="0x03" # OS Stop/Shutdown: Installation started
33BOOT_COMPLETED="0x01" # OS Boot: Installation started
34INSTALL_STARTED="0x07" # OS Boot: Installation started
35INSTALL_COMPLETED="0x08" # OS Boot: Installation completed
36INSTALL_ABORTED="0x09" # OS Boot: Installation aborted
37INSTALL_FAILED="0x0a" # OS Boot: Installation failed
38
39##########################################################################
40
41# check for ipmi functionality.
42check_ipmi()
43{
44	# ensures presence of ipmitool and /dev/ipmi*
45	${IPMI_CMD} mc info > /dev/null 2>&1
46	[ $? -ne 0 ] && RETVAL=2
47}
48
49# Write out the events to SEL
50ipmi_sel_add()
51{
52	# Refer ipmitool(1) event for details on format.
53	printf "0x04 %s 0x00 0x6f %s 0x00 0x00" ${type} ${status} > \
54		${tmpfile} && \
55		${IPMI_CMD} sel add ${tmpfile} > /dev/null 2>&1
56	[ $? -ne 0 ] && RETVAL=3
57}
58
59### Main
60# Most of the status is for this event type
61tmpfile=$(/usr/bin/mktemp)
62RETVAL=0
63type=${OS_BOOT}
64
65case ${1} in
66	os_shutdown)   type=${OS_STOP}; status=${GRACEFUL_SHUTDOWN} ;;
67	os_boot)       status=${BOOT_COMPLETED} ;;
68	inst_start)    status=${INSTALL_STARTED} ;;
69	inst_complete) status=${INSTALL_COMPLETED} ;;
70	inst_abort)    status=${INSTALL_ABORTED} ;;
71	inst_fail)     status=${INSTALL_FAILED} ;;
72	*)             RETVAL=1 ;;
73esac
74
75[ ${RETVAL} -eq 0 ] && check_ipmi
76[ ${RETVAL} -eq 0 ] && ipmi_sel_add ${status}
77
78case ${RETVAL} in
79	0) ;;
80	1) printf -- %s\\n "Usage: $0 <os_boot|os_shutdown|inst_start|inst_complete|inst_abort|inst_fail>" ;;
81	2) printf -- %s\\n "failed to communicate with BMC." ;;
82	3) printf -- %s\\n "error adding ipmi sel entry." ;;
83esac
84
85[ -f ${tmpfile} ] && rm -f ${tmpfile} > /dev/null 2>&1
86
87exit ${RETVAL}
88### End
89