Пример #1
0
    def _processDatasourceResults(self, datasource, results):
        """
        Process a single datasource's results

        @parameter datasource: datasource containg information
        @type datasource: Cmd object
        @parameter results: empty results object
        @type results: ParsedResults object
        """
        exitCode = datasource.result.exitCode
        output = datasource.result.output.strip()
        stderr = datasource.result.stderr.strip()

        if exitCode == 0 and not output:
            msg = "No data returned for command"
            if self._showfullcommand:
                msg += ": %s" % datasource.command
            log.warn("%s %s %s", self.name, datasource.name, msg)

            event = self._makeCmdEvent(datasource, msg)
            if self._showfullcommand:
                event["command"] = datasource.command
            results.events.append(event)
        else:
            try:
                operation = "Creating Parser"
                parser = datasource.parser.create()

                operation = "Running Parser"
                parser.preprocessResults(datasource, log)
                parser.processResults(datasource, results)

                if not results.events and parser.createDefaultEventUsingExitCode:
                    # If there is no event, send one based on the exit code
                    if exitCode == 0:
                        msg = ""
                        severity = Clear
                    else:
                        msg = "Datasource: %s - Code: %s - Msg: %s" % (
                            datasource.name,
                            exitCode,
                            getExitMessage(exitCode),
                        )
                        severity = datasource.severity
                    event = self._makeCmdEvent(datasource, msg, severity)
                    results.events.append(event)
                if stderr:
                    # Add the stderr output to the error events
                    for event in results.events:
                        if event["severity"] not in ("Clear", "Info", "Debug"):
                            event["stderr"] = stderr
            except Exception:
                msg = "Error %s %s" % (operation, datasource.parser)
                log.exception(msg)
                event = self._makeCmdEvent(datasource, msg)
                event["message"] = traceback.format_exc()
                event["output"] = output
                results.events.append(event)
Пример #2
0
    def _processDatasourceResults(self, datasource, results):
        """
        Process a single datasource's results

        @parameter datasource: datasource containg information
        @type datasource: Cmd object
        @parameter results: empty results object
        @type results: ParsedResults object
        """
        exitCode = datasource.result.exitCode
        output = datasource.result.output.strip()
        stderr = datasource.result.stderr.strip()

        if exitCode == 0 and not output:
            msg = "No data returned for command"
            if self._showfullcommand:
                msg += ": %s" % datasource.command
            log.warn("%s %s %s", self.name, datasource.name, msg)

            event = self._makeCmdEvent(datasource, msg)
            if self._showfullcommand:
                event['command'] = datasource.command
            results.events.append(event)
        else:
            try:
                operation = "Creating Parser"
                parser = datasource.parser.create()

                operation = "Running Parser"
                parser.preprocessResults(datasource, log)
                parser.processResults(datasource, results)

                if not results.events and \
                        parser.createDefaultEventUsingExitCode:
                    # If there is no event, send one based on the exit code
                    if exitCode == 0:
                        msg = ""
                        severity = Clear
                    else:
                        msg = "Datasource: %s - Code: %s - Msg: %s" % (
                            datasource.name, exitCode,
                            getExitMessage(exitCode))
                        severity = datasource.severity
                    event = self._makeCmdEvent(datasource, msg, severity)
                    results.events.append(event)
                if stderr:
                    # Add the stderr output to the error events
                    for event in results.events:
                        if event['severity'] not in ('Clear', 'Info', 'Debug'):
                            event['stderr'] = stderr
            except Exception:
                msg = "Error %s %s" % (operation, datasource.parser)
                log.exception(msg)
                event = self._makeCmdEvent(datasource, msg)
                event['message'] = traceback.format_exc()
                event['output'] = output
                results.events.append(event)
Пример #3
0
    def request_exit_status(self, data):
        """
        Gathers the exit code from the device

        @param data: returned value from device
        @type data: packet
        """
        import struct
        self.exitCode = struct.unpack('>L', data)[0]
        log.debug("%s channel %s CommandChannel exit code for %s is %d: %s",
                  self.targetIp, getattr(self.conn, 'localChannelID', None),
                  self.command, self.exitCode, getExitMessage(self.exitCode))
Пример #4
0
    def processResults(self, cmd, results):

        dps = {}

        output = cmd.result.output

        exitCode = cmd.result.exitCode
        severity = cmd.severity

        recv = sent = recvqueue = sentqueue = storesize = 0

        msg, values = '', ''
        #if MuninParser.search(firstline):
        #    msg, values = '', output
        #else:
        #    msg, values = output, ''

        msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (
            cmd.command, exitCode, getExitMessage(exitCode))

        if exitCode != 0:
            results.events.append(dict(device=cmd.deviceConfig.device,
                                       summary=msg,
                                       severity=severity,
                                       message=msg,
                                       performanceData=values,
                                       eventKey=cmd.eventKey,
                                       eventClass=cmd.eventClass,
                                       component=cmd.component))

        log.info(output)
        match =  RecvSendQueue.search(output)
        if match:
            recvqueue, sentqueue = match.groups()
        dps['recvqueue'] = int(recvqueue)
        dps['sentqueue'] = int(sentqueue)

        match =  RecvSendDeliver.search(output)
        if match:
            recv, sent = match.groups()
        dps['recv'] = int(recv)
        dps['sent'] = int(sent)

        match = StoreSize.search(output)
        if match:
            storesize = match.groups()[0]
        dps['storesize'] = int(storesize)

        log.info('recv=%s sent=%s recvqueue=%s sentqueue=%s storesize=%s' % (recv, sent, recvqueue, sentqueue, storesize))

        for dp in cmd.points:
            if dps.has_key(dp.id):
                results.values.append( (dp, dps[dp.id]) )
Пример #5
0
    def request_exit_status(self, data):
        """
        Gathers the exit code from the device

        @param data: returned value from device
        @type data: packet
        """
        import struct
        self.exitCode = struct.unpack('>L', data)[0]
        log.debug("%s channel %s CommandChannel exit code for %s is %d: %s",
                  self.targetIp, getattr(self.conn, 'localChannelID',
                                         None), self.command, self.exitCode,
                  getExitMessage(self.exitCode))
Пример #6
0
    def processResults(self, cmd, result):
        output = cmd.result.output
        output = output.split('\n')[0].strip()
        exitCode = cmd.result.exitCode
        severity = cmd.severity
        if output.find('|') >= 0:
            msg, values = output.split('|', 1)
            msg, values = output, ''

        elif CacParser.search(output):
            msg, values = '', output

        elif len(cmd.points) == 1:
            # Special case for plugins that only return one datapoint
            try:
                number = float(output)
                result.values.append((cmd.points[0], number))
                msg, values = '', output
            except:
                msg, values = output, ''

        else:
            msg, values = output, ''

        msg = msg.strip() or 'Datasource: %s - Code: %s - Msg: %s' % (
            cmd.name, exitCode, getExitMessage(exitCode))
        if exitCode != 0:
            if exitCode == 2:
                severity = min(severity + 1, 5)
            result.events.append(
                dict(device=cmd.deviceConfig.device,
                     summary=msg,
                     severity=severity,
                     message=msg,
                     performanceData=values,
                     eventKey=cmd.eventKey,
                     eventClass=cmd.eventClass,
                     component=cmd.component))

        for parts in CacParser.findall(values):
            label = parts[0].replace("''", "'")
            try:
                value = float(parts[2])
            except Exception:
                value = 'U'
            for dp in cmd.points:
                if dp.id == label:
                    result.values.append((dp, value))
                    break
Пример #7
0
    def _addDefaultEvent(self, datasource, results):
        """
        If there is no event, send one based on the exit code.
        """
        exitCode = datasource.result.exitCode
        if exitCode == 0:
            msg = ''
            severity = 0
        else:
            msg = 'Datasource: %s - Code: %s - Msg: %s' % (
                datasource.name, exitCode, getExitMessage(exitCode))
            severity = datasource.severity

        ev = self._makeCmdEvent(datasource, msg, severity)
        results.events.append(ev)
Пример #8
0
    def _addDefaultEvent(self, datasource, results):
        """
        If there is no event, send one based on the exit code.
        """
        exitCode = datasource.result.exitCode
        if exitCode == 0:
            msg = ''
            severity = 0
        else:
            msg = 'Datasource: %s - Code: %s - Msg: %s' % (
                datasource.name, exitCode, getExitMessage(exitCode))
            severity = datasource.severity

        ev = self._makeCmdEvent(datasource, msg, severity)
        results.events.append(ev)
Пример #9
0
    def processResults(self, cmd, result):
        output = cmd.result.output
        output = output.split('\n')[0].strip()
        exitCode = cmd.result.exitCode
        severity = cmd.severity
        if output.find('|') >= 0:
            msg, values = output.split('|', 1)
            msg, values = output, ''

        elif CacParser.search(output):
            msg, values = '', output

        elif len(cmd.points) == 1:
            # Special case for plugins that only return one datapoint
            try:
                number = float(output)
                result.values.append( (cmd.points[0], number) )
                msg, values = '', output
            except:
                msg, values = output, ''

        else:
            msg, values = output, ''

        msg = msg.strip() or 'Datasource: %s - Code: %s - Msg: %s' % (
            cmd.name, exitCode, getExitMessage(exitCode))
        if exitCode != 0:
            if exitCode == 2:
                severity = min(severity + 1, 5)
            result.events.append(dict(device=cmd.deviceConfig.device,
                                      summary=msg,
                                      severity=severity,
                                      message=msg,
                                      performanceData=values,
                                      eventKey=cmd.eventKey,
                                      eventClass=cmd.eventClass,
                                      component=cmd.component))

        for parts in CacParser.findall(values):
            label = parts[0].replace("''", "'")
            try:
                value = float(parts[2])
            except Exception:
                value = 'U'
            for dp in cmd.points:
                if dp.id == label:
                    result.values.append( (dp, value) )
                    break
Пример #10
0
 def processEnded(self, reason):
     try:
         self.parent.worker_processes.discard(self)
         ended_proc = self.parent.workerprocessmap.pop(
             self.pid, None)
         ended_proc_age = time.time() - ended_proc.spawn_time
         self.log.warning(
             "Worker %s (%s), age %f secs, exited with status: %s (%s)",
             self.workerNum, self.pid, ended_proc_age,
             reason.value.exitCode or -1,
             getExitMessage(reason.value.exitCode))
         # if not shutting down, restart a new worker
         if not self.parent.shutdown:
             self.log.info("Starting new zenhubworker")
             self.parent.createWorker(self.workerNum)
     except Exception:
         self.log.exception('Exception in zenhub worker'
                            ' processEnded')
Пример #11
0
    def processResults(self, cmd, result):
        output = cmd.result.output
        exitCode = cmd.result.exitCode
        severity = cmd.severity
        if exitCode == 0:
            severity = 0
        elif exitCode == 2:
            severity = min(severity + 1, 5)

        evt = {
            "device": cmd.deviceConfig.device,
            "message": output,
            "severity": severity,
            "component": cmd.component,
            "eventKey": cmd.eventKey,
            "eventClass": cmd.eventClass,
        }
        try:
            summary, rawPerfData = self.splitMultiLine(output)
        except Exception as ex:
            evt.update({
                "error_codes":
                "Datasource: %s - Code: %s - Msg: %s" %
                (cmd.name, exitCode, getExitMessage(exitCode)),
                "performanceData":
                None,
                "summary":
                str(ex),
            })
        else:
            evt.update({
                "performanceData": rawPerfData,
                "summary": summary[0],
                "message": '\n'.join(summary),
            })
            perfData = self.processPerfData(rawPerfData)
            for dp in cmd.points:
                if dp.id in perfData:
                    result.values.append((dp, perfData[dp.id]))
        result.events.append(evt)
Пример #12
0
    def processResults(self, cmd, result):
        #grab the output resulting from the command
        output = cmd.result.output
        output = output.split('\n')[0].strip()
        #get the exit code from the command
        # not exactly sure what it means
        exitCode = cmd.result.exitCode
        #gets the severityt that is associated with the command
        severity = cmd.severity
        #output looks like eg ("guestperf|memUsage=1000 ...")
        #make sure we are getting the correct output
        if output.find('|') >= 0:
            #msg = substring left of the |
            #values = substring right of the |
            msg, values = output.split('|', 1)
        else:
            #msg = output
            #values = ''
            msg, values = output, ''
        msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (
            cmd.command, exitCode, getExitMessage(exitCode))
        if exitCode != 0:
            result.events.append(
                dict(device=cmd.deviceConfig.device,
                     summary=msg,
                     severity=severity,
                     message=msg,
                     performanceData=values,
                     eventKey=cmd.eventKey,
                     eventClass=cmd.eventClass,
                     component=cmd.component))

        for value in values.split(' '):
            if value.find('=') > 0:
                label, val = value.split('=')
                for dp in cmd.points:
                    if dp.id == label:
                        result.values.append((dp, val))
                        break
Пример #13
0
 def _errors_found(self, cmd, result):
     """
     Run through a series of error checks
     @param cmd: The Command Object which was passed into processResults
     @rtype: Boolean
     @return: Boolean indicating if errors were found
     """
     errors_found = False
     #Check for non 0 exit code in the command
     exit_code = cmd.result.exitCode
     if exit_code != 0:
         errors_found = True
         msg = 'VarnishStat cmd parser error: %s - Code: %s - Msg: %s' % (
             cmd.command, exit_code, getExitMessage(exit_code))
         result.events.append(dict(device=cmd.deviceConfig.device,
                                   summary=msg,
                                   severity=cmd.severity,
                                   eventKey=cmd.eventKey,
                                   eventClass=cmd.eventClass,
                                   rawOutput=cmd.result.output,
                                   component=cmd.component))  
     return errors_found  
Пример #14
0
    def processResults(self, cmd, result):
        output = cmd.result.output
        exitCode = cmd.result.exitCode
        severity = cmd.severity
        if exitCode == 0:
            severity = 0
        elif exitCode == 2:
            severity = min(severity + 1, 5)

        evt = {
                "device": cmd.deviceConfig.device,
                "message": output,
                "severity": severity,
                "component": cmd.component,
                "eventKey": cmd.eventKey,
                "eventClass": cmd.eventClass,
            }
        try:
            summary, rawPerfData = self.splitMultiLine(output)
        except Exception as ex:
            evt.update({
                "error_codes": "Datasource: %s - Code: %s - Msg: %s" % (
                   cmd.name, exitCode, getExitMessage(exitCode)
                ),
                "performanceData": None,
                "summary": str(ex),
            })
        else:
            evt.update({
                "performanceData": rawPerfData,
                "summary": summary[0],
                "message": '\n'.join(summary),
            })
            perfData = self.processPerfData(rawPerfData)
            for dp in cmd.points:
                if dp.id in perfData:
                    result.values.append((dp, perfData[dp.id]))
        result.events.append(evt)
Пример #15
0
 def _errors_found(self, cmd, result):
     """
     Run through a series of error checks
     @param cmd: The Command Object which was passed into processResults
     @rtype: Boolean
     @return: Boolean indicating if errors were found
     """
     errors_found = False
     #Check for non 0 exit code in the command
     exit_code = cmd.result.exitCode
     if exit_code != 0:
         errors_found = True
         msg = 'VarnishStat cmd parser error: %s - Code: %s - Msg: %s' % (
             cmd.command, exit_code, getExitMessage(exit_code))
         result.events.append(
             dict(device=cmd.deviceConfig.device,
                  summary=msg,
                  severity=cmd.severity,
                  eventKey=cmd.eventKey,
                  eventClass=cmd.eventClass,
                  rawOutput=cmd.result.output,
                  component=cmd.component))
     return errors_found
Пример #16
0
	def processResults(self, cmd, result):
		#grab the output resulting from the command
		output = cmd.result.output
		output = output.split('\n')[0].strip()
		#get the exit code from the command
		# not exactly sure what it means
		exitCode = cmd.result.exitCode
		#gets the severityt that is associated with the command
		severity = cmd.severity
		#output looks like eg ("guestperf|memUsage=1000 ...")
		#make sure we are getting the correct output
		if output.find('|') >= 0:
			#msg = substring left of the |
			#values = substring right of the |
			msg, values = output.split('|', 1)
		else:
			#msg = output
			#values = ''
			msg, values = output, ''
		msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (cmd.command, exitCode, getExitMessage(exitCode))
		if exitCode != 0:
			result.events.append(dict(device=cmd.deviceConfig.device,
									  summary=msg,
									  severity=severity,
									  message=msg,
									  performanceData=values,
									  eventKey=cmd.eventKey,
									  eventClass=cmd.eventClass,
									  component=cmd.component))

		for value in values.split(' '):
			if value.find('=') > 0:
				label, val = value.split('=')
				for dp in cmd.points:
					if dp.id == label:
						result.values.append( (dp, val) )
						break
Пример #17
0
    def _processDatasourceResults(self, datasource, response, parsed):
        """
        Process a single datasource's results

        @parameter datasource: Data about datasource
        @type datasource: Cmd object
        @parameter response: Result of the datasource command
        @type response: an IRunner object (SshRunner)
        @parameter parsed: Parsed results are added to this object.
        @type parsed: ParsedResults object
        """
        exitCode = response.exitCode
        datasource.result = copy(response)
        output = response.output.strip()
        stderr = response.stderr.strip()

        if exitCode == 0 and not output:
            msg = "No data returned for command"
            if self._showfullcommand:
                msg += ": %s" % datasource.command
            log.warn("%s %s %s", self.name, datasource.name, msg)

            event = makeCmdEvent(self._devId, datasource, msg)
            if self._showfullcommand:
                event["command"] = datasource.command
            if stderr:
                event["stderr"] = stderr
            parsed.events.append(event)
            return

        try:
            operation = "Creating Parser"
            parser = datasource.parser.create()

            operation = "Running Parser"
            parser.preprocessResults(datasource, log)
            parser.processResults(datasource, parsed)

            if (not parsed.events and parser.createDefaultEventUsingExitCode):
                if exitCode == 0:
                    msg = ""
                    severity = Clear
                else:
                    msg = "Datasource: %s - Code: %s - Msg: %s" % (
                        datasource.name,
                        exitCode,
                        getExitMessage(exitCode),
                    )
                    severity = datasource.severity
                event = makeCmdEvent(
                    self._devId,
                    datasource,
                    msg,
                    severity=severity,
                )
                parsed.events.append(event)

            # Clear any timeout event
            parsed.events.append(
                makeCmdTimeoutEvent(self._devId, datasource, severity=Clear), )

            if stderr:
                # Add the stderr output to the error events.
                # Note: although the command succeeded, the parser may put an
                # error event into the results.
                for event in parsed.events:
                    if event["severity"] not in ("Clear", "Info", "Debug"):
                        event["stderr"] = stderr
        except Exception:
            msg = "Error %s %s" % (operation, datasource.parser)
            log.exception(msg)
            event = makeCmdEvent(self._devId, datasource, msg)
            event["message"] = traceback.format_exc()
            event["output"] = output
            if stderr:
                event["stderr"] = stderr
            parsed.events.append(event)
        else:
            # Determine whether a non-timeout related event exists.
            hasNonTimeoutEvent = any(
                (event.get("eventKey") == datasource.eventKey
                 for event in parsed.events))
            if not hasNonTimeoutEvent:
                # No existing non-timeout event, so add a Clear event to
                # clear any prior events on this datasource.
                parsed.events.append(
                    makeCmdEvent(
                        self._devId,
                        datasource,
                        "Datasource %s command completed successfully" %
                        datasource.name,
                        severity=Clear,
                    ), )