def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'PLUGINS': ['reject'] } self.app = create_app(test_config) self.client = self.app.test_client() self.alert = { 'resource': 'node404', 'event': 'node_marginal', 'environment': 'Production', 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'service': ['Core', 'Web', 'Network'], 'group': 'Network', 'tags': ['level=20', 'switch:off'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.admin_api_key = ApiKey(user='******', scopes=['admin', 'read', 'write'], text='demo-key') self.customer_api_key = ApiKey(user='******', scopes=['admin', 'read', 'write'], text='demo-key', customer='Foo') self.admin_api_key.create() self.customer_api_key.create()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'PLUGINS': ['timeout'], 'ALERT_TIMEOUT': 24680, 'ACK_TIMEOUT': 98765, 'SHELVE_TIMEOUT': 12345 } self.app = create_app(test_config) self.client = self.app.test_client() self.alert = { 'event': 'node_marginal', 'resource': 'node404', 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.admin_api_key = ApiKey(user='******', scopes=['admin', 'read', 'write'], text='demo-key') self.customer_api_key = ApiKey(user='******', scopes=['admin', 'read', 'write'], text='demo-key', customer='Foo') self.admin_api_key.create() self.customer_api_key.create()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'ALLOWED_EMAIL_DOMAINS': ['bonaparte.fr', 'debeauharnais.fr'] } self.app = create_app(test_config) self.client = self.app.test_client() self.alert = { 'event': 'Foo', 'resource': 'Bar', 'environment': 'Production', 'service': ['Quux'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey(user='******', scopes=['admin', 'read', 'write'], text='demo-key') self.api_key.create() self.headers = { 'Authorization': 'Key %s' % self.api_key.key, 'Content-type': 'application/json' }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'ADMIN_USERS': ['*****@*****.**'], 'ALLOWED_EMAIL_DOMAINS': ['alerta.io', 'doe.com'] } self.app = create_app(test_config) self.client = self.app.test_client() self.alert = { 'event': 'Foo', 'resource': 'Bar', 'environment': 'Production', 'service': ['Quux'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='demo-key' ) self.api_key.create() self.headers = { 'Authorization': f'Key {self.api_key.key}', 'Content-type': 'application/json' }
def make_key(user, scopes=None, type=None, text=''): api_key = ApiKey( user=user, scopes=scopes, type=type, text=text ) return api_key.create().key
def create_key(admin, key=None): key = ApiKey(user=admin, key=key, scopes=scopes, expire_time=expires, text=text, customer=customer) try: key = key.create() except Exception as e: click.echo('ERROR: {}'.format(e)) else: return key
def create_key(admin, key): key = ApiKey(user=admin, key=key, scopes=['admin', 'write', 'read'], text='Admin key created by alertad script', expire_time=None) try: db.get_db() # init db on global app context key = key.create() except Exception as e: click.echo('ERROR: {}'.format(e)) else: click.echo('{} {}'.format(key.key, key.user))
def setUp(self): self.access_key = 'cc3b7f30-360e-47bc-8abb-c0a27625e134' self.secret_key = 'MjM0ODU4NGI1YWQxZWMyYzcxNjAxZDA4MzczNGQ1M2IK' test_config = { 'DEBUG': True, 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'DELETE_SCOPES': ['delete:alerts'], 'ALLOWED_EMAIL_DOMAINS': ['bonaparte.fr', 'debeauharnais.fr', 'manorfarm.ru'], 'HMAC_AUTH_CREDENTIALS': [{ 'key': self.access_key, 'secret': self.secret_key, 'algorithm': 'sha256' }] } self.app = create_app(test_config) self.client = self.app.test_client() self.alert = { 'event': 'Foo', 'resource': 'Bar', 'environment': 'Production', 'service': ['Quux'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='demo-key') self.api_key.create() self.headers = { 'Authorization': 'Key %s' % self.api_key.key, 'Content-type': 'application/json' }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'ALLOWED_EMAIL_DOMAINS': ['alerta.io', 'foo.com', 'bar.com'] } self.app = create_app(test_config) self.client = self.app.test_client() self.foo_alert = { 'event': 'foo1', 'resource': 'foo1', 'environment': 'Production', 'service': ['Web'] } self.bar_alert = { 'event': 'bar1', 'resource': 'bar1', 'environment': 'Production', 'service': ['Web'] } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=['admin', 'read', 'write'], text='admin-key' ) self.api_key.create() self.admin_headers = { 'Authorization': 'Key %s' % self.api_key.key, 'Content-type': 'application/json' }
def setUp(self): test_config = { 'TESTING': True, 'DEBUG': True, 'AUTH_REQUIRED': True, 'AUTH_PROVIDER': 'ldap', 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'LDAP_URL': 'ldap://myldap.server', 'LDAP_BIND_USERNAME': '******', 'LDAP_BIND_PASSWORD': '******', 'LDAP_DOMAINS_SEARCH_QUERY': { 'debeauharnais.fr': 'sAMAccountName={username}' }, 'LDAP_DOMAINS_USER_BASEDN': { 'debeauharnais.fr': '' }, 'LDAP_DOMAINS': { 'debeauharnais.fr': 'DN=%s' } } self.app = create_app(test_config) self.client = self.app.test_client() with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='demo-key') self.api_key.create() self.headers = { 'Authorization': 'Key %s' % self.api_key.key, 'Content-type': 'application/json' }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'PLUGINS': [] } self.app = create_app(test_config) self.client = self.app.test_client() self.prod_alert = { 'resource': 'node404', 'event': 'node_down', 'environment': 'Production', 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'service': ['Core', 'Web', 'Network'], 'group': 'Network', 'tags': ['level=20', 'switch:off'], 'origin': 'foo/bar' } self.dev_alert = { 'resource': 'node404', 'event': 'node_marginal', 'environment': 'Development', 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'service': ['Core', 'Web', 'Network'], 'group': 'Network', 'tags': ['level=20', 'switch:off'], 'origin': 'foo/bar' } self.fatal_alert = { 'event': 'node_down', 'resource': 'net01', 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False}, 'origin': 'foo/bar' } self.critical_alert = { 'event': 'node_marginal', 'resource': 'net02', 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/bar', 'timeout': 30 } self.major_alert = { 'event': 'node_marginal', 'resource': 'net03', 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/bar', 'timeout': 40 } self.normal_alert = { 'event': 'node_up', 'resource': 'net03', 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/quux', 'timeout': 100 } self.minor_alert = { 'event': 'node_marginal', 'resource': 'net04', 'environment': 'Production', 'service': ['Network'], 'severity': 'minor', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/quux', 'timeout': 40 } self.ok_alert = { 'event': 'node_up', 'resource': 'net04', 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/quux', 'timeout': 100 } self.warn_alert = { 'event': 'node_marginal', 'resource': 'net05', 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'origin': 'foo/quux', 'timeout': 50 } with self.app.test_request_context('/'): self.app.preprocess_request() self.admin_api_key = ApiKey( user='******', scopes=['admin', 'read', 'write'], text='demo-key' ) self.customer_api_key = ApiKey( user='******', scopes=['admin', 'read', 'write'], text='demo-key', customer='Foo' ) self.admin_api_key.create() self.customer_api_key.create()
def setUp(self): # create dummy routing rules self.dist = pkg_resources.Distribution(__file__, project_name='alerta-routing', version='0.1') s = 'rules = tests.test_zrouting:rules' self.entry_point = pkg_resources.EntryPoint.parse(s, dist=self.dist) self.dist._ep_map = {'alerta.routing': {'rules': self.entry_point}} pkg_resources.working_set.add(self.dist) test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'ALLOWED_EMAIL_DOMAINS': ['alerta.io', 'foo.com', 'bar.com'], 'PD_API_KEYS': { 'Tyrell Corporation': 'tc-key', 'Cyberdyne Systems': 'cs-key', 'Weyland-Yutani': 'wy-key', 'Zorin Enterprises': 'ze-key' }, 'SLACK_API_KEYS': { 'Soylent Corporation': 'sc-key', 'Omni Consumer Products': 'ocp-key', 'Dolmansaxlil Shoe Corporation': 'dsc-key' }, 'API_KEY': 'default-key', 'HOOK': 'not-set' } self.app = create_app(test_config) self.client = self.app.test_client() self.tier1_tc_alert = { 'event': 'foo1', 'resource': 'foo1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Tyrell Corporation' # tier 1 } self.tier1_wy_alert = { 'event': 'foo1', 'resource': 'foo1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Weyland-Yutani' # tier 1 } self.tier2_sc_alert = { 'event': 'bar1', 'resource': 'bar1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Soylent Corporation' # tier 2 } self.tier2_ocp_alert = { 'event': 'bar1', 'resource': 'bar1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Omni Consumer Products' # tier 2 } self.tier2_dsc_alert = { 'event': 'bar1', 'resource': 'bar1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Dolmansaxlil Shoe Corporation' # tier 2 } self.tier3_it_alert = { 'event': 'bar1', 'resource': 'bar1', 'environment': 'Production', 'service': ['Web'], 'customer': 'Initech' # tier 3 } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='admin-key') self.api_key.create() self.headers = { 'Authorization': f'Key {self.api_key.key}', 'Content-type': 'application/json' } # create dummy plugins plugins.plugins['pagerduty'] = DummyPagerDutyPlugin() plugins.plugins['slack'] = DummySlackPlugin() plugins.plugins['config'] = DummyConfigPlugin()
def setUp(self): test_config = { 'DEBUG': False, 'TESTING': True, 'AUTH_REQUIRED': True, 'BASE_URL': 'http://localhost:8080', 'PLUGINS': ['forwarder'] } HMAC_AUTH_CREDENTIALS = [ { # http://localhost:9001 'key': 'e3b8afc0-db18-4c51-865d-b95322742c5e', 'secret': 'MDhjZGMyYTRkY2YyNjk1MTEyMWFlNmM3Y2UxZDU1ZjIK', 'algorithm': 'sha256' }, ] FWD_DESTINATIONS = [ ('http://localhost:9000', { 'username': '******', 'password': '******', 'timeout': 10 }, ['alerts', 'actions']), # BasicAuth # ('https://httpbin.org/anything', dict(username='******', password='******', ssl_verify=False), ['*']), ('http://localhost:9001', { 'key': 'e3b8afc0-db18-4c51-865d-b95322742c5e', 'secret': 'MDhjZGMyYTRkY2YyNjk1MTEyMWFlNmM3Y2UxZDU1ZjIK' }, ['actions']), # Hawk HMAC ('http://localhost:9002', { 'key': 'demo-key' }, ['delete']), # API key ('http://localhost:9003', { 'token': 'bearer-token' }, ['*']), # Bearer token ] test_config['HMAC_AUTH_CREDENTIALS'] = HMAC_AUTH_CREDENTIALS test_config['FWD_DESTINATIONS'] = FWD_DESTINATIONS self.app = create_app(test_config) self.client = self.app.test_client() self.resource = str(uuid4()).upper()[:8] self.major_alert = { 'id': 'b528c6f7-0925-4f6d-b930-fa6c0bba51dc', 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.repeated_major_alert = { 'id': '4ba2b0d6-ff4a-4fc0-8d93-45939c819465', 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.warn_alert = { 'id': '67344228-bd03-4660-9c45-ff9c8f1d53d0', 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 50 } self.normal_alert = { 'id': 'cb12250d-42ed-42cc-97ef-592f3a49618c', 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 100 } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='demo-key') self.api_key.create()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'PLUGINS': [ 'remote_ip', 'reject', 'heartbeat', 'blackout', 'acked_by', 'forwarder' ] } os.environ['ALLOWED_ENVIRONMENTS'] = 'Production,Staging,Development' self.app = create_app(test_config) self.client = self.app.test_client() self.resource = str(uuid4()).upper()[:8] self.reject_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': [], # alert will be rejected because service not defined 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['one', 'two'] } self.accept_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], # alert will be accepted because service defined 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['three', 'four'] } self.critical_alert = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': [] } self.ok_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': [] } with self.app.test_request_context('/'): self.app.preprocess_request() self.api_key = ApiKey( user='******', scopes=[Scope.admin, Scope.read, Scope.write], text='demo-key') self.api_key.create() self.headers = { 'Authorization': f'Key {self.api_key.key}', 'Content-type': 'application/json', 'X-Forwarded-For': '172.217.20.36' }