def _getCmd(self, component, command, exitCode, filename, points):
        cmd = Cmd()

        # DeviceConfig no longer exists as of Zenoss 4.
        try:
            from Products.ZenRRD.zencommand import DeviceConfig
            cmd.deviceConfig = DeviceConfig()
        except ImportError:
            from Products.ZenCollector.services.config import DeviceProxy
            cmd.deviceConfig = DeviceProxy()

        cmd.deviceConfig.device = 'testDevice'
        cmd.component = component
        cmd.command = command
        cmd.eventClass = '/Cmd/Fail'
        cmd.eventKey = 'interfaceIncomingBytes'
        cmd.result = FakeCmdResult(exitCode, loadData(filename))
        cmd.points = points
        # Since we only consider the OVS records within cycleTime for event
        # processing, we need to do something so that records for unittests
        # will always be processed. This is achieved by
        # setting a huge value for cycleTime
        cmd.cycleTime = 1430000000

        return cmd
    def _getCmd(self, output_filename):
        cmd = Cmd()

        # DeviceConfig no longer exists as of Zenoss 4.
        try:
            from Products.ZenRRD.zencommand import DeviceConfig
            cmd.deviceConfig = DeviceConfig()
        except ImportError:
            from Products.ZenCollector.services.config import DeviceProxy
            cmd.deviceConfig = DeviceProxy()

        cmd.deviceConfig.device = 'swift'
        cmd.component = 'swift'
        cmd.command = 'poll_swift_recon -H 127.0.0.1'
        cmd.eventClass = '/Status/Swift'
        cmd.eventKey = 'rabbitmq_node_status'
        cmd.result = FakeCmdResult(0, loadData(output_filename))

        metrics = (
            'asyncPending',
            'diskSizeAvg',
            'diskSizeMax',
            'diskSizeMin',
            'diskUsageAvg',
            'diskUsageMax',
            'diskUsageMin',
            'load1',
            'load15',
            'load15PerDisk',
            'load5',
            'pidRate',
            'quarantinedAccounts',
            'quarantinedContainers',
            'quarantinedObjects',
            'replicationTime',
            'runningProcs',
            'totalDisks',
            'totalProcs',
            'unmountedDisks',
            )

        points = []
        for metric in metrics:
            dpc = DataPointConfig()
            dpc.id = metric
            dpc.component = 'swift'
            points.append(dpc)

        cmd.points = points

        return cmd
Exemplo n.º 3
0
    def _getCmd(self, component, command, exitCode, output_filename, points):
        cmd = Cmd()

        # DeviceConfig no longer exists as of Zenoss 4.
        try:
            from Products.ZenRRD.zencommand import DeviceConfig
            cmd.deviceConfig = DeviceConfig()
        except ImportError:
            from Products.ZenCollector.services.config import DeviceProxy
            cmd.deviceConfig = DeviceProxy()

        cmd.deviceConfig.device = 'maverick'
        cmd.component = component
        cmd.command = command
        cmd.eventClass = '/Status/RabbitMQ'
        cmd.eventKey = 'rabbitmq_node_status'
        cmd.result = FakeCmdResult(exitCode, loadData(output_filename))
        cmd.points = points

        return cmd
    def _getCmd(self, component, command, exitCode, output_filename, points):
        cmd = Cmd()

        # DeviceConfig no longer exists as of Zenoss 4.
        try:
            from Products.ZenRRD.zencommand import DeviceConfig
            cmd.deviceConfig = DeviceConfig()
        except ImportError:
            from Products.ZenCollector.services.config import DeviceProxy
            cmd.deviceConfig = DeviceProxy()

        cmd.deviceConfig.device = 'maverick'
        cmd.component = component
        cmd.command = command
        cmd.eventClass = '/Status/RabbitMQ'
        cmd.eventKey = 'rabbitmq_node_status'
        cmd.result = FakeCmdResult(exitCode, loadData(output_filename))
        cmd.points = points

        return cmd
Exemplo n.º 5
0
    def _getComponentConfig(self, comp, device, perfServer, cmds):
        for templ in comp.getRRDTemplates():
            for ds in templ.getRRDDataSources(self.dsType):
                if not ds.enabled:
                    continue

                # Ignore SSH datasources if no username set
                useSsh = getattr(ds, 'usessh', False)
                if useSsh and not device.zCommandUsername:
                    self._warnUsernameNotSet(device)
                    continue

                parserName = getattr(ds, "parser", "Auto")
                ploader = getParserLoader(self.dmd, parserName)
                if ploader is None:
                    log.error("Could not load %s plugin", parserName)
                    continue

                cmd = Cmd()
                cmd.useSsh = useSsh
                cmd.name = "%s/%s" % (templ.id, ds.id)
                cmd.cycleTime = self._getDsCycleTime(comp, templ, ds)
                cmd.component = ds.getComponent(comp)
                cmd.eventClass = ds.eventClass
                cmd.eventKey = ds.eventKey or ds.id
                cmd.severity = ds.severity
                cmd.parser = ploader
                cmd.ds = ds.titleOrId()
                cmd.points = self._getDsDatapoints(comp, ds, ploader, perfServer)

                if isinstance(comp, OSProcess):
                    # save off the regex's specified in the UI to later run
                    # against the processes running on the device
                    cmd.includeRegex = comp.includeRegex
                    cmd.excludeRegex = comp.excludeRegex
                    cmd.replaceRegex = comp.replaceRegex
                    cmd.replacement  = comp.replacement
                    cmd.primaryUrlPath = comp.processClassPrimaryUrlPath()
                    cmd.generatedId = comp.id
                    cmd.displayName = comp.displayName

                # If the datasource supports an environment dictionary, use it
                cmd.env = getattr(ds, 'env', None)

                try:
                    cmd.command = ds.getCommand(comp)
                except ConflictError: raise
                except Exception: # TALES error
                    msg = "TALES error for device %s datasource %s" % (
                               device.id, ds.id)
                    details = dict(
                           template=templ.id,
                           datasource=ds.id,
                           affected_device=device.id,
                           affected_component=comp.id,
                           resolution='Could not create a command to send to zencommand' \
                                      ' because TALES evaluation failed.  The most likely' \
                                      ' cause is unescaped special characters in the command.' \
                                      ' eg $ or %')
                    # This error might occur many, many times
                    self._sendCmdEvent('localhost', msg, **details)
                    continue

                self.enrich(comp, cmd, templ, ds)
                cmds.add(cmd)

        return comp.getThresholdInstances(self.dsType)
Exemplo n.º 6
0
    def _getComponentConfig(self, comp, device, perfServer, cmds):
        for templ in comp.getRRDTemplates():
            for ds in templ.getRRDDataSources(self.dsType):
                if not ds.enabled:
                    continue

                # Ignore SSH datasources if no username set
                useSsh = getattr(ds, 'usessh', False)
                if useSsh and not device.zCommandUsername:
                    self._warnUsernameNotSet(device)
                    continue

                parserName = getattr(ds, "parser", "Auto")
                ploader = getParserLoader(self.dmd, parserName)
                if ploader is None:
                    log.error("Could not load %s plugin", parserName)
                    continue

                cmd = Cmd()
                cmd.useSsh = useSsh
                cmd.name = "%s/%s" % (templ.id, ds.id)
                cmd.cycleTime = self._getDsCycleTime(comp, templ, ds)
                cmd.component = ds.getComponent(comp)
                cmd.eventClass = ds.eventClass
                cmd.eventKey = ds.eventKey or ds.id
                cmd.severity = ds.severity
                cmd.parser = ploader
                cmd.ds = ds.titleOrId()
                cmd.points = self._getDsDatapoints(comp, ds, ploader,
                                                   perfServer)

                # If the datasource supports an environment dictionary, use it
                cmd.env = getattr(ds, 'env', None)

                try:
                    cmd.command = ds.getCommand(comp)
                except Exception as ex:  # TALES error
                    msg = "TALES error for device %s datasource %s" % (
                        device.id, ds.id)
                    details = dict(
                           template=templ.id,
                           datasource=ds.id,
                           affected_device=device.id,
                           affected_component=comp.id,
                           tb_exception=str(ex),
                           resolution='Could not create a command to send to zencommand' \
                                      ' because TALES evaluation failed.  The most likely' \
                                      ' cause is unescaped special characters in the command.' \
                                      ' eg $ or %')
                    # This error might occur many, many times
                    self._sendCmdEvent('localhost', msg, **details)
                    continue

                self.enrich(comp, cmd, templ, ds)
                cmds.add(cmd)

        return comp.getThresholdInstances(self.dsType)
Exemplo n.º 7
0
    def _getComponentConfig(self, comp, device, perfServer, cmds):
        for templ in comp.getRRDTemplates():
            for ds in templ.getRRDDataSources(self.dsType):
                if not ds.enabled:
                    continue

                # Ignore SSH datasources if no username set
                useSsh = getattr(ds, 'usessh', False)
                if useSsh and not device.zCommandUsername:
                    self._warnUsernameNotSet(device)
                    continue

                # clear any lingering no-username events
                self._clearUsernameNotSet(device)

                parserName = getattr(ds, "parser", "Auto")
                ploader = getParserLoader(self.dmd, parserName)
                if ploader is None:
                    log.error("Could not load %s plugin", parserName)
                    continue

                cmd = Cmd()
                cmd.useSsh = useSsh
                cmd.name = "%s/%s" % (templ.id, ds.id)
                cmd.cycleTime = self._getDsCycleTime(comp, templ, ds)
                cmd.component = ds.getComponent(comp, device=device)
                cmd.eventClass = ds.eventClass
                cmd.eventKey = ds.eventKey or ds.id
                cmd.severity = ds.severity
                cmd.parser = ploader
                cmd.ds = ds.titleOrId()
                cmd.points = self._getDsDatapoints(device, comp, ds, ploader, perfServer)

                if isinstance(comp, OSProcess):
                    # save off the regex's specified in the UI to later run
                    # against the processes running on the device
                    cmd.includeRegex = comp.includeRegex
                    cmd.excludeRegex = comp.excludeRegex
                    cmd.replaceRegex = comp.replaceRegex
                    cmd.replacement  = comp.replacement
                    cmd.primaryUrlPath = comp.processClassPrimaryUrlPath()
                    cmd.generatedId = comp.id
                    cmd.displayName = comp.displayName
                    cmd.sequence = comp.osProcessClass().sequence

                # If the datasource supports an environment dictionary, use it
                cmd.env = getattr(ds, 'env', None)

                try:
                    # Since 5.2.3 (ZEN-26606) we pass the device to avoid calling
                    # device() on the component all the time. This can break some
                    # zenpacks (ZEN-27076). To avoid having to update a bunch of zps
                    # we use inpect to figure out if the method accepts the device
                    # as argument
                    if "device" in getargspec(ds.getCommand).args:
                        cmd.command = ds.getCommand(comp, device=device)
                    else:
                        cmd.command = ds.getCommand(comp)
                except Exception as ex: # TALES error
                    msg = "TALES error for device %s datasource %s" % (
                               device.id, ds.id)
                    details = dict(
                           template=templ.id,
                           datasource=ds.id,
                           affected_device=device.id,
                           affected_component=comp.id,
                           tb_exception=str(ex),
                           resolution='Could not create a command to send to zencommand' \
                                      ' because TALES evaluation failed.  The most likely' \
                                      ' cause is unescaped special characters in the command.' \
                                      ' eg $ or %')
                    # This error might occur many, many times
                    self._sendCmdEvent('localhost', msg, **details)
                    continue

                self.enrich(comp, cmd, templ, ds)
                cmds.add(cmd)

        return comp.getThresholdInstances(self.dsType)
    def _getComponentConfig(self, comp, device, perfServer, cmds):
        for templ in comp.getRRDTemplates():
            for ds in templ.getRRDDataSources(self.dsType):
                if not ds.enabled:
                    continue

                # Ignore SSH datasources if no username set
                useSsh = getattr(ds, "usessh", False)
                if useSsh and not device.zCommandUsername:
                    self._warnUsernameNotSet(device)
                    continue

                parserName = getattr(ds, "parser", "Auto")
                ploader = getParserLoader(self.dmd, parserName)
                if ploader is None:
                    log.error("Could not load %s plugin", parserName)
                    continue

                cmd = Cmd()
                cmd.useSsh = useSsh
                cmd.name = "%s/%s" % (templ.id, ds.id)
                cmd.cycleTime = self._getDsCycleTime(comp, templ, ds)
                cmd.component = ds.getComponent(comp)
                cmd.eventClass = ds.eventClass
                cmd.eventKey = ds.eventKey or ds.id
                cmd.severity = ds.severity
                cmd.parser = ploader
                cmd.ds = ds.titleOrId()
                cmd.points = self._getDsDatapoints(comp, ds, ploader, perfServer)

                # If the datasource supports an environment dictionary, use it
                cmd.env = getattr(ds, "env", None)

                try:
                    cmd.command = ds.getCommand(comp)
                except Exception as ex:  # TALES error
                    msg = "TALES error for device %s datasource %s" % (device.id, ds.id)
                    details = dict(
                        template=templ.id,
                        datasource=ds.id,
                        affected_device=device.id,
                        affected_component=comp.id,
                        tb_exception=str(ex),
                        resolution="Could not create a command to send to zencommand"
                        " because TALES evaluation failed.  The most likely"
                        " cause is unescaped special characters in the command."
                        " eg $ or %",
                    )
                    # This error might occur many, many times
                    self._sendCmdEvent("localhost", msg, **details)
                    continue

                self.enrich(comp, cmd, templ, ds)
                cmds.add(cmd)

        return comp.getThresholdInstances(self.dsType)
    def _getComponentConfig(self, comp, device, perfServer, cmds):
        for templ in comp.getRRDTemplates():
            for ds in templ.getRRDDataSources(self.dsType):
                if not ds.enabled:
                    continue

                # Ignore SSH datasources if no username set
                useSsh = getattr(ds, 'usessh', False)
                if useSsh and not device.zCommandUsername:
                    self._warnUsernameNotSet(device)
                    continue

                # clear any lingering no-username events
                self._clearUsernameNotSet(device)

                parserName = getattr(ds, "parser", "Auto")
                ploader = getParserLoader(self.dmd, parserName)
                if ploader is None:
                    log.error("Could not load %s plugin", parserName)
                    continue

                cmd = Cmd()
                cmd.useSsh = useSsh
                cmd.name = "%s/%s" % (templ.id, ds.id)
                cmd.cycleTime = self._getDsCycleTime(comp, templ, ds)
                cmd.component = ds.getComponent(comp, device=device)
                cmd.eventClass = ds.eventClass
                cmd.eventKey = ds.eventKey or ds.id
                cmd.severity = ds.severity
                cmd.parser = ploader
                cmd.ds = ds.titleOrId()
                cmd.points = self._getDsDatapoints(device, comp, ds, ploader, perfServer)

                if isinstance(comp, OSProcess):
                    # save off the regex's specified in the UI to later run
                    # against the processes running on the device
                    cmd.includeRegex = comp.includeRegex
                    cmd.excludeRegex = comp.excludeRegex
                    cmd.replaceRegex = comp.replaceRegex
                    cmd.replacement  = comp.replacement
                    cmd.primaryUrlPath = comp.processClassPrimaryUrlPath()
                    cmd.generatedId = comp.id
                    cmd.displayName = comp.displayName
                    cmd.sequence = comp.osProcessClass().sequence

                # If the datasource supports an environment dictionary, use it
                cmd.env = getattr(ds, 'env', None)

                try:
                    # Since 5.2.3 (ZEN-26606) we pass the device to avoid calling
                    # device() on the component all the time. This can break some
                    # zenpacks (ZEN-27076). To avoid having to update a bunch of zps
                    # we use inpect to figure out if the method accepts the device
                    # as argument
                    if "device" in getargspec(ds.getCommand).args:
                        cmd.command = ds.getCommand(comp, device=device)
                    else:
                        cmd.command = ds.getCommand(comp)
                except Exception as ex: # TALES error
                    msg = "TALES error for device %s datasource %s" % (
                               device.id, ds.id)
                    details = dict(
                           template=templ.id,
                           datasource=ds.id,
                           affected_device=device.id,
                           affected_component=comp.id,
                           tb_exception=str(ex),
                           resolution='Could not create a command to send to zencommand' \
                                      ' because TALES evaluation failed.  The most likely' \
                                      ' cause is unescaped special characters in the command.' \
                                      ' eg $ or %')
                    # This error might occur many, many times
                    self._sendCmdEvent('localhost', msg, **details)
                    continue

                self.enrich(comp, cmd, templ, ds)
                cmds.add(cmd)

        return comp.getThresholdInstances(self.dsType)