Tuesday, 10 November 2009

Zenoss: Setting IP interface speed using a script

Zen modeler sometimes returns wrong interface speeds for some interfaces. This is usually not straight forward to rectify if the monitored device is a hardware appliance like environment monitors etc. Zenoss have as a matter of policy or best practice, not allowed modification of interfaces for automatically discovered devices. However, they have suggested that this can be done via ZenDMD. Punching the commands again and again everytime you want to set interface speed could be monotonous. The script below could be used as a one liner to set interface speed for a specific device.

#!/usr/bin/env python
import sys
import Globals
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit

dmd = ZenScriptBase(connect=True).dmd

for dev in dmd.Devices.getSubDevices():
  if dev.id.startswith(sys.argv[1]):
   for interface in dev.os.interfaces():
    if interface.id.startswith(sys.argv[2]):
     interface.speed = float(sys.argv[3])

save the script as script.py
[zenoss@server ~]chmod 755 script.py
You can then use this script on the commandline as zenoss user, usage:

e. g.[zenoss@server ~]./script.py cisco Fast 100000000

##for setting speed to 100Mbps on all FastEthernet interfaces on ALL devices that begin with cisco (like cisco-002.net.myorg.com, cisco-003. ... ...)
###NOTE: use appropriate indention in the script


  1. This is most suitable for servers, I will not recomend it for network devices. I will publish a post on why i say so; very soon.

  2. not very soon, I see

  3. You just saved me heaps of digging, thanks!

  4. its nice script.i have been saved it.