class ZabbixTrendValueFunction(object): """ZabbixTrendValueFunction Specifying type of trend value returned by Zabbix when trends are used (avg, min or max). https://alexanderzobnin.github.io/grafana-zabbix/reference/functions/#trendValue """ _options = ('avg', 'min', 'max') _default_type = 'avg' added = attr.ib(default=False, validator=instance_of(bool)) type = attr.ib(default=_default_type, validator=is_in(_options)) def to_json_data(self): text = "trendValue({type})" definition = { 'category': 'Trends', 'name': 'trendValue', 'defaultParams': [ self._default_type, ], 'params': [{ 'name': 'type', 'options': self._options, 'type': 'string' }] } return { 'def': definition, 'text': text.format(type=self.type), 'params': [self.type], 'added': self.added, }
class ZabbixTopFunction(object): _options = ("avg", "min", "max", "median") _default_number = 5 _default_function = "avg" added = attr.ib(default=False, validator=instance_of(bool)) number = attr.ib(default=_default_number, validator=instance_of(int)) function = attr.ib(default=_default_function, validator=is_in(_options)) def to_json_data(self): text = "top({number}, {function})" definition = { "category": "Filter", "name": "top", "defaultParams": [ self._default_number, self._default_function, ], "params": [ {"name": "number", "type": "string"}, {"name": "function", "options": self._options, "type": "string"}]} return { "def": definition, "text": text.format( number=self.number, function=self.function), "params": [self.number, self.function], "added": self.added, }
class ZabbixTrendValueFunction(object): """ZabbixTrendValueFunction Specifying type of trend value returned by Zabbix when trends are used (avg, min or max). http://docs.grafana-zabbix.org/reference/functions/#trendValue """ _options = ('avg', 'min', 'max') _default_type = "avg" added = attr.ib(default=False, validator=instance_of(bool)) type = attr.ib(default=_default_type, validator=is_in(_options)) def to_json_data(self): text = "trendValue({type})" definition = { "category": "Trends", "name": "trendValue", "defaultParams": [ self._default_type, ], "params": [ {"name": "type", "options": self._options, "type": "string"}]} return { "def": definition, "text": text.format( type=self.type), "params": [self.type], "added": self.added, }
class OpenTSDBFilter(object): value = attr.ib() tag = attr.ib() type = attr.ib(default=OTSDB_QUERY_FILTER_DEFAULT, validator=is_in(OTSDB_QUERY_FILTERS)) groupBy = attr.ib(default=False, validator=instance_of(bool)) def to_json_data(self): return { 'filter': self.value, 'tagk': self.tag, 'type': self.type, 'groupBy': self.groupBy }
class ZabbixAggregateByFunction(object): """ZabbixAggregateByFunction Takes all timeseries and consolidate all its points falled in given interval into one point using function, which can be one of: avg, min, max, median. https://alexanderzobnin.github.io/grafana-zabbix/reference/functions/#aggregateBy """ _options = ('avg', 'min', 'max', 'median') _default_interval = '1m' _default_function = 'avg' added = attr.ib(default=False, validator=instance_of(bool)) interval = attr.ib(default=_default_interval, validator=is_interval) function = attr.ib(default=_default_function, validator=is_in(_options)) def to_json_data(self): text = "aggregateBy({interval}, {function})" definition = { 'category': 'Aggregate', 'name': 'aggregateBy', 'defaultParams': [ self._default_interval, self._default_function, ], 'params': [{ 'name': 'interval', 'type': 'string' }, { 'name': 'function', 'options': self._options, 'type': 'string' }] } return { 'def': definition, 'text': text.format(interval=self.interval, function=self.function), 'params': [self.interval, self.function], 'added': self.added, }
class ZabbixAggregateByFunction(object): """ZabbixAggregateByFunction Takes all timeseries and consolidate all its points falled in given interval into one point using function, which can be one of: avg, min, max, median. http://docs.grafana-zabbix.org/reference/functions/#aggregateBy """ _options = ("avg", "min", "max", "median") _default_interval = "1m" _default_function = "avg" added = attr.ib(default=False, validator=instance_of(bool)) interval = attr.ib(default=_default_interval, validator=is_interval) function = attr.ib(default=_default_function, validator=is_in(_options)) def to_json_data(self): text = "aggregateBy({interval}, {function})" definition = { "category": "Aggregate", "name": "aggregateBy", "defaultParams": [ self._default_interval, self._default_function, ], "params": [{ "name": "interval", "type": "string" }, { "name": "function", "options": self._options, "type": "string" }] } return { "def": definition, "text": text.format(interval=self.interval, function=self.function), "params": [self.interval, self.function], "added": self.added, }
class ZabbixTopFunction(object): _options = ('avg', 'min', 'max', 'median') _default_number = 5 _default_function = 'avg' added = attr.ib(default=False, validator=instance_of(bool)) number = attr.ib(default=_default_number, validator=instance_of(int)) function = attr.ib(default=_default_function, validator=is_in(_options)) def to_json_data(self): text = "top({number}, {function})" definition = { 'category': 'Filter', 'name': 'top', 'defaultParams': [ self._default_number, self._default_function, ], 'params': [{ 'name': 'number', 'type': 'string' }, { 'name': 'function', 'options': self._options, 'type': 'string' }] } return { 'def': definition, 'text': text.format(number=self.number, function=self.function), 'params': [self.number, self.function], 'added': self.added, }
def test_is_in_raises(): item = 0 choices = (1, 2, 3) val = validators.is_in(choices) with pytest.raises(ValueError): val(None, create_attribute(), item)
def test_is_in(): item = 1 choices = (1, 2, 3) val = validators.is_in(choices) res = val(None, create_attribute(), item) assert res is None
class OpenTSDBTarget(object): """Generates OpenTSDB target JSON structure. Grafana docs on using OpenTSDB: http://docs.grafana.org/features/datasources/opentsdb/ OpenTSDB docs on querying or reading data: http://opentsdb.net/docs/build/html/user_guide/query/index.html :param metric: OpenTSDB metric name :param refId: target reference id :param aggregator: defines metric aggregator. The list of opentsdb aggregators: http://opentsdb.net/docs/build/html/user_guide/query/aggregators.html#available-aggregators :param alias: legend alias. Use patterns like $tag_tagname to replace part of the alias for a tag value. :param isCounter: defines if rate function results should be interpret as counter :param counterMax: defines rate counter max value :param counterResetValue: defines rate counter reset value :param disableDownsampling: defines if downsampling should be disabled. OpenTSDB docs on downsampling: http://opentsdb.net/docs/build/html/user_guide/query/index.html#downsampling :param downsampleAggregator: defines downsampling aggregator :param downsampleFillPolicy: defines downsampling fill policy :param downsampleInterval: defines downsampling interval :param filters: defines the list of metric query filters. OpenTSDB docs on filters: http://opentsdb.net/docs/build/html/user_guide/query/index.html#filters :param shouldComputeRate: defines if rate function should be used. OpenTSDB docs on rate function: http://opentsdb.net/docs/build/html/user_guide/query/index.html#rate :param currentFilterGroupBy: defines if grouping should be enabled for current filter :param currentFilterKey: defines current filter key :param currentFilterType: defines current filter type :param currentFilterValue: defines current filter value """ metric = attr.ib() refId = attr.ib(default="") aggregator = attr.ib(default="sum") alias = attr.ib(default=None) isCounter = attr.ib(default=False, validator=instance_of(bool)) counterMax = attr.ib(default=None) counterResetValue = attr.ib(default=None) disableDownsampling = attr.ib(default=False, validator=instance_of(bool)) downsampleAggregator = attr.ib(default=OTSDB_AGG_SUM) downsampleFillPolicy = attr.ib( default=OTSDB_DOWNSAMPLING_FILL_POLICY_DEFAULT, validator=is_in(OTSDB_DOWNSAMPLING_FILL_POLICIES)) downsampleInterval = attr.ib(default=None) filters = attr.ib(default=attr.Factory(list)) shouldComputeRate = attr.ib(default=False, validator=instance_of(bool)) currentFilterGroupBy = attr.ib(default=False, validator=instance_of(bool)) currentFilterKey = attr.ib(default="") currentFilterType = attr.ib(default=OTSDB_QUERY_FILTER_DEFAULT) currentFilterValue = attr.ib(default="") def to_json_data(self): return { 'aggregator': self.aggregator, 'alias': self.alias, 'isCounter': self.isCounter, 'counterMax': self.counterMax, 'counterResetValue': self.counterResetValue, 'disableDownsampling': self.disableDownsampling, 'downsampleAggregator': self.downsampleAggregator, 'downsampleFillPolicy': self.downsampleFillPolicy, 'downsampleInterval': self.downsampleInterval, 'filters': self.filters, 'metric': self.metric, 'refId': self.refId, 'shouldComputeRate': self.shouldComputeRate, 'currentFilterGroupBy': self.currentFilterGroupBy, 'currentFilterKey': self.currentFilterKey, 'currentFilterType': self.currentFilterType, 'currentFilterValue': self.currentFilterValue, }