From 83275ce64a505b098b17c6a4181689c4a0d2ee79 Mon Sep 17 00:00:00 2001 From: Tigerblue77 <37409593+tigerblue77@users.noreply.github.com> Date: Sun, 26 Oct 2025 19:44:48 +0000 Subject: [PATCH] Factorized generation of the iDRAC login string --- Dell_iDRAC_fan_controller.sh | 13 +------------ functions.sh | 24 ++++++++++++++++++++++++ healthcheck.sh | 13 +------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Dell_iDRAC_fan_controller.sh b/Dell_iDRAC_fan_controller.sh index bab1efc..63a4d39 100644 --- a/Dell_iDRAC_fan_controller.sh +++ b/Dell_iDRAC_fan_controller.sh @@ -22,18 +22,7 @@ else readonly HEXADECIMAL_FAN_SPEED=$(convert_decimal_value_to_hexadecimal "$FAN_SPEED") fi -# Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly -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 - 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 - echo "iDRAC/IPMI username: \"$IDRAC_USERNAME\"" - #echo "iDRAC/IPMI password: \"$IDRAC_PASSWORD\"" - IDRAC_LOGIN_STRING="lanplus -H \"$IDRAC_HOST\" -U \"$IDRAC_USERNAME\" -P \"$IDRAC_PASSWORD\"" -fi +set_iDRAC_login_string "$IDRAC_HOST" "$IDRAC_USERNAME" "$IDRAC_PASSWORD" get_Dell_server_model diff --git a/functions.sh b/functions.sh index f2117df..d09f8c4 100644 --- a/functions.sh +++ b/functions.sh @@ -32,6 +32,30 @@ function convert_hexadecimal_value_to_decimal() { echo $DECIMAL_NUMBER } +# Set the IDRAC_LOGIN_STRING variable based on connection type +# Usage : set_iDRAC_login_string $IDRAC_HOST $IDRAC_USERNAME $IDRAC_PASSWORD +# Returns : IDRAC_LOGIN_STRING +function set_iDRAC_login_string() { + local IDRAC_HOST="$1" + local IDRAC_USERNAME="$2" + local IDRAC_PASSWORD="$3" + + IDRAC_LOGIN_STRING="" + + # Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly + 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 + 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 + echo "iDRAC/IPMI username: \"$IDRAC_USERNAME\"" + #echo "iDRAC/IPMI password: \"$IDRAC_PASSWORD\"" + IDRAC_LOGIN_STRING="lanplus -H \"$IDRAC_HOST\" -U \"$IDRAC_USERNAME\" -P \"$IDRAC_PASSWORD\"" + fi +} + # Retrieve temperature sensors data using ipmitool # Usage : retrieve_temperatures $IS_EXHAUST_TEMPERATURE_SENSOR_PRESENT $IS_CPU2_TEMPERATURE_SENSOR_PRESENT function retrieve_temperatures() { diff --git a/healthcheck.sh b/healthcheck.sh index f3c386a..bf948c1 100644 --- a/healthcheck.sh +++ b/healthcheck.sh @@ -6,17 +6,6 @@ source functions.sh -# Check if the iDRAC host is set to 'local' or not then set the IDRAC_LOGIN_STRING accordingly -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 - 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 - echo "iDRAC/IPMI username: \"$IDRAC_USERNAME\"" - #echo "iDRAC/IPMI password: \"$IDRAC_PASSWORD\"" - IDRAC_LOGIN_STRING="lanplus -H \"$IDRAC_HOST\" -U \"$IDRAC_USERNAME\" -P \"$IDRAC_PASSWORD\"" -fi +set_iDRAC_login_string "$IDRAC_HOST" "$IDRAC_USERNAME" "$IDRAC_PASSWORD" ipmitool -I $IDRAC_LOGIN_STRING sdr type temperature