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)
Esempio n. 2
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)
Esempio n. 3
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

                # 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)