Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

HOWTO turn off monitoring of all interfaces on a device / device group

VERSION 11  Click to view document history
Created on: Dec 4, 2009 3:04 PM by phonegi - Last Modified:  Dec 22, 2009 9:56 AM by phonegi

NOTE: In all the examples below, indentation is three spaces per level. Python is indentation-sensitive, so be sure to match the indentation exactly as it is in the examples.

 

In the code below, code in green is optional. It just provides visual feedback to explain what the program is doing.

 

 

 

Via DMD

 

Any of the instructions below can be converted to "turn on monitoring" by changing

interface.monitor = False

to

interface.monitor = True

 

Turn off monitoring for all interfaces on one device

SSH into your Zenoss system as user zenoss

 

At the command prompt enter:

[zenoss@zenoss ~]$ zendmd

 

Now you will be at the zendmd prompt. Enter the following:

>>> device = dmd.Devices.findDevice( '[name of your device]' )
>>> for interface in device.os.interfaces():

...    if interface.isLockedFromUpdates():

...       print interface.interfaceName + ' is locked from updates, skipping'

...    else: 

...       interface.monitor = False

...       print interface.interfaceName + ' monitoring set to False'

...

 

[ code will execute here...]

 

>>> commit()

(^d to exit)

 

Turn off monitoring for all interfaces on all devices within a Device Class

SSH into your Zenoss system as user zenoss

 

At the command prompt enter:

[zenoss@zenoss ~]$ zendmd

 

Now you will be at the zendmd prompt. Enter the following:

>>> for device in dmd.Devices.[device class path].devices():

...    print device.getId() + ":"

...    for interface in device.os.interfaces():

...       if interface.isLockedFromUpdates():

...          print interface.interfaceName + ' is locked from updates, skipping'

...       else: 

...          interface.monitor = False

...          print interface.interfaceName + ' monitoring set to False'

...

 

[ code will execute here...]

 

>>> commit()

(^d to exit)

 

Example:

If you wanted to turn off monitoring on all the interfaces on all the devices in the /Devices/Network/Switch device class, the first line of code would be:
>>> for device in dmd.Devices.Network.Switch.devices():

 

Turn off monitoring for all interfaces on all devices within a Device Class and all Sub-Devices

In this case, we define a python function and then execute the function with a specific set of parameters

 

SSH into your Zenoss system as user zenoss

 

At the command prompt enter:

[zenoss@zenoss ~]$ zendmd

 

Now you will be at the zendmd prompt. Enter the following:

>>> def setMonitor(deviceClass, path):

...    print path

...    for device in deviceClass.devices():

...       print '  ' + device.getId() + ':'

...       for interface in device.os.interfaces():

...          if interface.isLockedFromUpdates():

...             print interface.interfaceName + ' is locked from updates, skipping'

...          else: 

...             interface.monitor = False

...             print interface.interfaceName + ' monitoring set to False'

...    for item in deviceClass.__dict__:

...       if type(deviceClass.__dict__[item]).__name__ == \

...             'DeviceClass' and item != '__primary_parent__':

...          setMonitor(deviceClass.__dict__[item], path + '/' + item)

...

>>> setMonitor(dmd.Devices.[device class path], '/Devices/[path name]')

 

[ code will execute here...]

 

>>> commit()

(^d to exit)

 

Example:

If you wanted to turn off monitoring on all the interfaces on all the devices and sub-devices in the /Devices/Network/Switch device class, the last line of code would be:
>>> setMonitor(dmd.Devices.Network.Switch, '/Devices/Network/Switch')

 

Via User Command

 

Although it takes a bit more work, and is a bit complicated, this method is much more convenient to use. With this method, you will have user commands available from the drop down menu whenever you want. For convenience, I've attached the python script below.

 

Create python script file

 

Start by creating a python script in the $ZENHOME/bin directory. I named the file user.InterfaceMonitor.py. Enter the following into the file using your favorite text editor:

 

#!/usr/bin/env python


# This script is designed to be executed from the command line

# with the following syntax:

# user.InterfaceMonitor.py '(device name)' (ON | OFF)

# Example:

# user.InterfaceMonitor.py 'Cisco Switch 1' OFF


import Globals

from Products.ZenUtils.ZenScriptBase import ZenScriptBase

from transaction import commit

import sys


def showHelp():

   print '\nSyntax:'

   print '   user.InterfaceMonitor.py \'(device name)\' (ON | OFF)\n'

   print 'Example:'

   print '   user.InterfaceMonitor.py 'Cisco Switch 1' OFF\n'

   sys.exit()

 

if len(sys.argv) != 3:

   print '\n*** Invalid Syntax ***'

   showHelp()


dmd = ZenScriptBase(connect=True).dmd

deviceName = sys.argv[1]

device = dmd.Devices.findDevice(deviceName)

if device is None:

   print '\nDevice not found in dmd.\n'

   sys.exit()

  

commandState = sys.argv[2].upper()

if commandState == 'ON':

   monitorState = True

elif commandState == 'OFF':

   monitorState = False

else:

   print '\n*** Invalid Syntax ***'

   showHelp()


for interface in device.os.interfaces():

    if interface.isLockedFromUpdates():

        print interface.interfaceName + ' is locked from updates, skipping'

    else:   

        interface.monitor = monitorState

        print interface.interfaceName + ' monitoring set to ' \

            + commandState


commit()

 

Make the file executable using the command:

[zenoss@zenoss bin] chmod u+x user.InterfaceMonitor.py

 

Create User Commands

 

Once the file is in place, you must create the user commands. You must decide which device class to put them in. I put mine in /Devices/Network but there is no reason you can't put them in /Devices. The commands will be available for any device or sub-device under the device class where you put them. For instance, because I put mine in /Devices/Network, the commands will be available when I am viewing the device /Devices/Network/Switch/Cisco Switch 1. They will not be available from /Devices/Power.

 

      1. Navigate to the device class where you will be installing the User Commands. From the main drop down menu, select More > Administration.
      2. From the Define Commands drop down menu, select Add User Command...
      3. The Command Id will be the name of the command. I named mine "Turn OFF All Interface Monitoring" but you can name it anything you want. Click OK.
      4. You are now at the User Command tab. In the Command text box, enter the following:
        user.InterfaceMonitor.py '${device/getId}' OFF 
      5. Click the Save button.
      6. Repeat steps 1 through 5, except this command will be used to turn all interfaces ON, so name the command appropriately in step 3, and use the following in the Command text box in step 4:
        user.InterfaceMonitor.py '${device/getId}' ON

Using your new User Commands

 

To turn on/off monitoring the interfaces on just one device:

      1. Navigate to the device
      2. From the main drop down menu, select Run Commands... > [your command name]

 

To turn on/off monitoring the interfaces on every device in a device class:

      1. Navigate to the device class
      2. From the main drop down menu, select Run Commands... > [your command name]
Attachments:
Note: binary attachments ending in .zip will need to be unzipped before use.
Comments (0)

More Like This

  • Retrieving data ...

More by phonegi