def processResults(self, cmd, result):
    """
    Process the results for command "lsdrive -delim :".
    """
    update = False
    datapointMap = dict([(dp.id, dp) for dp in cmd.points])
    devname = cmd.deviceConfig.device

    # returned from datasource component field with ${here/id}
    componentid = cmd.component

    rresult = Utils.cmdParser(cmd.result.output,'id','DRIVE_ID')
    # specific component device
    rresult = rresult[componentid] 


    # drive status raise event
    if rresult['status']!='online': 
      result.events.append(Utils.getEvent(cmd,"Drive status not online",clear=False))
      update = True

    # drive error sequence number
    if rresult['error_sequence_number']!='': 
      result.events.append(Utils.getEvent(cmd,"Drive error sequence number: "+rresult['error_sequence_number'],clear=False))
      update = True
  
    # update current component if needed
    if update:
      scriptbase = ZenScriptBase(noopts = 1, connect = True)
      device = scriptbase.findDevice(devname)
      component = device.drives.findObjectsById(componentid)[0]
      component.drive_status=rresult['status']
      component.error_sequence_number=rresult['error_sequence_number']
      commit()
  def processResults(self, cmd, result):
    
      
    """
    Process the results for command "lsenclosurebattery -delim :".
    """
    datapointMap = dict([(dp.id, dp) for dp in cmd.points])
    devname = cmd.deviceConfig.device
    # returned from datasource component field with ${here/id}
    componentid = cmd.component

    rresult = Utils.cmdParser(cmd.result.output,'battery_id','BAT_ID')

    # specific component device
    rresult = rresult[componentid] 

    
    # recondition_needed raise event
    if rresult['recondition_needed']!='no': 
      result.events.append(Utils.getEvent(cmd,"Battery recondition needed",clear=False))

    #Battery end of life warning raise event
    if rresult['end_of_life_warning']!='no': 
      result.events.append(Utils.getEvent(cmd,"Battery end of life warning",clear=False))

    
    # update current component
    # zencommand does not have direct access to the model and components but
    # maybe theres another way to do this
    
    scriptbase = ZenScriptBase(noopts = 1, connect = True)
    device = scriptbase.findDevice(devname)
    component = device.batteries.findObjectsById(componentid)[0]
    component.battery_status=rresult['status']
    component.charging_status=rresult['charging_status']
    component.recondition_needed=rresult['recondition_needed']
    component.percent_charged=int(rresult['percent_charged'])
    component.end_of_life_warning=rresult['end_of_life_warning']
    commit()
Example #3
0
    def processResults(self, cmd, result):
        """
    Process the results for command "lsdrive -delim :".
    """
        update = False
        datapointMap = dict([(dp.id, dp) for dp in cmd.points])
        devname = cmd.deviceConfig.device

        # returned from datasource component field with ${here/id}
        componentid = cmd.component

        rresult = Utils.cmdParser(cmd.result.output, 'id', 'DRIVE_ID')
        # specific component device
        rresult = rresult[componentid]

        # drive status raise event
        if rresult['status'] != 'online':
            result.events.append(
                Utils.getEvent(cmd, "Drive status not online", clear=False))
            update = True

        # drive error sequence number
        if rresult['error_sequence_number'] != '':
            result.events.append(
                Utils.getEvent(cmd,
                               "Drive error sequence number: " +
                               rresult['error_sequence_number'],
                               clear=False))
            update = True

        # update current component if needed
        if update:
            scriptbase = ZenScriptBase(noopts=1, connect=True)
            device = scriptbase.findDevice(devname)
            component = device.drives.findObjectsById(componentid)[0]
            component.drive_status = rresult['status']
            component.error_sequence_number = rresult['error_sequence_number']
            commit()
    def processResults(self, cmd, results):
        # split data into component blocks
        lines = cmd.result.output.split('\n')

        data = {}
        for line in lines:

            if len(line) == 0:
                continue

            splitted = line.split(' ')
            if len(splitted) < 2:
                continue

            data[splitted[0]] = ' '.join(splitted[1:])

        scriptbase = ZenScriptBase(noopts = 1, connect = True)
        for point in cmd.points:
            if point.id not in self.POINTS:
                continue

            if 'portid' not in point.data:
                log.error("No port id provided: %s" % (point.id,))
                continue

            if 'snmpindex' not in point.data:
                log.error("No snmpindex provided: %s" % (point.id,))
                continue

            oid = self.POINTS[point.id]
            devname = cmd.deviceConfig.device
            portid = point.data['portid']
            snmpindex = point.data['snmpindex']
            key = "%s.%d" % (oid, snmpindex,)

            if key not in data:
                continue

            try:
                value = float(data[key])
            except ValueError:
                continue


            # Update current model
            d = scriptbase.findDevice(devname)
            if d is not None and d.getDeviceClassPath() == self.DEVICE_PATH:

                port = d.SerialPrt._getOb(portid)
                if port is not None:
                    log.debug("setattr(%s, %s, %s)" % (d, point.id, value,))
                    setattr(port, point.id, value)
                    id = d.SerialPrt._setObject(portid, port)
                    commit()
                    #print "*** _getOb(%s)" % (portid,)
                    #print pformat(d.SerialPrt._getOb(portid).__dict__)
                else:
                    log.error("No such attribute: %s on %s" % (
                        point.id, d.getDeviceName(),))

            log.debug("Appending result %s: (%s / %s) %s" % (
                point.id, type(value), value, value,))
            results.values.append((point, value,))

        log.debug(pformat(results))
        return results
    def processResults(self, cmd, results):
        # split data into component blocks
        lines = cmd.result.output.split('\n')

        data = {}
        for line in lines:

            if len(line) == 0:
                continue

            splitted = line.split(' ')
            if len(splitted) < 2:
                continue

            data[splitted[0]] = ' '.join(splitted[1:])

        scriptbase = ZenScriptBase(noopts=1, connect=True)
        for point in cmd.points:
            if point.id not in self.POINTS:
                continue

            if 'portid' not in point.data:
                log.error("No port id provided: %s" % (point.id, ))
                continue

            if 'snmpindex' not in point.data:
                log.error("No snmpindex provided: %s" % (point.id, ))
                continue

            oid = self.POINTS[point.id]
            devname = cmd.deviceConfig.device
            portid = point.data['portid']
            snmpindex = point.data['snmpindex']
            key = "%s.%d" % (
                oid,
                snmpindex,
            )

            if key not in data:
                continue

            try:
                value = float(data[key])
            except ValueError:
                continue

            # Update current model
            d = scriptbase.findDevice(devname)
            if d is not None and d.getDeviceClassPath() == self.DEVICE_PATH:

                port = d.SerialPrt._getOb(portid)
                if port is not None:
                    log.debug("setattr(%s, %s, %s)" % (
                        d,
                        point.id,
                        value,
                    ))
                    setattr(port, point.id, value)
                    id = d.SerialPrt._setObject(portid, port)
                    commit()
                    #print "*** _getOb(%s)" % (portid,)
                    #print pformat(d.SerialPrt._getOb(portid).__dict__)
                else:
                    log.error("No such attribute: %s on %s" % (
                        point.id,
                        d.getDeviceName(),
                    ))

            log.debug("Appending result %s: (%s / %s) %s" % (
                point.id,
                type(value),
                value,
                value,
            ))
            results.values.append((
                point,
                value,
            ))

        log.debug(pformat(results))
        return results