Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Python fan controller for Dell R510 based on CPU temperature.
- """
- from subprocess import Popen, PIPE, STDOUT
- import time
- import string
- Tcase = 68 # Tcase, maximum temperature allowed at the processor Integrated Heat Spreader (IHS).
- sleepTime = 10
- celcius = 'C'
- floatDot = '.'
- user = "root"
- password = "calvin"
- ip = "192.168.x.xx"
- #Do a command and return the stdout of proccess
- def sendcommand(cmdIn):
- p = Popen(cmdIn, shell=True, executable="/bin/bash", stdin=PIPE, stdout=PIPE, universal_newlines = True, stderr=STDOUT, close_fds=True)
- return p.stdout.read()
- #Do a ipmi command, setup for the default command.
- def ipmicmd(cmdIn):
- return sendcommand("ipmitool " + cmdIn)
- #Gets the CPU tempertures from lm-sensors, returns the maximum.
- def getcputemp():
- cmd = sendcommand('sensors -u | grep "input"')
- indexes = [pos for pos, char in enumerate(cmd) if char == floatDot]
- cputemperatures = []
- for loc in indexes:
- temp = cmd[int(loc) - 2] + cmd[int(loc) - 1]
- cputemperatures.append(int(temp))
- #return the maximum cpu temperature
- return max(cputemperatures)
- #return the average cpu temperature
- #return sum(cputemperatures) / int(len(cputemperatures))
- #Check if controller was in automode, if so we override to manual.
- def checkstatus(status):
- if (status == 5):
- ipmicmd("raw 0x30 0x30 0x01 0x00")
- #Main checking function which checks temperatures to the default set above.
- def checktemps(status):
- maxCpuT = getcputemp()
- if (maxCpuT <= (Tcase - 20)):
- if (status != 1):
- checkstatus(status)
- ipmicmd("raw 0x30 0x30 0x02 0xff 0x10")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to low RPM", flush=True)
- status = 1
- elif (maxCpuT <= (Tcase - 9)):
- if (status != 1):
- checkstatus(status)
- ipmicmd("raw 0x30 0x30 0x02 0xff 0x18")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to 4440 RPM", flush=True)
- status = 2
- elif(maxCpuT > (Tcase - 9) and maxCpuT <= (Tcase -7)):
- if (status != 2):
- checkstatus(status)
- ipmicmd("raw 0x30 0x30 0x02 0xff 0x26")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to 7200 RPM", flush=True)
- status = 3
- elif(maxCpuT > (Tcase - 7) and maxCpuT <= (Tcase -5)):
- if (status != 3):
- checkstatus(status)
- ipmicmd("raw 0x30 0x30 0x02 0xff 0x34")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to 7920 RPM", flush=True)
- status = 4
- elif(maxCpuT > (Tcase - 5) and maxCpuT <= (Tcase -2)):
- if (status != 4):
- checkstatus(status)
- ipmicmd("raw 0x30 0x30 0x02 0xff 0x36")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to 10320 RPM", flush=True)
- status = 5
- else:
- if (status != 5):
- ipmicmd("raw 0x30 0x30 0x01 0x01")
- print("Cpu at: " + str(maxCpuT) + " celcius, Fan set to auto/loud mode, Server it too hot")
- status = 5
- # print("Cpu at: " + str(maxCpuT) + " celcius, Fan status =" + str(status),flush=True)
- return status
- #Main running function.
- def main():
- status = 5
- while True:
- time.sleep(sleepTime)
- status = checktemps(status)
- #print("Sleeping for " + str(sleepTime))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement