Package ZenReports :: Module AliasPlugin
[hide private]
[frames] | no frames]

Source Code for Module ZenReports.AliasPlugin

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, 2009, 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 Globals 
15  from Products.ZenModel.RRDDataPoint import getDataPointsByAliases 
16  from Products.ZenModel.RRDDataPointAlias import EVAL_KEY 
17  from Products.ZenReports import Utils, Utilization 
18   
19   
20 -class AliasPlugin( object ):
21 """ 22 A base class for performance report plugins that use aliases to 23 choose datapoints 24 """ 25
26 - def getAliasColumnMap(self):
27 """ 28 Return the mapping of aliases to column names. This should be one 29 to one. This is unimplemented in the base class. 30 """ 31 raise Exception( 'Unimplemented: Only subclasses of AliasPlugin' + 32 ' should be instantiated directly' )
33
34 - def run(self, dmd, args):
35 """ 36 Generate the report using the columns and aliases obtained by 37 calling getAliasColumnMap() 38 """ 39 summary = Utilization.getSummaryArgs(dmd, args) 40 41 aliasColumnMap = self.getAliasColumnMap() 42 43 report = [] 44 45 columnDatapointsMap = {} 46 aliasDatapointPairs = getDataPointsByAliases( dmd, 47 aliasColumnMap.keys() ) 48 for alias, datapoint in aliasDatapointPairs: 49 if alias: 50 columnName = aliasColumnMap[ alias.id ] 51 else: 52 columnName = aliasColumnMap[ datapoint.id ] 53 54 if not columnDatapointsMap.has_key( columnName ): 55 columnDatapointsMap[columnName]=[] 56 columnDatapointsMap[columnName].append( (alias,datapoint) ) 57 58 # @todo: Handle component reports 59 for d in Utilization.filteredDevices(dmd, args): 60 61 columnValueMap = {} 62 for column, aliasDatapointPairs in columnDatapointsMap.iteritems(): 63 value = None 64 for alias, datapoint in aliasDatapointPairs: 65 template = datapoint.datasource().rrdTemplate() 66 deviceTemplates = d.getRRDTemplates() 67 if template in deviceTemplates: 68 if alias: 69 summary['extraRpn'] = alias.evaluate( d ) 70 value = d.getRRDValue( datapoint.id, **summary ) 71 if value is not None: 72 break 73 columnValueMap[column] = value 74 75 r = Utils.Record(device=d, 76 **columnValueMap) 77 report.append(r) 78 79 return report
80