diff --git a/streamalert/rule_promotion/publisher.py b/streamalert/rule_promotion/publisher.py index 648f8a8f4..c85271983 100644 --- a/streamalert/rule_promotion/publisher.py +++ b/streamalert/rule_promotion/publisher.py @@ -24,7 +24,7 @@ class StatsPublisher: """Run queries to generate statistics on alerts.""" - DEFAULT_STATS_SNS_TOPIC = 'staging_stats' + DEFAULT_STATS_SNS_TOPIC_SUFFIX = '{}_streamalert_rule_staging_stats' def __init__(self, config, athena_client, current_time): self._topic_arn = self.formatted_sns_topic_arn(config) @@ -41,9 +41,10 @@ def formatted_sns_topic_arn(cls, config): Return: str: Formatted SNS topic arn using either the config option or default topic """ + prefix = config['global']['account']['prefix'] topic = config['lambda']['rule_promotion_config'].get( 'digest_sns_topic', - cls.DEFAULT_STATS_SNS_TOPIC + cls.DEFAULT_STATS_SNS_TOPIC_SUFFIX.format(prefix) ) return 'arn:aws:sns:{region}:{account_id}:{topic}'.format( region=config['global']['account']['region'], diff --git a/tests/unit/streamalert/rule_promotion/test_publisher.py b/tests/unit/streamalert/rule_promotion/test_publisher.py index 3087f63cc..d0c402803 100644 --- a/tests/unit/streamalert/rule_promotion/test_publisher.py +++ b/tests/unit/streamalert/rule_promotion/test_publisher.py @@ -51,18 +51,39 @@ def _get_fake_stats(count=2): yield stat - def test_formatted_sns_topic_arn(self): - """StatsPublisher - Format SNS Topic""" + def test_formatted_sns_topic_arn_default(self): + """StatsPublisher - Format SNS Topic, Default""" test_config = { 'global': { 'account': { 'aws_account_id': '123456789012', + 'prefix': 'unit-testing', + 'region': 'us-east-1' + } + }, + 'lambda': { + 'rule_promotion_config': {} # no digest_sns_topic here + } + } + topic = self.publisher.formatted_sns_topic_arn(test_config) + assert_equal( + topic, + 'arn:aws:sns:us-east-1:123456789012:unit-testing_streamalert_rule_staging_stats' + ) + + def test_formatted_sns_topic_arn_hard_coded(self): + """StatsPublisher - Format SNS Topic, Hard-Coded""" + test_config = { + 'global': { + 'account': { + 'aws_account_id': '123456789012', + 'prefix': 'unit-testing', 'region': 'us-east-1' } }, 'lambda': { 'rule_promotion_config': { - 'digest_sns_topic': 'foobar' + 'digest_sns_topic': 'foobar' # should use digest_sns_topic here } } } diff --git a/tests/unit/streamalert_cli/terraform/test_rule_promotion.py b/tests/unit/streamalert_cli/terraform/test_rule_promotion.py index e247917c2..e43269d96 100644 --- a/tests/unit/streamalert_cli/terraform/test_rule_promotion.py +++ b/tests/unit/streamalert_cli/terraform/test_rule_promotion.py @@ -41,7 +41,7 @@ def test_generate(self): 'rules_table_arn': '${module.globals.rules_table_arn}', 'source': 'modules/tf_rule_promotion_iam', 'send_digest_schedule_expression': 'cron(30 13 * * ? *)', - 'digest_sns_topic': 'staging_stats', + 'digest_sns_topic': 'unit-testing_streamalert_rule_staging_stats', 'athena_results_bucket_arn': '${module.stream_alert_athena.results_bucket_arn}', 'athena_data_buckets': [ 'unit-testing.streamalert.data',