Package Products :: Package ZenHub :: Package services :: Module CommandConfig
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenHub.services.CommandConfig

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  import logging 
 15  log = logging.getLogger('zen.CommandConfig') 
 16   
 17  from ZODB.POSException import POSError 
 18   
 19  from PerformanceConfig import PerformanceConfig 
 20  from Products.ZenRRD.zencommand import Cmd, DeviceConfig, DataPointConfig 
 21  from Products.ZenHub.PBDaemon import translateError 
 22  from Products.DataCollector.Plugins import getParserLoader 
 23  from Products.ZenEvents.ZenEventClasses import Warning 
24 25 -def getComponentCommands(comp, commandCache, commandSet, dmd):
26 """Return list of command definitions. 27 """ 28 perfServer = comp.device().getPerformanceServer() 29 for templ in comp.getRRDTemplates(): 30 basepath = comp.rrdPath() 31 for ds in templ.getRRDDataSources('COMMAND'): 32 if not ds.enabled: continue 33 parserName = getattr(ds, "parser", "Auto") 34 ploader = getParserLoader(dmd, parserName) 35 if ploader is None: 36 log.error("Could not load %s plugin", parserName) 37 continue 38 component_name = ds.getComponent(comp) 39 parser = ploader.create() 40 points = [] 41 for dp in ds.getRRDDataPoints(): 42 dpc = DataPointConfig() 43 dpc.id = dp.id 44 dpc.component = component_name 45 dpc.rrdPath = "/".join((basepath, dp.name())) 46 dpc.rrdType = dp.rrdtype 47 dpc.rrdCreateCommand = dp.getRRDCreateCommand(perfServer) 48 dpc.rrdMin = dp.rrdmin 49 dpc.rrdMax = dp.rrdmax 50 dpc.data = parser.dataForParser(comp, dp) 51 points.append(dpc) 52 cmd = Cmd() 53 cmd.useSsh = getattr(ds, 'usessh', False) 54 try: 55 cmd.cycleTime = int(ds.cycletime) 56 except ValueError: 57 message = "Unable to convert the cycle time '%s' to an " \ 58 "integer for %s/%s on %s" \ 59 " -- setting to 300 seconds" % ( 60 ds.cycletime, templ.id, ds.id, comp.device().id) 61 log.error(message) 62 component = ds.getPrimaryUrlPath() 63 dedupid = "Unable to convert cycletime for %s" % component 64 dmd.ZenEventManager.sendEvent(dict( 65 device=comp.device().id, component=component, 66 eventClass='/Cmd', severity=Warning, summary=message, 67 dedupid=dedupid, 68 )) 69 cmd.cycleTime = 300 70 cmd.component = component_name 71 cmd.eventClass = ds.eventClass 72 cmd.eventKey = ds.eventKey or ds.id 73 cmd.severity = ds.severity 74 cmd.parser = ploader 75 cmd.command = ds.getCommand(comp) 76 cmd = commandCache.setdefault(cmd.commandKey(), cmd) 77 cmd.points.extend(points) 78 commandSet.add(cmd) 79 return comp.getThresholdInstances('COMMAND')
80
81 82 -def getDeviceCommands(dev):
83 if not dev.monitorDevice(): 84 return None 85 cache = {} 86 cmds = set() 87 try: 88 threshs = getComponentCommands(dev, cache, cmds, dev.getDmd()) 89 except (SystemExit, KeyboardInterrupt), ex: 90 log.exception("Unable to process device commands for %s -- skipping", 91 dev.id) 92 for o in dev.getMonitoredComponents(collector="zencommand"): 93 try: 94 threshs.extend(getComponentCommands(o, cache, cmds, dev.getDmd())) 95 except (SystemExit, KeyboardInterrupt), ex: 96 log.exception("Unable to process component commands for %s %s -- skipping", 97 dev.id, o.id) 98 if cmds: 99 d = DeviceConfig() 100 d.lastChange = dev.getLastChange() 101 d.device = dev.id 102 d.ipAddress = dev.getManageIp() 103 d.port = dev.getProperty('zCommandPort') 104 d.username = dev.getProperty('zCommandUsername') 105 d.password = dev.getProperty('zCommandPassword') 106 d.loginTimeout = dev.getProperty('zCommandLoginTimeout') 107 d.commandTimeout = dev.getProperty('zCommandCommandTimeout') 108 d.keyPath = dev.getProperty('zKeyPath') 109 d.maxOids = dev.getProperty('zMaxOIDPerRequest') 110 d.concurrentSessions = dev.getProperty('zSshConcurrentSessions') 111 d.commands = list(cmds) 112 d.thresholds = threshs 113 return d 114 return None
115
116 117 -class CommandConfig(PerformanceConfig):
118 119 @translateError
120 - def remote_getDataSourceCommands(self, devices = None):
121 return self.getDataSourceCommands(devices)
122 123
124 - def getDeviceConfig(self, device):
126 127
128 - def sendDeviceConfig(self, listener, config):
129 return listener.callRemote('updateConfig', config)
130 131
132 - def getDataSourceCommands(self, devices = None):
133 '''Get the command configuration for all devices. 134 ''' 135 result = [] 136 for dev in self.config.devices(): 137 if devices and dev.id not in devices: continue 138 dev = dev.primaryAq() 139 try: 140 cmdinfo = getDeviceCommands(dev) 141 if not cmdinfo: continue 142 result.append(cmdinfo) 143 except POSError: raise 144 except: 145 self.log.exception("getDeviceCommands() exception for device %s", 146 dev.id) 147 return result
148
149 - def update(self, object):
150 from Products.ZenModel.RRDDataSource import RRDDataSource 151 if isinstance(object, RRDDataSource): 152 if object.sourcetype != 'COMMAND': 153 return 154 155 PerformanceConfig.update(self, object)
156