log_bmc.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #############################################################################
  25. IPMI_CMD="/usr/bin/ipmitool"
  26. #############################################################################
  27. # SEL Event types from ipmi_sel.h
  28. OS_STOP="0x20"
  29. OS_BOOT="0x1f"
  30. # SEL Event data from ipmi_sel.h
  31. GRACEFUL_SHUTDOWN="0x03" # OS Stop/Shutdown: Installation started
  32. BOOT_COMPLETED="0x01" # OS Boot: Installation started
  33. INSTALL_STARTED="0x07" # OS Boot: Installation started
  34. INSTALL_COMPLETED="0x08" # OS Boot: Installation completed
  35. INSTALL_ABORTED="0x09" # OS Boot: Installation aborted
  36. INSTALL_FAILED="0x0a" # OS Boot: Installation failed
  37. ##########################################################################
  38. # check for ipmi functionality.
  39. check_ipmi()
  40. {
  41. # ensures presence of ipmitool and /dev/ipmi*
  42. ${IPMI_CMD} mc info > /dev/null 2>&1
  43. [ $? -ne 0 ] && RETVAL=2
  44. }
  45. # Write out the events to SEL
  46. ipmi_sel_add()
  47. {
  48. # Refer ipmitool(1) event for details on format.
  49. printf "0x04 %s 0x00 0x6f %s 0x00 0x00" ${type} ${status} > \
  50. ${tmpfile} && \
  51. ${IPMI_CMD} sel add ${tmpfile} > /dev/null 2>&1
  52. [ $? -ne 0 ] && RETVAL=3
  53. }
  54. ### Main
  55. # Most of the status is for this event type
  56. tmpfile=$(/usr/bin/mktemp)
  57. RETVAL=0
  58. type=${OS_BOOT}
  59. case ${1} in
  60. os_shutdown) type=${OS_STOP}; status=${GRACEFUL_SHUTDOWN} ;;
  61. os_boot) status=${BOOT_COMPLETED} ;;
  62. inst_start) status=${INSTALL_STARTED} ;;
  63. inst_complete) status=${INSTALL_COMPLETED} ;;
  64. inst_abort) status=${INSTALL_ABORTED} ;;
  65. inst_fail) status=${INSTALL_FAILED} ;;
  66. *) RETVAL=1 ;;
  67. esac
  68. [ ${RETVAL} -eq 0 ] && check_ipmi
  69. [ ${RETVAL} -eq 0 ] && ipmi_sel_add ${status}
  70. case ${RETVAL} in
  71. 0) ;;
  72. 1) printf -- %s\\n "Usage: $0 <os_boot|os_shutdown|inst_start|inst_complete|inst_abort|inst_fail>" ;;
  73. 2) printf -- %s\\n "failed to communicate with BMC." ;;
  74. 3) printf -- %s\\n "error adding ipmi sel entry." ;;
  75. esac
  76. [ -f ${tmpfile} ] && rm -f ${tmpfile} > /dev/null 2>&1
  77. exit ${RETVAL}
  78. ### End