Skip to content

Commit

Permalink
Merge pull request #122 from bebyx/feature/amazon-event-bridge
Browse files Browse the repository at this point in the history
Feature/Amazon EventBridge + 2 convenience combinators
  • Loading branch information
venky526 authored Jul 20, 2023
2 parents f70a1af + 3efe4c1 commit e454870
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.10.0 (2023-7-19)

* Added `AmazonEventBridgeNotification` for Amazon EventBridge integration within detectors.
* Added combinators `EQ` (Equal) and `NE` (Not Equal).

## 2.9.3 (2020-3-18)

* Added `Alerts` in `signal_analog.flow` module to allow linking Detectors to Charts.
Expand Down
3 changes: 1 addition & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ click
coverage
email_validator
enum34
# https://github.com/PyCQA/pycodestyle/issues/728
-e git+https://gitlab.com/pycqa/flake8@9631dac5#egg=flake8
flake8
hypothesis
mock
pytest
Expand Down
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
current_version = 2.9.3
current_version = 2.10.0
commit = True
tag = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}.{release}{build}
Expand Down Expand Up @@ -34,4 +34,3 @@ test = pytest

[tool:pytest]
addopts = -n auto

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

setup(
name='signal_analog',
version='2.9.3',
version='2.10.0',
description='A troposphere-like library for managing SignalFx'
+ 'Charts, Dashboards, and Detectors.',
long_description=readme + '\n\n' + history,
Expand Down
2 changes: 1 addition & 1 deletion signal_analog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__author__ = """Fernando Freire"""
__email__ = '[email protected]'
__version__ = '2.9.3'
__version__ = '2.10.0'

logging_config = pkg_resources.resource_string(
__name__, 'logging.yaml').decode('utf-8')
Expand Down
16 changes: 16 additions & 0 deletions signal_analog/combinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ def __init__(self, left, right):
super(GTE, self).__init__('>=', left, right)


class EQ(NAryCombinator):
"""Equal combinator for comparing SignalFlow objects.
"""

def __init__(self, left, right):
super(EQ, self).__init__('==', left, right)


class NE(NAryCombinator):
"""Not Equal combinator for comparing SignalFlow objects.
"""

def __init__(self, left, right):
super(NE, self).__init__('!=', left, right)


class Mul(NAryCombinator):
"""Multiplication combinator for performing math on SignalFlow objects.
"""
Expand Down
21 changes: 21 additions & 0 deletions signal_analog/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ def __init__(self, vo_id, routing_key):
}


class AmazonEventBridgeNotification(Notification):
"""An Amazon EventBridge notification for detector rules."""

def __init__(self, aeb_id):
"""Initializes a new Amazon EventBridge notification.
This does not set up a Amazon EventBridge integration for you, one must already
exist before using this notification type. No validation is done to
ensure that a Amazon EventBridge integration id is valid.
Arguments:
aeb_id: the Amazon EventBridge integration id to use
"""
util.assert_valid(aeb_id)

self.options = {
'type': 'AmazonEventBridge',
'credentialId': aeb_id
}


class WebhookNotification(Notification):
"""A Webhook notification for detector rules."""

Expand Down
5 changes: 3 additions & 2 deletions tests/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ def ascii():
return text(
characters(min_codepoint=1, max_codepoint=128,
blacklist_categories=['Cc', 'Cs']),
min_size=1)
min_size=1, max_size=5)


def flows():
return recursive(
filters() | datas() | consts() | graphites() | newrelics(),
lambda children: whens() | detects())
lambda children: whens() | detects(),
max_leaves=5)


@composite
Expand Down
12 changes: 12 additions & 0 deletions tests/test_signal_analog_combinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_binary_combinator_gte(f, ff):
assert str(comb.GTE(f, ff)) == "{0} >= {1}".format(str(f), str(ff))


@given(flows(), flows())
def test_binary_combinator_eq(f, ff):
"""EQ combinator should always intersperse '==' in the elements."""
assert str(comb.EQ(f, ff)) == "{0} == {1}".format(str(f), str(ff))


@given(flows(), flows())
def test_binary_combinator_ne(f, ff):
"""NE combinator should always intersperse '!=' in the elements."""
assert str(comb.NE(f, ff)) == "{0} != {1}".format(str(f), str(ff))


@given(flows())
def test_combinator_not(expr):
"""Not combinator should always prefix 'not' to its expression."""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_signal_analog_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
SlackNotification, HipChatNotification, \
ServiceNowNotification, \
VictorOpsNotification, \
AmazonEventBridgeNotification, \
WebhookNotification, TeamNotification, \
TeamEmailNotification, Rule, Severity, \
Time, TimeConfig, VisualizationOptions, \
Expand Down Expand Up @@ -114,6 +115,14 @@ def test_victorops_valid():
assert n.options['routingKey'] == routing


def test_amazoneventbridge_valid():
aeb_id = 'foo'
n = AmazonEventBridgeNotification(aeb_id)

assert n.options['type'] == 'AmazonEventBridge'
assert n.options['credentialId'] == aeb_id


def test_webhook_valid():
url = 'foo.com'
secret = 'foo'
Expand Down

0 comments on commit e454870

Please sign in to comment.