From 30ceee70b534be5cd7baa6c3a918e68490b55061 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 | 25 +++++++++++++++++++++++-- healthcheck.sh | 3 +-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index 63c00bc..3ffe16f 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -28,8 +28,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 @@ -41,8 +40,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..1c70c47 100644 --- a/functions.sh +++ b/functions.sh @@ -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,25 @@ 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" + echo "/!\ Error /!\ $ERROR_MESSAGE." >&2 +} + +function print_error_and_exit() { + local ERROR_MESSAGE="$1" + print_error "$ERROR_MESSAGE Exciting." + exit 1 +} + +function print_warning() { + local WARNING_MESSAGE="$1" + echo "/!\ Warning /!\ $WARNING_MESSAGE." +} + +function print_warning_and_exit() { + local WARNING_MESSAGE="$1" + print_warning "$WARNING_MESSAGE Exciting." + 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