Pobice / ZenPacks.community.WhatsDownPortlet

Zenoss portlet to list Down Devices
2 stars 0 forks source link

Zenoss 4: No ping failure counts shown #1

Open Pobice opened 12 years ago

Pobice commented 12 years ago

Zenpack works ok in Zenoss 4 - apart from ping count only shows "Down"

rebelinux commented 12 years ago

change init.py:

row = { 'Device': d.getPrettyLink(), 'Failed Pings': d.getPingStatusString() }

to

row = { 'Device': d.getPrettyLink(), 'Failed Pings': d.getPingStatusNumber() }

Also there is a bug in the getPingStatus and getPingStatusNumber it show always 1 ping count.

Pobice commented 11 years ago

Thanks - I suspected as much.

Pobice commented 11 years ago

Looks like I may be able to do something with the 'facades' to get the failed pint count zep_facade = getFacade('zep') zep_facade.getDevicePingIssues() [('user-TOSH.home', 1, 51)]

rebelinux commented 11 years ago

This works for me:

import json def getJSONDownDevices(self, path='', prodstate=''): """ Given a report class path, returns a list of links to child reports in a format suitable for a TableDatasource. """

This function will be monkey-patched onto zport, so

        # references to self should be taken as referring to zport
        # Add the base path to the path given
        path = '/zport/dmd/Devices/' + path.strip('/')
        if prodstate=='':
            prodstate='1000'

        # Create the empty structure of the response object
        response = { 'columns': ['Device','Failed Pings'], 'data': [] }

        # Retrieve the ReportClass object for the path given. If
        # nothing can be found, return an empty response
        try:
            deviceClass = self.dmd.unrestrictedTraverse(path)
        except KeyError:
            return json.dumps(response)

        zep_facade = getFacade('zep')
        issues = zep_facade.getDevicePingIssues()
        for x in issues:
            device = x[0]
            d = self.dmd.Devices.findDevice(device)
            if d.getPingStatus()>0 and d.productionState>=int(prodstate) :  
        devicesinclass = deviceClass.getSubDevices()
        if d in devicesinclass: 
                    row = { 'Device': d.getPrettyLink(), 'Failed Pings': x[2] }
                    response['data'].append(row)            
        return json.dumps(response)