interfaceusage.py

import Globals
from Products.ZenReports import Utils, Utilization
import re
class interfaceusage:
        "The usage report"
        def run(self, dmd, args):
                summary = Utilization.getSummaryArgs(dmd, args)
                report = []

                for d in Utilization.getSummaryArgs(dmd, args):
                        if re.compile('^local', 
re.IGNORECASE).match(d.getDeviceName()):
                                if re.compile('^eth, 
re.IGNORECASE').match(interface.getInterfaceName()):
                                        isLocal = 
re.compile(d.zLocalInterfaceNames)
                                        for i in d.os.interfaces():
                                                if isLocal.match(i.name()): 
continue
                                                if not i.monitored(): continue
                                                if i.snmpIgnore(): continue
                                                if not i.speed: continue
                                                total = None
                                                results = 
i.getRRDValues(['ifHCInOctets', 'ifInOctets', 'ifOutOctets', 'ifHCOutOctets'], 
**summary)
                                                input = 
results.get('ifHCInOctets', results.get('ifInOctets', None))
                                                output = 
results.get('ifHCOutOctets', results.get('ifOutOctets', None))
                                                if i.id == 
device.prepId(evt.component):
                                                        descr = i.description
                                                if descr == ' ':
                                                        descr = 'unknown'
                                                if None not in [input, output]:
                                                        total = input + output
                                                r = Utils.Record(device=d, 
interface=i, description=descr, speed=i.speed, input=input, output=output, 
total=total, percentUsed=Utils.percent(total, i.speed / 8))
                                                report.append(r)
                                        return report


Interface_Utilization.rpt

<tal:block tal:define="
     tableName string: interfaceusagereport;
     objects python:here.ReportServer.plugin('interfaceusage',here.REQUEST);
     objects python: (hasattr(request, 'doExport') and list(objects)) or 
objects;
     exportFields python:['device', 'description', 'speed', 'input', 'output', 
'total', 'percentUsed'];
     batch 
python:here.ZenTableManager.getBatch(tableName,objects,sortedHeader='percentUsed',
 sortedSence='desc'); 

">
<tal:block metal:use-macro="here/reportMacros/macros/exportableReport">
<tal:block metal:fill-slot="report">

<tal:block metal:use-macro="here/templates/macros/page1">
<tal:block metal:fill-slot="breadCrumbPane">
    <span metal:use-macro="here/miscmacros/macros/reportBreadCrumbsList"/>    
</tal:block>
<tal:block metal:fill-slot="contentPane">

<tal:block metal:use-macro="here/reportMacros/macros/utilizationForm"/>

<form method="POST" tal:attributes="action request/URL; name string:deviceList"
                        tal:define="tabletitle string: Tunnel Utilization;
                        showfilterbox python:True;
                                                tblcolspan string:7">
<tal:block metal:use-macro="here/zenuimacros/macros/zentable">
<tal:block metal:fill-slot="zentablecontents">

    <tr>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'device','Device')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'interface','Interface')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'descr','Customer Name and ID')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'speed','Speed')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'input','Input')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'output','Output')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'total','Total')"/>
        <th tal:replace="structure python:here.ZenTableManager.getTableHeader(
                            tableName,'percentUsed','% Util')"/>
    </tr>
    <tal:block tal:repeat="r batch">
        <tr tal:define="odd repeat/r/odd"
            tal:attributes="class python:test(odd,'odd','even')">
           <td><a tal:attributes="href r/device/getPrimaryUrlPath"
                  tal:content="r/device/id"/></td>
           <td><a tal:attributes="href r/interface/getPrimaryUrlPath"
                  tal:content="r/interface/id"/></td>
           <td tal:content="python: r.humanBits(r.description)"/>
           <td tal:content="python: r.humanBits(r.speed)"/>
           <td tal:content="python: r.humanBits(r.input, 8)"/>
           <td tal:content="python: r.humanBits(r.output, 8)"/>
           <td tal:content="python: r.humanBits(r.total, 8)"/>
           <td tal:content="python: r.percentString(r.percentUsed, 1)"/>
        </tr>
    </tal:block>
    <tr>
        <td colspan="7" class="tableheader" align='center'>
        <form metal:use-macro="here/zenTableNavigation/macros/navtool"/>
        </td>
    </tr>
</tal:block>
</tal:block>
</form>

</tal:block>
</tal:block>
</tal:block>

</tal:block>
</tal:block>




-------------------- m2f --------------------

Read this topic online here:
http://forums.zenoss.com/viewtopic.php?p=37957#37957

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to