Discussion:
Example: Adding more CPUs to template via zendmd
jeronimo
2012-12-20 18:03:50 UTC
Permalink
jeronimo [http://community.zenoss.org/people/jeronimo] created the discussion

"Example: Adding more CPUs to template via zendmd"

To view the discussion, visit: http://community.zenoss.org/message/70651#70651

--------------------------------------------------------------
I've been using rmatte's zenpack for SNMP monitoring of multi-CPU Windows systems.  Unfortunately, it did not come with 12, 32 and 64 CPU templates so I needed to make them.  The 32 and 64 CPU templates would be a lot of clicking so I decided to learn DMD and try to automate it (programmers like to work hard at being lazy).

Here's my script for posterity (and so I can find it in a year).  Also welcoming any comments on anything I did wrong or poorly.

*This was all done in 4.2 sp 1, so check that it works with your version and modify if necessary.*

# this does the following:
# creates a device class, e.g. /Servers/Windows/64 Processors
# copies the 2 Processors template to it
# creates new data sources for all the new cpus
# creates new thresholds for all the data sources, copying the maxval from the other template
# creates new CPU graph points for all the data sources, copying the format from the other template

import sys

# set this to the number of CPUs of the new template
cpus = 64

try:
    dmd.Devices.Server.Windows.manage_addOrganizer(str(cpus) + ' Processors')
    device = dmd.Devices.Server.Windows._getOb(str(cpus) + ' Processors')
    src = dmd.Devices.Server.Windows._getOb('2 Processors')
    src.manage_copyAndPasteRRDTemplates(['Device'], '/Server/Windows/' + str(cpus) + ' Processors')

    template = device.rrdTemplates._getOb('Device')

    ds = template.datasources.CPU
    cpu_start = ds.datapoints.countObjects()
    cpu1gp = template.graphDefs.CPU.graphPoints.CPU1
    cpu1th = template.thresholds.CPU1
    for x in range(cpu_start, cpus + 1):
        # create datapoints
        dp = ds.manage_addRRDDataPoint('CPU' + str(x))
        dp.rrdtype = 'GAUGE'
        # create thresholds
        threshold = template.manage_addRRDThreshold('CPU' + str(x), 'MinMaxThreshold')
        threshold.maxval = cpu1th.maxval
        threshold.dsnames = ['CPU_CPU' + str(x)]
        # create graph points
        gp = template.graphDefs.CPU.manage_addDataPointGraphPoints(['CPU_CPU' + str(x)])[0]
        gp.format = cpu1gp.format

    commit()

    print "Finished creating template"
except:
    print "Unexpected error:", sys.exc_info()[0]
    raise


And inevitably because I messed something up while coming up with the script, I also wrote some code to go back and change existing templates.  This is handy if decide to make a change like moving the cpu thresholds all to 95% or changing the format to only one decimal place.  I included changes to several things just as an example.  You should snip out and modify to fit your situation:

# this does the following:
# changes all the datapoints to GUAGE
# changes all the threshold maxvals to 90
# changes all the CPU graph points to format %5.2lf

# set this to the number of CPUs of the template to edit
cpus = 32

device = dmd.Devices.Server.Windows._getOb(str(cpus) + ' Processors')
template = device.rrdTemplates._getOb('Device')

try:
    ds = template.datasources.CPU
    gdps = template.graphDefs.CPU.graphPoints
    for x in range(1, cpus + 1):
        dp = ds.datapoints._getOb('CPU' + str(x))
        dp.rrdtype = 'GAUGE'
        threshold = template.thresholds._getOb('CPU' + str(x))
        threshold.maxval = '90'
        gdps._getOb('CPU' + str(x)).format = '%5.2lf'

    commit()

    print "Finished editing template"
except:
    print "Unexpected error:", sys.exc_info()[0]
    raise

I'm posting this in the general group rather than the windows one, because it wouldn't take much to modify this for other types of template creation/editing.

Note: I found this to be extremely helpful when figuring out the dmd I needed:
http://linuxdynasty.org/194/howto-add-multiple-datapoints-to-zenoss-using-the-zenoss-api/ http://linuxdynasty.org/194/howto-add-multiple-datapoints-to-zenoss-using-the-zenoss-api/
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70651#70651]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...