예제 #1
0
    def __init__(self):
        """Initialization logic that can be cached across invocations"""
        # Merge user-specified output configuration with the required output configuration
        output_config = load_config(include={'outputs.json'})['outputs']
        self.config = resources.merge_required_outputs(output_config, env['STREAMALERT_PREFIX'])

        self.alerts_table = AlertTable(env['ALERTS_TABLE'])
예제 #2
0
    def __init__(self, invoked_function_arn):
        """Initialization logic that can be cached across invocations.

        Args:
            invoked_function_arn (str): The ARN of the alert processor when it was invoked.
                This is used to calculate region, account, and prefix.
        """
        # arn:aws:lambda:REGION:ACCOUNT:function:PREFIX_streamalert_alert_processor:production
        split_arn = invoked_function_arn.split(':')
        self.region = split_arn[3]
        self.account_id = split_arn[4]
        self.prefix = split_arn[6].split('_')[0]

        # Merge user-specified output configuration with the required output configuration
        output_config = load_config(include={'outputs.json'})['outputs']
        self.config = resources.merge_required_outputs(output_config, self.prefix)

        self.alerts_table = AlertTable(os.environ['ALERTS_TABLE'])
예제 #3
0
    def __init__(self, config, context):
        """AlertProcessorTester initializer

        Args:
            context (namedtuple): Constructed aws context object. The
                namedtuple contains an attribute of `mocked` that indicates
                if all dispatch calls should be mocked out instead of actually
                performed. If not mocked, the tests will attempt to actually
                send alerts to outputs.
        """
        self.all_tests_passed = True
        self.context = context
        self.kms_alias = 'alias/stream_alert_secrets_test'
        self.secrets_bucket = 'test.streamalert.secrets'
        self.outputs_config = resources.merge_required_outputs(
            config['outputs'], 'test-prefix')
        self.region = config['global']['account']['region']
        self._cleanup_old_secrets()
        helpers.setup_mock_firehose_delivery_streams(config)
예제 #4
0
def test_merge_required_outputs_dne():
    """Shared - Merge Required Outputs, Does Not Exist"""
    # A simple user config that will be merged with required outputs
    users_config = {
        'aws-s3': {
            'bucket': 'my.s3.bucket'
        },
        'aws-sns': {
            'topic': 'my-sns-topic'
        },
        'slack': ['slack_output']
    }

    outputs = resources.merge_required_outputs(users_config, "test")

    assert_equal(len(outputs), 4)

    expected_fh = {'alerts': 'test_streamalert_alert_delivery'}

    assert_items_equal(outputs['aws-firehose'], expected_fh)
예제 #5
0
def test_merge_required_outputs_exists():
    """Shared - Merge Required Outputs, Has Existing"""
    # A simple user config with an exist aws-firehose output
    # that will be merged with required outputs
    users_config = {
        'aws-firehose': {
            'notalerts': 'resource_name'
        },
        'aws-sns': {
            'topic': 'my-sns-topic'
        },
        'slack': ['slack_output']
    }

    outputs = resources.merge_required_outputs(users_config, "test")

    assert_equal(len(outputs), 3)

    expected_fh = {
        'notalerts': 'resource_name',
        'alerts': 'test_streamalert_alert_delivery'
    }

    assert_items_equal(outputs['aws-firehose'], expected_fh)
예제 #6
0
You may obtain a copy of the License at
   http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import json

from stream_alert.shared import resources
from stream_alert.shared.config import load_config

REGION = 'us-east-1'
ACCOUNT_ID = '123456789012'
PREFIX = 'prefix'
FUNCTION_NAME = '{}_streamalert_alert_processor'.format(PREFIX)

base_config = load_config('tests/unit/conf/',
                          include={'outputs.json'})['outputs']
CONFIG = resources.merge_required_outputs(base_config, PREFIX)

ALERTS_TABLE = '{}_streamalert_alerts'.format(PREFIX)
KMS_ALIAS = 'alias/stream_alert_secrets_test'

MOCK_ENV = {
    'AWS_ACCOUNT_ID': ACCOUNT_ID,
    'STREAMALERT_PREFIX': PREFIX,
    'AWS_DEFAULT_REGION': REGION
}