Jump to content

Dell Fan Static Fan Speed Startup Script

I'm sure there are better ways to do this but figured I'd share a helpful script I got around to getting cobbled together for Dell servers to use the ipmitool to set the fan speed to a fixed rate after bootup. This was tested against a Dell R620 and R630 so YMMV.

 

Assumptions:

IPMI is already enabled on the server in question.

Python3 is at the default install location (/usr/bin/python3)

 

Software:

Linux VM (Ubuntu/Centos/Redhat/etc.) or baremetal Linux OS install on the server

Python3

ipmitool

 

Setup Commands:

(Ubuntu) sudo apt install ipmitool

(CentOS/Redhat) yum install OpenIPMI ipmitool

pip3 install pysnmp

 

Script:

Replace 1.1.1.1 with the IPMI address of the server in question

Replace Secr3t! with the IPMI password and root with the username to login to the IPMI

Replace [value] with the HEX value of the speed you want to set. Example 0x[value] for 20% fan speed would be 0x14

Name the file whatever you like but just put .py at the end to make things easier

import os
from pysnmp import hlapi
from datetime import datetime, timedelta

def get(target, oids, credentials, port=161, engine=hlapi.SnmpEngine(), context=hlapi.ContextData()):
    handler = hlapi.getCmd(
        engine,
        credentials,
        hlapi.UdpTransportTarget((target, port)),
        context,
        *construct_object_types(oids)
    )
    return fetch(handler, 1)[0]

def construct_object_types(list_of_oids):
    object_types = []
    for oid in list_of_oids:
        object_types.append(hlapi.ObjectType(hlapi.ObjectIdentity(oid)))
    return object_types

def fetch(handler, count):
    result = []
    for i in range(count):
        try:
            error_indication, error_status, error_index, var_binds = next(handler)
            if not error_indication and not error_status:
                items = {}
                for var_bind in var_binds:
                    items[str(var_bind[0])] = cast(var_bind[1])
                result.append(items)
            else:
                raise RuntimeError('Got SNMP error: {0}'.format(error_indication))
        except StopIteration:
            break
    return result

def cast(value):
    try:
        return int(value)
    except (ValueError, TypeError):
        try:
            return float(value)
        except (ValueError, TypeError):
            try:
                return str(value)
            except (ValueError, TypeError):
                pass
    return value

snmpval = get('1.1.1.1', ['1.3.6.1.2.1.1.3.0'], hlapi.CommunityData('public'))
ticks = (snmpval['1.3.6.1.2.1.1.3.0'])
seconds = ticks/100
up_time = timedelta(seconds=seconds)
if seconds < 3600:
    os.system("ipmitool -I lanplus -H 1.1.1.1 -U root -P Secr3t! raw 0x30 0x30 0x01 0x00")
    os.system("ipmitool -I lanplus -H 1.1.1.1 -U root -P Secr3t! raw 0x30 0x30 0x02 0xff 0x[value]")
else:
    exit()

chmod +x the .py file you made

Ideally move the file under /usr/bin or similar

 

Option 1:

Execute natively in cron on reboot:

 

Cron:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

@reboot /usr/bin/python3 yourfilename.py

 

Option 2:

Execute as part of shell script on reboot:

 

Shell script:

#!/bin/bash
#Commands to be run at startup

python3 /usr/bin/yourscriptname.py

Cron:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

@reboot shellcript.sh

 

 

References:

https://www.ictshore.com/sdn/python-snmp-tutorial/

https://www.reddit.com/r/homelab/comments/7xqb11/dell_fan_noise_control_silence_your_poweredge/

Current Network Layout:

Current Build Log/PC:

Prior Build Log/PC:

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/15/2021 at 9:42 AM, Bigun said:

I assume it's running system.d since it's Ubuntu?

 

How about creating a system.d service?  http://tuxgraphics.org/npa/systemd-scripts/

The whole point of the script though isn't to run as a service, it's to run after the server boots up and the VM starts (if applicable) to quiet the server back down. Once the server is booted and the fan speed set there isn't a need to set it again because it retains that static speed. There are however, in the reddit post link, options to monitor and adjust the fan speed dynamically depending on temps but I just wanted to keep it simple. If it were constantly running then yah it could make sense to do something with system.d service or similar for other distros though.

Current Network Layout:

Current Build Log/PC:

Prior Build Log/PC:

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×