def params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                'powershell Cluster Services',
                'powershell Cluster Resources',
                'Custom Command',
                'DCDiag'):
            resource = '\\' + resource
        if safe_hasattr(context, 'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        if safe_hasattr(context, 'instancename'):
            instancename = context.instancename
        else:
            instancename = ''

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join((context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) + 1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except(AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title
        if contexttitle == servername and resource == 'get-clustergroup':
            contexttitle = ''

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        try:
            script = datasource.talesEval(datasource.script, context)
        except:
            script = ''
            log.error('Invalid tales expression in custom command script')

        return dict(resource=resource,
            strategy=datasource.strategy,
            instancename=instancename,
            servername=servername,
            script=script,
            parser=parser,
            usePowershell=datasource.usePowershell,
            contextrelname=contextrelname,
            contextcompname=contextcompname,
            contextmodname=contextmodname,
            contexttitle=contexttitle)
Exemplo 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 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

                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 params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                'powershell Cluster Services',
                'powershell Cluster Resources',
                'Custom Command'):
            resource = '\\' + resource
        if safe_hasattr(
                context,
                'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        if safe_hasattr(context, 'instancename'):
            instancename = context.instancename
        else:
            instancename = ''

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join(
                (context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) +
                                         1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except (AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title
        if contexttitle == servername and resource == 'get-clustergroup':
            contexttitle = ''

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    servername=servername,
                    script=datasource.talesEval(datasource.script, context),
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle)
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 params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                                        'Custom Command',
                                        'DCDiag',
                                        'powershell MSSQL Instance',
                                        'powershell MSSQL Job'):
            resource = '\\' + resource
        if safe_hasattr(
                context,
                'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        instancename = getattr(context, 'instancename', '')

        instanceid = getattr(context, 'id', '')

        version = getattr(context, 'sql_server_version', 0)
        if version:
            # ensure version is a string
            match = re.match('(\d+)\..*', str(version))
            if match:
                version = match.groups()[0]
            else:
                version = 0

        owner_node_ip = None
        if hasattr(context, 'cluster_node_server'):
            owner_node, _ = context.cluster_node_server.split('//')
            owner_node_ip = getattr(context, 'owner_node_ip', None)
            if not owner_node_ip:
                try:
                    owner_node_ip = context.device(
                    ).clusterhostdevicesdict.get(owner_node, None)
                except Exception:
                    pass

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join(
                (context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) +
                                         1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except (AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        script = get_script(datasource, context)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    instanceid=instanceid,
                    servername=servername,
                    script=script,
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle,
                    version=version,
                    owner_node_ip=owner_node_ip)
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 params(cls, datasource, context):
        resource = datasource.talesEval(datasource.resource, context)
        if not resource.startswith('\\') and \
            datasource.strategy not in ('powershell MSSQL',
                                        'Custom Command',
                                        'DCDiag',
                                        'powershell MSSQL Instance',
                                        'powershell MSSQL Job'):
            resource = '\\' + resource
        if safe_hasattr(context, 'perfmonInstance') and context.perfmonInstance is not None:
            resource = context.perfmonInstance + resource

        instancename = getattr(context, 'instancename', '')

        instanceid = getattr(context, 'id', '')

        version = getattr(context, 'sql_server_version', 0)
        if version:
            # ensure version is a string
            match = re.match('(\d+)\..*', str(version))
            if match:
                version = match.groups()[0]
            else:
                version = 0

        owner_node_ip = None
        if hasattr(context, 'cluster_node_server'):
            owner_node, _ = context.cluster_node_server.split('//')
            owner_node_ip = getattr(context, 'owner_node_ip', None)
            if not owner_node_ip:
                try:
                    owner_node_ip = context.device().clusterhostdevicesdict.get(owner_node, None)
                except Exception:
                    pass

        try:
            contextURL = context.getPrimaryUrlPath()
            deviceURL = urlparse(context.getParentDeviceUrl())
            contextInstance = urllib.quote("/".join((context.getParentNode().id, context.id)))
            contextcompname = contextURL[len(deviceURL.path) + 1:-len(contextInstance) - 1]
            contextrelname = context.getParentNode().id
            contextmodname = context.__module__

        except(AttributeError):
            contextmodname = ''
            contextrelname = ''
            contextcompname = ''

        contexttitle = context.title

        servername = context.device().title

        if len(servername) == 0:
            servername = ''

        parser = getParserLoader(context.dmd, datasource.parser)

        script = get_script(datasource, context)

        return dict(resource=resource,
                    strategy=datasource.strategy,
                    instancename=instancename,
                    instanceid=instanceid,
                    servername=servername,
                    script=script,
                    parser=parser,
                    usePowershell=datasource.usePowershell,
                    contextrelname=contextrelname,
                    contextcompname=contextcompname,
                    contextmodname=contextmodname,
                    contexttitle=contexttitle,
                    version=version,
                    owner_node_ip=owner_node_ip)
    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)