From 88167eecfbf8190eeb11040f3774fb8b931d0c07 Mon Sep 17 00:00:00 2001 From: Tigerblue77 <37409593+tigerblue77@users.noreply.github.com> Date: Sun, 26 Jan 2025 14:23:55 +0000 Subject: [PATCH] Added print_error and print_warning functions --- Dell_iDRAC_fan_controller.sh | 6 ++---- functions.sh | 31 +++++++++++++++++++++++++++---- healthcheck.sh | 3 +-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index f876902..eb32ea3 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -26,8 +26,7 @@ fi if [[ $IDRAC_HOST == "local" ]]; then # Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then - echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2 - exit 1 + print_error_and_exit "Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode" fi IDRAC_LOGIN_STRING='open' else @@ -39,8 +38,7 @@ fi get_Dell_server_model if [[ ! $SERVER_MANUFACTURER == "DELL" ]]; then - echo "/!\ Your server isn't a Dell product. Exiting." >&2 - exit 1 + print_error_and_exit "Your server isn't a Dell product" fi # If server model is Gen 14 (*40) or newer diff --git a/functions.sh b/functions.sh index 1575b42..1e52d65 100644 --- a/functions.sh +++ b/functions.sh @@ -36,7 +36,7 @@ function convert_hexadecimal_value_to_decimal() { # Usage : retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT function retrieve_temperatures() { if (( $# != 2 )); then - printf "Illegal number of parameters.\nUsage: retrieve_temperatures \$IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT \$IS_CPU2_TEMPERATURE_SENSOR_PRESENT" >&2 + print_error "Illegal number of parameters.\nUsage: retrieve_temperatures \$IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT \$IS_CPU2_TEMPERATURE_SENSOR_PRESENT" return 1 fi local IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT=$1 @@ -88,7 +88,7 @@ function disable_third_party_PCIe_card_Dell_default_cooling_response() { # elif [ "$THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE" == "16 05 00 00 00 05 00 00 00 00" ]; then # return 1 # else -# echo "Unexpected output: $THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE" >&2 +# print_error "Unexpected output: $THIRD_PARTY_PCIE_CARD_COOLING_RESPONSE" # return 2 # fi # } @@ -102,8 +102,7 @@ function graceful_exit() { enable_third_party_PCIe_card_Dell_default_cooling_response fi - echo "/!\ WARNING /!\ Container stopped, Dell default dynamic fan control profile applied for safety." - exit 0 + print_warning_and_exit "Container stopped, Dell default dynamic fan control profile applied for safety" } # Helps debugging when people are posting their output @@ -127,3 +126,27 @@ function get_Dell_server_model() { # Define functions to check if CPU 1 and CPU 2 temperatures are above the threshold function CPU1_OVERHEATING() { [ $CPU1_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; } function CPU2_OVERHEATING() { [ $CPU2_TEMPERATURE -gt $CPU_TEMPERATURE_THRESHOLD ]; } + +function print_error() { + local ERROR_MESSAGE="$1" + printf "/!\ Error /!\ %s." "$ERROR_MESSAGE" >&2 +} + +function print_error_and_exit() { + local ERROR_MESSAGE="$1" + print_error "$ERROR_MESSAGE" + printf " Exiting.\n" >&2 + exit 1 +} + +function print_warning() { + local WARNING_MESSAGE="$1" + printf "/!\ Warning /!\ %s." "$WARNING_MESSAGE" +} + +function print_warning_and_exit() { + local WARNING_MESSAGE="$1" + print_warning "$WARNING_MESSAGE" + printf " Exiting.\n" + exit 0 +} diff --git a/healthcheck.sh b/healthcheck.sh index b71afa4..4e6d76c 100644 --- a/healthcheck.sh +++ b/healthcheck.sh @@ -10,8 +10,7 @@ source functions.sh if [[ $IDRAC_HOST == "local" ]]; then # Check that the Docker host IPMI device (the iDRAC) has been exposed to the Docker container if [ ! -e "/dev/ipmi0" ] && [ ! -e "/dev/ipmi/0" ] && [ ! -e "/dev/ipmidev/0" ]; then - echo "/!\ Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode. Exiting." >&2 - exit 1 + print_error_and_exit "Could not open device at /dev/ipmi0 or /dev/ipmi/0 or /dev/ipmidev/0, check that you added the device to your Docker container or stop using local mode" fi IDRAC_LOGIN_STRING='open' else