示例#1
0
    def __init__(self, label, y_axis, palette_index, plot_type, display_name):
        """Initializes and validates publish label options.

        Arguments:
            label: label used in the publish statement that displayes the plot
            y_axis: the y-axis associated with values for this plot.
                    Must be 0 (left) or 1 (right).
            palette_index: the indexed palette color to use for all plot lines
            plot_type: the visualization style to use
            display_name: an alternate name to show in the legend
        """
        for arg in [label, display_name]:
            util.is_valid(arg)
        util.in_given_enum(palette_index, PaletteColor)
        util.in_given_enum(plot_type, PlotType)
        if y_axis not in [0, 1]:
            msg = "YAxis for chart must be 0 (Left) or 1 (Right); " +\
                    "'{0}' provided."
            raise ValueError(msg.format(y_axis))

        self.opts = {
            'label': label,
            'yAxis': y_axis,
            'paletteIndex': palette_index.value,
            'plotType': plot_type.value,
            'displayName': display_name
        }
示例#2
0
    def with_program_options(self,
                             min_resolution,
                             max_delay,
                             disable_sampling=False):
        """How should the program underlying the visualization be run.

        Arguments:
            min_resolution: min resolution to use for computing program
            max_delay: How long to wait for late datapoints, in ms.
            disable_sampling: samples a subset of output MTS unless enabled.
                              Improves chart performance for heavier MTS.

        Consult this page for more information on min resolution:
            https://docs.signalfx.com/en/latest/reference/analytics-docs/how-choose-data-resolution.html

        Consult this page for more information on late datapoints:
            https://docs.signalfx.com/en/latest/charts/chart-options-tab.html#max-delay

        Returns:
            This TimeSeriesChart with program options.
        """

        util.is_valid(min_resolution)
        util.is_valid(max_delay)
        program_opts = {
            'minimumResolution': min_resolution,
            'maxDelay': max_delay,
            'disableSampling': disable_sampling
        }
        self.chart_options.update({'programOptions': program_opts})
        return self
示例#3
0
    def with_id(self, ident):
        """The id for this resource.

        Useful for creates/deletes.
        """
        util.is_valid(ident)
        self.options.update({'id': ident})
        return self
示例#4
0
    def with_id(self, id):
        """The unique identifier for this chart.

        Useful when updating/deleting charts.
        """
        util.is_valid(id)
        self.options.update({'id': id})
        return self
示例#5
0
    def with_parameterized_subject(self, subject):
        """Custom notification message subject for this rule when an alert is
        triggered.

        See the documentation for `with_parameterized_body` for more detail.
        """
        util.is_valid(subject)
        self.options.update({'parameterizedSubject': subject})
        return self
示例#6
0
    def with_runbook_url(self, url):
        """URL of the page to consult when an alert is triggered.

        This can be used with custom notification messages. It can be
        referenced using the {{runbookUrl}} template var.
        """
        util.is_valid(url)
        self.options.update({'runbookUrl': url})
        return self
示例#7
0
    def __set_api_token__(self, token):
        """Internal helper for setting valid API tokens."""

        message = """Cannot proceed with an empty API token.
        Either pass one in at Resource instantiation time or provide one
        via the `with_api_token` method."""

        util.is_valid(token, message)
        self.api_token = token
示例#8
0
    def with_tip(self, tip):
        """Plain text suggested first course of action, such as a command line
        to execute.

        This can be used with custom notification messages. It can be
        referenced using the {{tip}} template var.
        """
        util.is_valid(tip)
        self.options.update({'tip': tip})
        return self
示例#9
0
    def with_axes(self, axes):
        """Options for labeling axes on TimeSeries charts.

        Don't leave your axes laying about or this guy might show up:
        https://youtu.be/V2FygG84bg8
        """
        util.is_valid(axes)
        self.chart_options.update(
            {'axes': list(map(lambda x: x.to_dict(), axes))})
        return self
示例#10
0
    def with_program(self, program):
        """The SignalFlow program to execute for this chart.

        For more information SignalFlow consult the `signal_analog.flow`
        module or the upstream SignalFlow documentation here:

        https://developers.signalfx.com/docs/signalflow-overview
        """
        util.is_valid(program)
        self.options.update({'programText': program})
        return self
示例#11
0
    def __init__(self, team_id):
        """Initializes a new team e-mail notification.

        No validation is done to verify that a team id exists in SignalFx.

        Arguments:
            team_id: the id of the team to e-mail.
        """
        util.is_valid(team_id)

        self.options = {'type': 'TeamEmail', 'team': team_id}
示例#12
0
    def with_colorscale(self, thresholds):
        """Values for each color in the range.

        Arguments:
            thresholds: The thresholds to set for the color range being used.
        """
        util.is_valid(thresholds)
        thresholds.sort(reverse=True)
        opts = {'thresholds': thresholds}
        self.chart_options.update({'colorScale': opts})
        return self
示例#13
0
    def __init__(self, sn_id):
        """Initializes a new ServiceNow notification.

        This does not setup a ServiceNow integration for you, one must already
        exist before using this notification type. No validation is done to
        ensure that a ServiceNow integration id is valid.

        Arguments:
            sn_id: the ServiceNow integration id to use
        """
        util.is_valid(sn_id)

        self.options = {'type': 'ServiceNow', 'credentialId': sn_id}
示例#14
0
    def with_time_config_relative(self, range):
        """Options to set the relative view window into the given chart.

        Arguments:
            range: Absolute millisecond offset from now to visualize.

        Returns:
            This TimeSeriesChart with absolute time config
        """
        util.is_valid(range)
        opts = {'type': 'relative', 'range': range}
        self.chart_options.update({'time': opts})
        return self
示例#15
0
    def with_colorscale(self, thresholds, inverted=False):
        """Values for each color in the range.

        Arguments:
            thresholds: The thresholds to set for the color range being used.
            inverted: If false, values are red if they are above
                      the highest specified value. If true, values are red if
                      they are below the lowest specified value.
        """
        util.is_valid(thresholds)
        thresholds.sort(reverse=True)
        opts = {'thresholds': thresholds, 'inverted': inverted}
        self.chart_options.update({'colorScale': opts})
        return self
示例#16
0
    def with_parameterized_body(self, body):
        """Custom notifiction message body for this rule when the alert is
           triggeered.

           Content can contain ASCII chars and is parsed as plain text. Quotes
           can be escaped using a backslash, and new line characters are
           indicated with "\\n"

           Available variables can be found here:
           https://docs.signalfx.com/en/latest/detect-alert/set-up-detectors.html#message-variables
        """
        util.is_valid(body)
        self.options.update({'parameterizedBody': body})
        return self
示例#17
0
    def with_time_config_absolute(self, start, end):
        """Options to set the absolute view window into the given chart.

        Arguments:
            start: Milliseconds since epoch to start the visualization.
            end: Milliseconds since epoch to end the visualization.

        Returns:
            This TimeSeriesChart with a relative time config.
        """
        util.is_valid(start)
        util.is_valid(end)
        opts = {'type': 'absolute', 'start': start, 'end': end}
        self.chart_options.update({'time': opts})
        return self
示例#18
0
    def __init__(self, url, secret=None):
        """Initializes a new webhook notification.

        Arguments:
            url: the URL to call back
            secret: optional, when provided the request will contain a
                    `X-SFX-Signature` header containing the Base64 encoded
                    HMAC-SHA1 digest of the request body using the shared
                    secret.
        """
        util.is_valid(url)

        self.options = {'type': 'Webhook', 'url': url}

        if secret:
            self.options.update({'secret': secret})
示例#19
0
    def __init__(self, pd_id):
        """Initializes a new PagerDuty notification.

        This does not setup a PagerDuty integration for you, one must already
        exist before using this notification type. No validation is done to
        ensure that a PD integration id is valid.

        These values will typically differ depending on the on-call rotation
        you want to add to the detector.

        See the integration page for more detail:
        https://developers.signalfx.com/v2/reference#pagerduty-integration-model

        Arguments:
            pd_id: the id of the PagerDuty integration to include.
        """
        util.is_valid(pd_id)
        self.options = {'type': 'PagerDuty', 'credentialId': pd_id}
示例#20
0
    def __init__(self, vo_id, routing_key):
        """Initializes a new VictorOps notification.

        This does not setup a VictorOps integration for you, one must already
        exist before using this notification type. No validation is done to
        ensure that a VictorOps integration id is valid.

        Arguments:
            vo_id: the VictorOps integration id to use
            routing_key: a VictorOps routing key
        """
        util.is_valid(vo_id)
        util.is_valid(routing_key)

        self.options = {
            'type': 'VictorOps',
            'credentialId': vo_id,
            'routingKey': routing_key
        }
示例#21
0
    def __init__(self, slack_id, channel_name):
        """Initializes a new Slack notification rule.

        This does not setup a Slack integration for you, one must already exist
        before using this notification type. No validation is done to ensure
        that a Slack integration id is valid.

        See the integration page for more detail:
        https://developers.signalfx.com/v2/reference#slack-integration-model

        Arguments:
            slack_id: the slack integration id to use
            channel_name: the name of the channel to send alerts to
        """
        util.is_valid(slack_id)
        util.is_valid(channel_name)

        self.options = {
            'type': 'Slack',
            'credentialId': slack_id,
            'channel': channel_name
        }
示例#22
0
    def __init__(self, hp_id, room_name):
        """Initializes a new HipChat notification.

        This does not setup a Slack integration for you, one must already exist
        before using this notification type. No validation is done to ensure
        that a HipChat integration id is valid.

        See the integration page for more detail:
        https://developers.signalfx.com/v2/reference#hipchat-integration-model

        Arguments:
            hp_id: the HipChat integration id to use
            room_name: the HipChat room name to post integrations to
        """

        util.is_valid(hp_id)
        util.is_valid(room_name)

        self.options = {
            'type': 'HipChat',
            'credentialId': hp_id,
            'room': room_name
        }
示例#23
0
 def with_unit_prefix(self, prefix):
     """Add a unit prefix to this chart."""
     util.is_valid(prefix)
     util.in_given_enum(prefix, UnitPrefix)
     self.chart_options.update({'unitPrefix': prefix.value})
     return self
示例#24
0
 def with_refresh_interval(self, interval):
     """How often (in milliseconds) to refresh the values of the list."""
     util.is_valid(interval)
     self.chart_options.update({'refreshInterval': interval})
     return self
示例#25
0
 def with_maximum_precision(self, precision):
     """The maximum precision to for values displayed in the list."""
     util.is_valid(precision)
     self.chart_options.update({'maximumPrecision': precision})
     return self
示例#26
0
 def with_publish_label_options(self, *publish_opts):
     """Plot-level customization, associated with a publish statement."""
     util.is_valid(publish_opts)
     opt = list(map(lambda o: o.to_dict(), publish_opts))
     self.chart_options.update({'publishLabelOptions': opt})
     return self
示例#27
0
 def with_chart_legend_options(self, dimension, show_legend=False):
     """Show the on-chart legend using the given dimension."""
     util.is_valid(dimension)
     opts = {'showLegend': show_legend, 'dimensionInLegend': dimension}
     self.chart_options.update({'onChartLegendOptions': opts})
     return self
示例#28
0
 def with_axis_precision(self, num):
     """Force a specific number of significant digits in the y-axis."""
     util.is_valid(num)
     self.chart_options.update({'axisPrecision': num})
     return self
示例#29
0
 def with_default_plot_type(self, plot_type):
     """The default plot display style for the visualization."""
     util.is_valid(plot_type)
     util.in_given_enum(plot_type, PlotType)
     self.chart_options.update({'defaultPlotType': plot_type.value})
     return self
示例#30
0
 def with_legend_options(self, field_opts):
     """Options for the behavior of this chart's legend."""
     util.is_valid(field_opts)
     opts = {'fields': list(map(lambda x: x.to_dict(), field_opts))}
     self.chart_options.update({'legendOptions': opts})
     return self