Discussion:
unexpected results with script to create template objects
Vincent van Os
2012-05-11 12:35:35 UTC
Permalink
Vincent van Os [http://community.zenoss.org/people/vvanos] created the discussion

"unexpected results with script to create template objects"

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

--------------------------------------------------------------
Hi there,

Im am trying to build a script for adding templates, datasources to this template, datapoints to the datasource and graphs to the datapoint( I know im lazy, yet i take comfort in the idea i'm 'automating' instead of actually doing repetitive work). The little code i got works but only this far that it wel register the object in the database, visible with the zope database manage interface. but not in the zenoss web interface. if i rename the template object via the zope management interface it suddenly shows up in the zenoss webinterface. can someone help me out to fix this so that my script works right away? Tnx in advance!

script:

#!/opt/zenoss/python/bin/python2.6
import os
import sys
import re

from optparse import OptionParser
import Globals
import Acquisition

from Products.ZenUtils.ZenScriptBase import ZenScriptBase
from transaction import commit

templateRoot = '/Server/Linux'
templateLocation = '/rrdTemplates/'


if __name__ == '__main__':
        usage = 'rtfm'
        parser = OptionParser(usage)
        parser.add_option("-t", "--template", dest="newTemplate", help="template")
        parser.add_option("-d", "--datasource", dest="newDs", help="datasource")
        parser.add_option("-c", "--command", dest="newDsCommand", help="command")
        parser.add_option("-p", "--points", dest="newDp", help="datapoints")

        (options, args) = parser.parse_args()
        dmd = ZenScriptBase(connect=True,noopts=True).dmd
        if options.newTemplate:
                newTemplate = options.newTemplate
                newDs = options.newDs
                newDsCommand = options.newDsCommand
                newDp = [options.newDp, ]
                newTemplateLocation = templateRoot + templateLocation + newTemplate
        else:
                print "Pass --help for help"
                sys.exit(1)



        obj = dmd.Devices.getOrganizer(templateRoot)
        obj.manage_addRRDTemplate(newTemplate)
        commit()
        device = dmd.Devices.getOrganizer(newTemplateLocation)
        print(device)
        DS = device.manage_addRRDDataSource(newDs, 'BasicDataSource.COMMAND')
        print(DS)
        DS.enabled = False
        DS.usessh = True
        DS.component = newDs
        DS.eventClass = '/Cmd/Fail'
        DS.eventKey = newDs
        DS.severity = 'Critical'
        DS.cycletime = '120'
        DS.parser = 'Nagios'
        DS.commandTemplate = newDsCommand
        commit()
        for x in newDp:
                print(x)
                DP = DS.manage_addRRDDataPoint(x)
                graph = DP.manage_addGraphDefinition(x)
                print(graph)
                gp = newDs + '_' + x
                gps = [x, ]
                graph.manage_addDataPointGraphPoints(gps)
        commit()
        print("last commit done?")

        commit()


script is called as follows:

script.py -t template -d datasource -c command -p datapoint

Usage: rtfm

Options:
  -h, --help            show this help message and exit
  -t NEWTEMPLATE, --template=NEWTEMPLATE
                        template
  -d NEWDS, --datasource=NEWDS
                        datasource
  -c NEWDSCOMMAND, --command=NEWDSCOMMAND
                        command
  -p NEWDP, --points=NEWDP
                        datapoints
--------------------------------------------------------------

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

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]
dpetzel
2012-05-11 13:12:10 UTC
Permalink
dpetzel [http://community.zenoss.org/people/dpetzel] created the discussion

"Re: unexpected results with script to create template objects"

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

--------------------------------------------------------------
            log.info("Creating RRDTemplate %s", self.app_name)
            dc = dmd.Devices.Server
            temple = RRDTemplate(self.app_name)
            dc.rrdTemplates._setObject(temple.id, temple)
--------------------------------------------------------------

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

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...