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

Source Code for Module 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  from PerformanceConfig import PerformanceConfig 
 15  from ZODB.POSException import POSError 
 16  from Products.ZenRRD.zencommand import Cmd, DeviceConfig, DataPointConfig 
 17  from Products.ZenRRD.CommandParser import getParser 
 18  from Products.ZenHub.PBDaemon import translateError 
 19   
 20   
21 -def getComponentCommands(comp, commandCache, commandSet):
22 """Return list of command definitions. 23 """ 24 perfServer = comp.device().getPerformanceServer() 25 for templ in comp.getRRDTemplates(): 26 basepath = comp.rrdPath() 27 for ds in templ.getRRDDataSources('COMMAND'): 28 if not ds.enabled: continue 29 parserName = getattr(ds, "parser", "Auto") 30 parser = getParser(parserName) 31 points = [] 32 for dp in ds.getRRDDataPoints(): 33 dpc = DataPointConfig() 34 dpc.id = dp.id 35 dpc.component = comp.id 36 dpc.rrdPath = "/".join((basepath, dp.name())) 37 dpc.rrdType = dp.rrdtype 38 dpc.rrdCreateCommand = dp.getRRDCreateCommand(perfServer) 39 dpc.rrdMin = dp.rrdmin 40 dpc.rrdMax = dp.rrdmax 41 dpc.data = parser.dataForParser(comp, dp) 42 points.append(dpc) 43 cmd = Cmd() 44 cmd.useSsh = getattr(ds, 'usessh', False) 45 cmd.cycleTime = ds.cycletime 46 cmd.component = ds.getComponent(comp) 47 cmd.eventClass = ds.eventClass 48 cmd.eventKey = ds.eventKey or ds.id 49 cmd.severity = ds.severity 50 cmd.parser = parserName 51 cmd.command = ds.getCommand(comp) 52 cmd = commandCache.setdefault(cmd.commandKey(), cmd) 53 cmd.points.extend(points) 54 commandSet.add(cmd) 55 return comp.getThresholdInstances('COMMAND')
56 57
58 -def getDeviceCommands(dev):
59 if not dev.monitorDevice(): 60 return None 61 cache = {} 62 cmds = set() 63 threshs = getComponentCommands(dev, cache, cmds) 64 for o in dev.getMonitoredComponents(collector="zencommand"): 65 threshs.extend(getComponentCommands(o, cache, cmds)) 66 if cmds: 67 d = DeviceConfig() 68 d.lastChange = dev.getLastChange() 69 d.device = dev.id 70 d.ipAddress = dev.getManageIp() 71 d.port = dev.zCommandPort 72 d.username = dev.zCommandUsername 73 d.password = dev.zCommandPassword 74 d.loginTimeout = dev.zCommandLoginTimeout 75 d.commandTimeout = dev.zCommandCommandTimeout 76 d.keyPath = dev.zKeyPath 77 d.maxOids = dev.zMaxOIDPerRequest 78 d.concurrentSessions = dev.zSshConcurrentSessions 79 d.commands = list(cmds) 80 d.thresholds = threshs 81 return d 82 return None
83 84
85 -class CommandConfig(PerformanceConfig):
86 87 @translateError
88 - def remote_getDataSourceCommands(self, devices = None):
89 return self.getDataSourceCommands(devices)
90 91
92 - def getDeviceConfig(self, device):
94 95
96 - def sendDeviceConfig(self, listener, config):
97 return listener.callRemote('updateConfig', config)
98 99
100 - def getDataSourceCommands(self, devices = None):
101 '''Get the command configuration for all devices. 102 ''' 103 result = [] 104 for dev in self.config.devices(): 105 if devices and dev.id not in devices: continue 106 dev = dev.primaryAq() 107 try: 108 cmdinfo = getDeviceCommands(dev) 109 if not cmdinfo: continue 110 result.append(cmdinfo) 111 except POSError: raise 112 except: 113 self.log.exception("device %s", dev.id) 114 return result
115
116 - def update(self, object):
117 from Products.ZenModel.RRDDataSource import RRDDataSource 118 if isinstance(object, RRDDataSource): 119 if object.sourcetype != 'COMMAND': 120 return 121 122 PerformanceConfig.update(self, object)
123