Python Tutorial: Get data from a Dell PowerEdge Server using pysnmp

转载 2018年04月17日 10:33:24

This python tutorial will teach you how to query the Dell PowerEdge temperature sensors via SNMP. Once OpenManage software is installed on a Dell server, a ton of information is made available via SNMP including…

  • Chassis Temperature
  • Fan(s) Speed
  • Chassis Intrusion Switch
  • Hard Drive Health
  • Power Supply Status, Voltages, and Consumption


1.) Install the pysnmp package
C:\> pip install --upgrade pysnmp
Collecting pysnmp
Installing collected packages: pysmi, pysnmp
Successfully installed pysmi-0.0.6 pysnmp-4.3.1

2.) A Dell PowerEdge Server running Windows Server 2008 or newer with Dell Open Manage Installed.

3.) You will also need to install and configure SNMP support on the target Windows Server machine.

If you search for pysnmp example code you will find two type, Synchronous, and Asynchronous. The following code is an example of a synchronous SNMP Get found in the old pysnmp manual

SNMPv2-SMI::enterprises.674.10892.1.300. = b'Dell Inc.'
SNMPv2-SMI::enterprises.674.10892.1.300. = b'PowerEdge R720'

Throughout the rest of this tutorial, we will stick with the Synchronous type code. We are only fetching a few data points and there is no need to add the complexity of performing Asynchronous operations.

Next, we will create a snmpget() function that will encapsulate the above code and make it reusable.

With everything now contained inside the snmpget() function we can call the function for each OID we want to query.

Dell Inc.
Now that we are getting the data, we will apply some formatting.

Make: Dell Inc.
Model: PowerEdge R720

Next, lets fetch some data about the power supply amperage and total watts consumed. You may get different results if your server does not have redundant(2) power supplies.

PS1 Current 1: 16 AMPS
PS2 Current 2: 0 AMPS
System Board Pwr Consumption: 196 Watts

So far, we have called snmpget() individually to get data. Lets modify snmpget to accept a list of OIDs and return a list of return values.
We will progressively modify our snmpget() function to accomplish this. We add two additional arguments to the function oid2, oid3. While this is not ideal the getCmd() wants each addition oid as an additional command line argument.
Lets focus on the return values. Instead of iterating over varBinds we will extract the values and return a simple list or singular value if the list’s length is 1.

PS1 Current 1
PS2 Current 2
System Board Pwr Consumption

The function now returns a list of values but our approach to accepting additional arguments is not very flexible. As you can see we get an error when we try to request anything other than 3 oids.

IndexError Traceback (most recent call last)
in ()
----> 1 results = snmpget( '', '' )

in snmpget(oid, oid2, oid3)
14 oid,
15 oid2,
---> 16 oid3
17 )

As you see, this code raises an error.

We need to modify the function definition to accept a variable number of arguments.

The function getCmd() also uses this same technique. We can pass along these additional OIDs to the getCmd() function but we must prefix the more_oids variable with an asterisk *.

Now when we call snmpget() with any number of oids.

PS1 Current 1
PS2 Current 2
System Board Pwr Consumption
PS1 Current 1

Our snmpget() function is rather functional but we are still referencing the global variables for host,port,community defined back at the top of this tutorial.

We can make this code even more reusable by encapsulating everything into a Class.

We supply the IP, Port, and Community string to the class’s constructor.

Dell Inc.
PowerEdge R720
PS1 Current 1
PS2 Current 2
System Board Pwr Consumption

Now that we have a working SNMP Client that we can use to query the server lets look at some of the interesting data presented by the Dell OpenManage SNMP extensions.

# Cooling Device AKA Fan Location Name

# Cooling Fan RPMs

# Cooling Fan Status (3 is OK)

# Cooling Unit Status (All Fans considers (3 is OK)

# Temp Probe Location(s)

# Temp Reading (Value is Celius 1/10 Degree)

When we query the system’s temperature probes tthe value is returned in Celsius at a resolution of 1/10 of a degree.

So a value of 234 is 23.4 Celsius.

To get this value we simply divide by 10.

Additionally, I want the temperature reading in Fahrenheit so we use the formula to convert Celsius to Fahrenheit.

T(F) = T(C) x 9/5 + 32

System Board Inlet Temp: 69F
System Board Exhaust Temp: 95F

I hope you find this python example useful and educational. You are free to use the above code how you see fit.

More Python Goodness

Dell PowerEdge R620 免光驱安装WindowsServer2003x64系统

  • 2013年09月24日 08:29
  • 7.64MB
  • 下载

在Dell服务器PowerEdge R730上安装操作系统

  • lizi_stdio
  • lizi_stdio
  • 2017-12-02 19:21:37
  • 2260

戴尔poweredge r730服务器配置以及系统安装

第一次给服务器安装的是ubantu系统;   首先我们开机进入小型BIOS设置一下RAID,或者进入服务器管理系统,在系统的BIOS中进行RAID设置; 开机后当看到出现 时按Ctrl+r,进入...
  • qq_34886018
  • qq_34886018
  • 2017-07-19 15:29:07
  • 766

Dell-------------- PowerEdge R720(U盘装WIN2008 R2 X64)

1.开机看到提示(比如:F10 )
  • YangangwuWuyangang
  • YangangwuWuyangang
  • 2014-05-16 14:10:37
  • 2950


pysnmp是用python语言开发的snmp开源项目,感觉没有net-snmp强大。但如果你只开发snmp 客户端的 trap,那么用pysnmp还是很简单的。 1、安装下载pysnmp和pyasn...
  • sealyao
  • sealyao
  • 2009-09-12 10:18:00
  • 7184

dell t110二代服务器RAID模式下安装win2003终极有效方法.zip

  • 2013年12月31日 14:54
  • 262KB
  • 下载


安装pysnmp: 编译安装的话,pysnmp需要用到asn.1,安装pysnmp的话需要先安装asn.1,不过我没有安装成功。 也可以使用easy_install pysnmp安...
  • shangzhihaohao
  • shangzhihaohao
  • 2011-11-19 23:15:27
  • 7971

Cousera-Using python to access web data(第2~4周笔记)

第二周: 正则表达式 第三周: Networks and Sockets http://www....
  • u014518506
  • u014518506
  • 2016-10-31 20:28:48
  • 2891

Root-NFS: Unable to get nfsd port number from server, using default

今晚遇到一个很奇怪的问题,TQ2440开发板的nfs系统突然启动不了了,前几天一直都是这么用,一直没有发生过今晚那么特殊的情况,下面是开发板的启动信息。   Root-NFS: Unable to...
  • lwj103862095
  • lwj103862095
  • 2013-01-28 23:01:00
  • 7174

戴尔poweredge 1950的安装 fedora系统小记

公司要搭建一个测试服务器,所以就选择了fedora的系统,因为很喜欢fedora的桌面版,而且,超级喜欢fedora的包管理器。 第一步 制作启动U盘 fedora的启动U盘很好制作,在fed...
  • qq_31927797
  • qq_31927797
  • 2017-11-16 09:42:35
  • 106
您举报文章:Python Tutorial: Get data from a Dell PowerEdge Server using pysnmp