def setUp(self): test_config = { 'TESTING': True, 'DEBUG': True, 'AUTH_REQUIRED': False, 'ADMIN_USERS': ['*****@*****.**'], 'AUTH_PROVIDER': 'ldap', 'ALLOWED_EMAIL_DOMAINS': ['planetexpress.com'], 'LDAP_URL': 'ldap://localhost:389', 'LDAP_BASEDN': 'dc=planetexpress,dc=com', 'LDAP_DOMAINS': { # 'planetexpress.com': 'cn=%s,ou=people,dc=planetexpress,dc=com', }, 'LDAP_BIND_USERNAME': '******', 'LDAP_BIND_PASSWORD': '******', 'LDAP_USER_BASEDN': 'ou=people,dc=planetexpress,dc=com', 'LDAP_USER_FILTER': '(&(uid={username})(objectClass=inetOrgPerson))', 'LDAP_USER_NAME_ATTR': 'cn', 'LDAP_USER_EMAIL_ATTR': 'mail', 'LDAP_GROUP_BASEDN': 'ou=people,dc=planetexpress,dc=com', 'LDAP_GROUP_FILTER': '(&(member={userdn})(objectClass=group))', 'LDAP_GROUP_NAME_ATTR': 'cn', # memberOf or cn 'LDAP_DEFAULT_DOMAIN': 'planetexpress.com' } self.app = create_app(test_config) self.client = self.app.test_client()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'ADMIN_USERS': ['*****@*****.**', '*****@*****.**'], 'DEFAULT_ADMIN_ROLE': 'ops', 'ADMIN_ROLES': ['ops', 'devops'], 'DEFAULT_USER_ROLE': 'dev', 'USER_ROLES': ['dev'], 'CUSTOM_SCOPES': ['admin:foo', 'write:foo.bar', 'read:foo.baz', 'delete:foo.quux'] } self.app = create_app(test_config, environment='development') self.client = self.app.test_client() 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 with self.app.test_request_context('/'): self.app.preprocess_request() self.api_keys_scopes = dict() self.api_keys_scopes['read-only'] = make_key('*****@*****.**', scopes=['read'], type=None, text='read-only') self.api_keys_scopes['read-write'] = make_key('*****@*****.**', scopes=['read', 'write'], type=None, text='read-write') self.api_keys_scopes['admin'] = make_key( '*****@*****.**', scopes=['read', 'write', 'admin'], type=None, text='admin')
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'ADMIN_USERS': ['*****@*****.**'], 'ALLOWED_EMAIL_DOMAINS': ['bonaparte.fr', 'debeauharnais.fr', 'manorfarm.ru'] } 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 test_slack_plugin(self): test_config = {'TESTING': True, 'AUTH_REQUIRED': False} with mod_env( SLACK_WEBHOOK_URL= 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' ): self.app = create_app(test_config) self.client = self.app.test_client() plugins.plugins['slack'] = ServiceIntegration() self.alert = { 'event': 'node_down', 'resource': 'net5', 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': [] } response = self.client.post( '/alert', data=json.dumps(self.alert), headers={'Content-type': 'application/json'}) self.assertEqual(response.status_code, 201) data = json.loads(response.data.decode('utf-8')) self.assertEqual(data['status'], 'ok') self.assertRegex( data['id'], '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
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': False } self.app = create_app(test_config) self.client = self.app.test_client() self.headers = { 'Content-type': 'application/json' } self.resource = str(uuid4()).upper()[:8] self.major_alert = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'ADMIN_USERS': ['*****@*****.**', '*****@*****.**'] } self.app = create_app(test_config) self.client = self.app.test_client() 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 with self.app.test_request_context('/'): self.app.preprocess_request() self.api_keys_scopes = dict() self.api_keys_scopes['read-only'] = make_key('*****@*****.**', scopes=['read'], type=None, text='read-only') self.api_keys_scopes['read-write'] = make_key( '*****@*****.**', scopes=['read', 'write'], type=None, text='read-write') self.api_keys_scopes['admin'] = make_key( '*****@*****.**', scopes=['read', 'write', 'admin'], type=None, text='admin')
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'ADMIN_USERS': ['*****@*****.**', '*****@*****.**'] } self.app = create_app(test_config) self.client = self.app.test_client() 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 with self.app.test_request_context('/'): self.app.preprocess_request() self.api_keys_scopes = dict() self.api_keys_scopes['read-only'] = make_key('*****@*****.**', scopes=['read'], type=None, text='read-only') self.api_keys_scopes['read-write'] = make_key('*****@*****.**', scopes=['read', 'write'], type=None, text='read-write') self.api_keys_scopes['admin'] = make_key('*****@*****.**', scopes=['read', 'write', 'admin'], type=None, text='admin')
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': False} self.app = create_app(test_config) self.client = self.app.test_client() self.resource = str(uuid4()).upper()[:8] self.node_down_alert = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': { 'ip': '10.0.3.4' } } self.node_up_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': { 'ip': '10.0.3.4' } } self.headers = {'Content-type': 'application/json'}
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, 'CUSTOMER_VIEWS': True } 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, '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 setUp(self): test_config = {'TESTING': True, 'AUTH_REQUIRED': False} self.app = create_app(test_config) self.client = self.app.test_client() self.resource = str(uuid4()).upper()[:8] self.fatal_alert = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': { 'foo': 'abc def', 'bar': 1234, 'baz': False } } self.critical_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.major_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.warn_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.normal_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.headers = { 'Content-type': 'application/json', 'X-Forwarded-For': '10.0.0.1' }
def setUp(self): test_config = {'TESTING': True, 'AUTH_REQUIRED': False} self.app = create_app(test_config) self.client = self.app.test_client() custom_webhooks.webhooks[ 'azuremonitor'] = alerta_azuremonitor.AzureMonitorWebhook()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'SLACK_WEBHOOK_URL': 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX' } self.app = create_app(test_config) self.client = self.app.test_client()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'PLUGINS': ['remote_ip'] } 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': 'Staging', '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': 'Staging', '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': 'Staging', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': [] } self.coffee_alert = { 'event': 'coffee_pot', 'resource': self.resource, 'environment': 'Staging', 'service': ['Network'], 'severity': 'critical', 'text': 'coffee alert', 'tags': [] } self.headers = {'Content-type': 'application/json'}
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'PLUGINS': [], 'PLUGINS_RAISE_ON_ERROR': True } self.app = create_app(test_config) self.client = self.app.test_client() self.reject_alert = { 'id': '224040c5-5fdb-4d94-b564-398c755fdd02', 'event': 'node_marginal', 'resource': 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 = { 'id': '82d8379c-5ea2-45fa-92e0-51c69c3048b9', 'event': 'node_marginal', 'resource': 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 = { 'id': '5e2f6e2f-01f9-4a56-b9c1-a4d8a412b055', 'event': 'node_down', 'resource': resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'value': 'UP=0', 'text': 'node is down.', 'tags': ['cisco', 'core'], 'attributes': { 'region': 'EU', 'site': 'london' }, 'origin': 'test_hooks.py', 'rawData': 'raw text' } self.headers = {'Content-type': 'application/json'}
def setUp(self): test_config = {'DEBUG': True, 'TESTING': True, 'AUTH_REQUIRED': False} self.app = create_app(test_config) self.client = self.app.test_client() self.headers = {'Content-type': 'application/json'} def random_resource(): return str(uuid4()).upper()[:8] self.expired_alert = { 'event': 'node_down', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': { 'foo': 'abc def', 'bar': 1234, 'baz': False }, 'timeout': 2 } self.shelved_alert = { 'event': 'node_marginal', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 20 } self.acked_alert = { 'event': 'node_down', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network', 'Shared'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'] } self.ok_alert = { 'event': 'node_up', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'] }
def setUp(self): test_config = { 'DEBUG': False, 'TESTING': True, 'AUTH_REQUIRED': False, 'BASE_URL': 'http://localhost:8080', 'PLUGINS': ['forwarder'] } 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['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 = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.warn_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 50 } self.normal_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 100 }
def setUp(self): test_config = {'TESTING': True, 'AUTH_REQUIRED': False} self.app = create_app(test_config) self.client = self.app.test_client() custom_webhooks.webhooks[ 'msteams'] = alerta_msteamswebhook.MsteamsWebhook() self.headers = {'Content-Type': 'application/json'} self.alert_id = 'f0c55228-c61d-462a-9aeb-f6048d37fdf6'
def setUp(self): test_config = {'TESTING': True, 'AUTH_REQUIRED': False} self.app = create_app(test_config) self.client = self.app.test_client() self.origin = str(uuid4()).upper()[:8] self.heartbeat = {'origin': self.origin, 'tags': ['foo', 'bar', 'baz']} self.headers = {'Content-type': 'application/json'}
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'LOG_HANDLERS': ['console'], 'LOG_FORMAT': 'verbose', 'AUDIT_TRAIL': ['admin', 'write', 'auth'], 'AUDIT_LOG': True } self.app = create_app(test_config) self.client = self.app.test_client()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'CORS_ORIGINS': ['http://localhost:5000', 'http://try.alerta.io'], 'CORS_ALLOWED_HEADERS': ['Content-Type', 'Authorization', 'X-PING-PONG'] } self.app = create_app(test_config) self.client = self.app.test_client() CORS(self.client.application, origins=self.app.config['CORS_ORIGINS'])
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'PLUGINS': ['reject'] } 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.headers = { 'Content-type': 'application/json' } plugins.plugins['old1'] = OldPlugin1() plugins.plugins['test1'] = CustPlugin1() plugins.plugins['test2'] = CustPlugin2() plugins.plugins['test3'] = CustPlugin3()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'PLUGINS': ['reject'] } 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.headers = { 'Content-type': 'application/json' } plugins.plugins['test1'] = TestPlugin1() plugins.plugins['test2'] = TestPlugin2() plugins.plugins['test3'] = TestPlugin3()
def setUp(self): test_config = { 'TESTING': True, 'DEBUG': True, 'AUTH_PROVIDER': 'saml2', 'BASE_URL': 'http://localhost:8080', # 'SAML2_METADATA_URL': 'https://dev-490527.okta.com/app/exk65v4trcrBK3iH6357/sso/saml/metadata' 'SAML2_METADATA_URL': 'http://localhost:9080/simplesaml/saml2/idp/metadata.php' } self.app = create_app(test_config) self.client = self.app.test_client()
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': False, 'HEARTBEAT_TIMEOUT': 240, 'HEARTBEAT_EVENTS': ['Heartbeat', 'Watchdog'], 'PLUGINS': ['heartbeat'] } self.app = create_app(test_config) self.client = self.app.test_client() self.origin = str(uuid4()).upper()[:8] self.heartbeat = {'origin': self.origin, 'tags': ['foo', 'bar', 'baz']} self.headers = {'Content-type': 'application/json'}
def setUp(self): test_config = { 'TESTING': True, 'BASE_URL': 'https://api.alerta.dev:9898/_' } self.app = create_app(test_config) self.client = self.app.test_client() self.prod_alert = { 'id': 'custom-alert-id', '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'] }
def test_config(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': True, 'CUSTOMER_VIEWS': True, 'PLUGINS': [] } self.allowed_environments = ['Foo', 'Bar', 'Baz', 'QUUX'] self.allowed_github_orgs = ['gh1', 'gh2'] self.allowed_gitlab_groups = ['gl1', 'gl2'] self.allowed_keycloak_roles = ['kc1', 'kc2'] self.allowed_oidc_roles = ['oidc1', 'oidc2'] with mod_env( ALLOWED_ENVIRONMENTS=','.join(self.allowed_environments), DEFAULT_ENVIRONMENT='Baz', ALLOWED_GITHUB_ORGS=','.join(self.allowed_github_orgs), # ALLOWED_GITLAB_GROUPS=','.join(self.allowed_gitlab_groups), ALLOWED_KEYCLOAK_ROLES=','.join(self.allowed_keycloak_roles), # ALLOWED_OIDC_ROLES=','.join(self.allowed_oidc_roles), ): self.app = create_app(test_config) self.client = self.app.test_client() response = self.client.get('/config') self.assertEqual(response.status_code, 200) data = json.loads(response.data.decode('utf-8')) self.assertTrue(data['auth_required']) self.assertTrue(data['customer_views']) self.assertListEqual(data['sort_by'], ['severity', 'lastReceiveTime']) self.assertEqual(data['environments'], self.allowed_environments) self.assertEqual(self.app.config['ALLOWED_GITHUB_ORGS'], self.allowed_github_orgs) # self.assertEqual(self.app.config['ALLOWED_GITLAB_GROUPS'], self.allowed_gitlab_groups) # self.assertEqual(self.app.config['ALLOWED_KEYCLOAK_ROLES'], self.allowed_keycloak_roles) self.assertEqual(self.app.config['ALLOWED_OIDC_ROLES'], self.allowed_keycloak_roles)
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'HEARTBEAT_TIMEOUT': 240 } self.app = create_app(test_config) self.client = self.app.test_client() self.origin = str(uuid4()).upper()[:8] self.heartbeat = { 'origin': self.origin, 'tags': ['foo', 'bar', 'baz'] } self.headers = { '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=[Scope.admin, Scope.read, Scope.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, '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): self.app = create_app()
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'ALERT_TIMEOUT': 120, 'HISTORY_LIMIT': 5 } self.app = create_app(test_config) self.client = self.app.test_client() def random_resource(): return str(uuid4()).upper()[:8] self.fatal_alert = { 'event': 'node_down', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network', 'Shared'], 'group': 'Network', 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': { 'foo': 'abc def', 'bar': 1234, 'baz': False }, } self.critical_alert = { 'event': 'node_marginal', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'Nw', 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['bar'], 'timeout': 30 } self.major_alert = { 'event': 'node_marginal', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network', 'Shared'], 'group': 'Network', 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['baz'], 'timeout': 40 } self.warn_alert = { 'event': 'node_marginal', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'net', 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['quux'], 'timeout': 50 } self.normal_alert = { 'event': 'node_up', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'Network', 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['quux'], 'timeout': 100 } self.ok_alert = { 'event': 'node_up', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'nw', 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['quux'], } self.cleared_alert = { 'event': 'node_up', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'Network', 'severity': 'cleared', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], } self.ok2_alert = { 'event': 'node_up', 'resource': random_resource(), 'environment': 'Production', 'service': ['Network'], 'group': 'Network', 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['bar'], } self.headers = { 'Content-type': 'application/json', 'X-Forwarded-For': '10.0.0.1' }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'ALERT_TIMEOUT': 120, 'HISTORY_LIMIT': 5 } self.app = create_app(test_config) self.client = self.app.test_client() self.resource = str(uuid4()).upper()[:8] self.fatal_alert = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network', 'Shared'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False}, } self.fatal_alert_no_attributes = { 'event': 'node_down', 'resource': self.resource, 'environment': 'Production', 'service': ['Network', 'Shared'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'] } self.critical_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 30 } self.major_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network', 'Shared'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.warn_alert = { 'event': 'node_marginal', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 50 } self.normal_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 100 } self.ok_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.cleared_alert = { 'event': 'node_up', 'resource': self.resource, 'environment': 'Production', 'service': ['Network'], 'severity': 'cleared', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.ok2_alert = { 'event': 'node_up', 'resource': self.resource + '2', 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.headers = { 'Content-type': 'application/json', 'X-Forwarded-For': '10.0.0.1' }
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.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'] } 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'] } 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}, } self.critical_alert = { 'event': 'node_marginal', 'resource': 'net02', 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 30 } self.major_alert = { 'event': 'node_marginal', 'resource': 'net03', 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.normal_alert = { 'event': 'node_up', 'resource': 'net03', 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 100 } self.minor_alert = { 'event': 'node_marginal', 'resource': 'net04', 'environment': 'Production', 'service': ['Network'], 'severity': 'minor', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 40 } self.ok_alert = { 'event': 'node_up', 'resource': 'net04', 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'timeout': 100 } self.warn_alert = { 'event': 'node_marginal', 'resource': 'net05', 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'], '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): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False } self.app = create_app(test_config) self.client = self.app.test_client() # alert templates self.trigger_alert = { 'event': 'node_down', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} } self.resolve_alert = { 'event': 'node_marginal', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.cloudwatch_subscription_confirmation = r""" { "Type" : "SubscriptionConfirmation", "MessageId" : "8a14e4f3-f3ab-4be0-a12f-681ee8fe214f", "Token" : "2336412f37fb687f5d51e6e241da92fd72d769c5b4ca6fd6cd6d30949d5a51abf7e21aae199b52813b6f2ea51b41e3119b599532d25df4e6aea368b3a6d8272d38688f73c116b04204e9afb2f5b1d8c4bdb823103299a9f1da7409f1dcf4096ba20a0b0222cc493586e76450e3be6715", "TopicArn" : "arn:aws:sns:eu-west-1:1234567890:alerta-test", "Message" : "You have chosen to subscribe to the topic arn:aws:sns:eu-west-1:1234567890:alerta-test.\nTo confirm the subscriptionDataBuilder, visit the SubscribeURL included in this message.", "SubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:eu-west-1:1234567890:alerta-test&Token=2336412f37fb687f5d51e6e241da92fd72d769c5b4ca6fd6cd6d30949d5a51abf7e21aae199b52813b6f2ea51b41e3119b599532d25df4e6aea368b3a6d8272d38688f73c116b04204e9afb2f5b1d8c4bdb823103299a9f1da7409f1dcf4096ba20a0b0222cc493586e76450e3be6715", "Timestamp" : "2018-07-08T21:33:44.782Z", "SignatureVersion" : "1", "Signature" : "os7PC+SYxz+6Ms92k5T6QDEHOJ8SIgKYL2vR987rSgTk91qqVoY1wTa0kl4SD4Abwb8oAdeL5bXAeoWjwOe8wD88GTEmYRwgGALC2tgrMZP9fBg/5WlHpbUPkcI8Ch8OMxAS8Lmn3ZUq814Vmvse8jqCNyNPquBIxT8KUaka0wFivaVTMKa43OWEWoHKlEfriFD1dtkmI2kKpsJpH7x2Az/izJMpWX9hJpA6aeiuzeeO2LOlLAzH2qD1PmUguPZCUVwbcEiySOD2tL+uwDDiN22h3QxYd9Je8ZfNSwimSbdpQzyumOtoogP9dAHcua8sSo3glPuakNzdFhrWywBVFQ==", "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-eaea6120e66ea12e88dcd8bcbddca752.pem" } """ self.cloudwatch_notification = r""" { "Type" : "Notification", "MessageId" : "e288882d-4281-5be4-8fde-dccc11c8cb01", "TopicArn" : "arn:aws:sns:eu-west-1:1234567890:alerta-test", "Subject" : "ALARM: \"bucketbytesAlarm\" in EU (Ireland)", "Message" : "{\"AlarmName\":\"bucketbytesAlarm\",\"AlarmDescription\":\"bucket bytes size exceeded\",\"AWSAccountId\":\"1234567890\",\"NewStateValue\":\"ALARM\",\"NewStateReason\":\"Threshold Crossed: 1 datapoint [1062305.0 (14/02/19 23:53:00)] was greater than or equal to the threshold (0.0).\",\"StateChangeTime\":\"2019-02-15T23:53:45.093+0000\",\"Region\":\"EU (Ireland)\",\"OldStateValue\":\"INSUFFICIENT_DATA\",\"Trigger\":{\"MetricName\":\"BucketSizeBytes\",\"Namespace\":\"AWS/S3\",\"StatisticType\":\"Statistic\",\"Statistic\":\"AVERAGE\",\"Unit\":null,\"Dimensions\":[{\"value\":\"StandardStorage\",\"name\":\"StorageType\"},{\"value\":\"try.alerta.io\",\"name\":\"BucketName\"}],\"Period\":86400,\"EvaluationPeriods\":1,\"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\"Threshold\":0.0,\"TreatMissingData\":\"\",\"EvaluateLowSampleCountPercentile\":\"\"}}", "Timestamp" : "2019-02-15T23:53:45.134Z", "SignatureVersion" : "1", "Signature" : "Wui8ZxaiH1IXLGJOTonbzc9lUaoq5HN3e2tPaX7G122R4r9P+Gbs01gOUsKMjPFiOwdvLT5rQjJwczb+1F6r6kt4qhU3i1qMHlDjdnXF6rYDzP0u1RUJgX/b3Asb6V5w9SEiTCHlsF7ZInYn99lTOQOI7je4tYv8V9kVlzuynKmr7TGwKmxQc84UoIR9Nb7gU5ZXgOfoY64iZzY8nDssS8rLBTVNTGNVacJWCsIz5RLX41gUhAKNNdCW9dfI6G/cqMc+FFKqVAgYPTwnH/0hdx7jKei5fzyXUOzSSmAFxdUPN+DfwHemrfDzk8enALq7LIbR+HmbhtdSQaiXVAChkg==", "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem", "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:1234567890:alerta-test:6590056b-77a0-495f-83a1-53fbba126544" } """ self.cloudwatch_insufficient_data = r""" { "Type" : "Notification", "MessageId" : "3a6a339c-60fc-5718-875e-66cf50fbf89a", "TopicArn" : "arn:aws:sns:eu-west-1:1234567890:alerta-test", "Subject" : "INSUFFICIENT_DATA: \"NotificationCount\" in EU (Ireland)", "Message" : "{\"AlarmName\":\"notificationCountAlarm\",\"AlarmDescription\":\"number of notifications exceeded\",\"AWSAccountId\":\"1234567890\",\"NewStateValue\":\"INSUFFICIENT_DATA\",\"NewStateReason\":\"Insufficient Data: 10 datapoints were unknown.\",\"StateChangeTime\":\"2019-05-13T08:41:43.548+0000\",\"Region\":\"EU (Ireland)\",\"OldStateValue\":\"ALARM\",\"Trigger\":{\"MetricName\":\"NumberOfNotificationsDelivered\",\"Namespace\":\"AWS/SNS\",\"StatisticType\":\"Statistic\",\"Statistic\":\"AVERAGE\",\"Unit\":null,\"Dimensions\":[{\"value\":\"alerta-test\",\"name\":\"TopicName\"}],\"Period\":300,\"EvaluationPeriods\":10,\"ComparisonOperator\":\"GreaterThanOrEqualToThreshold\",\"Threshold\":0.0,\"TreatMissingData\":\"\",\"EvaluateLowSampleCountPercentile\":\"\"}}", "Timestamp" : "2019-05-13T08:41:43.567Z", "SignatureVersion" : "1", "Signature" : "ebq83SatlvuSq9HIsZdVw1P11K2/axeXMxuEJXEq8S1mNg7h8WVHAcWjauiwr6IvrFglJkuEhcfIVgkomJ4Ijmbz5cJY8Pt0zrRkBvl2z9W7vrdeG3ZIqFf13ki64C7gBpWzyxSh6p1MEAzAjpR13maRvZYB7XH5G5+QjYgZ1dbu4Pt4gtdJNTND5bnXTgkJvccTLeGnHi4cYFP3UkvQPWfKbjTBpkgnHcakeKFHZaxvtU72qhYWcldbqxTAHhjf8LY2p4PE+yRzXiMgqDo1437skFe73IIlb+lqw2NCn0VLyP5VWJFExzl7WRrprmAi4CJzZXRDfFFxaQpTMzTgkA==", "SigningCertURL" : "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53efda11f913f9.pem", "UnsubscribeURL" : "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:1234567890:alerta-test:6e8ae9aa-983b-4a47-9821-f02a4ef3a519" } """ self.grafana_alert_alerting = """ { "evalMatches": [ { "value": 97.007606, "metric": "user", "tags": { "__name__": "netdata_cpu_cpu_percentage_average", "chart": "cpu.cpu0", "dimension": "user", "family": "utilization", "instance": "zeta.domain", "job": "monitoring", "info.host_id": "i-0d0721c7f97545d43" } } ], "message": "boom!", "ruleId": 7, "ruleName": "Zeta CPU alert", "ruleUrl": "https://grafana.domain.tld/dashboard/db/alarms?fullscreen&edit&tab=alert&panelId=1&orgId=1", "state": "alerting", "title": "[Alerting] CPU alert" } """ self.grafana_alert_ok = """ { "evalMatches": [], "message": "boom!", "ruleId": 7, "ruleName": "Zeta CPU alert", "ruleUrl": "https://grafana.domain.tld/dashboard/db/alarms?fullscreen&edit&tab=alert&panelId=1&orgId=1", "state": "ok", "title": "[OK] CPU alert" } """ self.grafana_example = """ { "title": "My alert", "ruleId": 1, "ruleName": "Load peaking!", "ruleUrl": "http://url.to.grafana/db/dashboard/my_dashboard?panelId=2", "state": "alerting", "imageUrl": "http://s3.image.url", "message": "Load is peaking. Make sure the traffic is real and spin up more webfronts", "evalMatches": [ { "metric": "requests", "tags": {}, "value": 122 } ] } """ self.graylog_notification = """ { "check_result": { "result_description": "Stream had 2 messages in the last 1 minutes with trigger condition more than 1 messages. (Current grace time: 1 minutes)", "triggered_condition": { "id": "5e7a9c8d-9bb1-47b6-b8db-4a3a83a25e0c", "type": "MESSAGE_COUNT", "created_at": "2015-09-10T09:44:10.552Z", "creator_user_id": "admin", "grace": 1, "parameters": { "grace": 1, "threshold": 1, "threshold_type": "more", "backlog": 5, "time": 1 }, "description": "time: 1, threshold_type: more, threshold: 1, grace: 1", "type_string": "MESSAGE_COUNT", "backlog": 5 }, "triggered_at": "2015-09-10T09:45:54.749Z", "triggered": true, "matching_messages": [ { "index": "graylog2_7", "message": "WARN: System is failing", "fields": { "gl2_remote_ip": "127.0.0.1", "gl2_remote_port": 56498, "gl2_source_node": "41283fec-36b4-4352-a859-7b3d79846b3c", "gl2_source_input": "55f15092bee8e2841898eb53" }, "id": "b7b08150-57a0-11e5-b2a2-d6b4cd83d1d5", "stream_ids": [ "55f1509dbee8e2841898eb64" ], "source": "127.0.0.1", "timestamp": "2015-09-10T09:45:49.284Z" }, { "index": "graylog2_7", "message": "ERROR: This is an example error message", "fields": { "gl2_remote_ip": "127.0.0.1", "gl2_remote_port": 56481, "gl2_source_node": "41283fec-36b4-4352-a859-7b3d79846b3c", "gl2_source_input": "55f15092bee8e2841898eb53" }, "id": "afd71342-57a0-11e5-b2a2-d6b4cd83d1d5", "stream_ids": [ "55f1509dbee8e2841898eb64" ], "source": "127.0.0.1", "timestamp": "2015-09-10T09:45:36.116Z" } ] }, "stream": { "creator_user_id": "admin", "outputs": [], "matching_type": "AND", "description": "test stream", "created_at": "2015-09-10T09:42:53.833Z", "disabled": false, "rules": [ { "field": "gl2_source_input", "stream_id": "55f1509dbee8e2841898eb64", "id": "55f150b5bee8e2841898eb7f", "type": 1, "inverted": false, "value": "55f15092bee8e2841898eb53" } ], "alert_conditions": [ { "creator_user_id": "admin", "created_at": "2015-09-10T09:44:10.552Z", "id": "5e7a9c8d-9bb1-47b6-b8db-4a3a83a25e0c", "type": "message_count", "parameters": { "grace": 1, "threshold": 1, "threshold_type": "more", "backlog": 5, "time": 1 } } ], "id": "55f1509dbee8e2841898eb64", "title": "test", "content_pack": null } } """ # new relic payload self.pagerduty_alert = """ { "messages": [ { "id": "bb8b8fe0-e8d5-11e2-9c1e-22000afd16cf", "created_on": "2013-07-09T20:25:44Z", "type": "incident.acknowledge", "data": { "incident": { "id": "PIJ90N7", "incident_number": 1, "created_on": "2013-07-09T20:25:44Z", "status": "triggered", "html_url": "https://acme.pagerduty.com/incidents/PIJ90N7", "incident_key": "%s", "service": { "id": "PBAZLIU", "name": "service", "html_url": "https://acme.pagerduty.com/services/PBAZLIU" }, "assigned_to_user": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" }, "trigger_summary_data": { "subject": "45645" }, "trigger_details_html_url": "https://acme.pagerduty.com/incidents/PIJ90N7/log_entries/PIJ90N7", "last_status_change_on": "2013-07-09T20:25:44Z", "last_status_change_by": "null" } } }, { "id": "8a1d6420-e9c4-11e2-b33e-f23c91699516", "created_on": "2013-07-09T20:25:45Z", "type": "incident.resolve", "data": { "incident": { "id": "PIJ90N7", "incident_number": 1, "created_on": "2013-07-09T20:25:44Z", "status": "resolved", "html_url": "https://acme.pagerduty.com/incidents/PIJ90N7", "incident_key": "%s", "service": { "id": "PBAZLIU", "name": "service", "html_url": "https://acme.pagerduty.com/services/PBAZLIU" }, "assigned_to_user": "******", "resolved_by_user": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" }, "trigger_summary_data": { "subject": "45645" }, "trigger_details_html_url": "https://acme.pagerduty.com/incidents/PIJ90N7/log_entries/PIJ90N7", "last_status_change_on": "2013-07-09T20:25:45Z", "last_status_change_by": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" } } } } ] } """ self.pingdom_down = """ { "second_probe": { "ip": "185.39.146.214", "location": "Stockholm 2, Sweden", "ipv6": "2a02:752:100:e::4002" }, "check_type": "HTTP", "first_probe": { "ip": "85.93.93.123", "location": "Strasbourg 5, France", "ipv6": "" }, "tags": [], "check_id": 803318, "current_state": "DOWN", "check_params": { "url": "/", "encryption": false, "hostname": "api.alerta.io", "basic_auth": false, "port": 80, "header": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)", "ipv6": false, "full_url": "http://api.alerta.io/" }, "previous_state": "UP", "check_name": "Alerta API on OpenShift", "version": 1, "state_changed_timestamp": 1498861543, "importance_level": "HIGH", "state_changed_utc_time": "2017-06-30T22:25:43", "long_description": "HTTP Server Error 503 Service Unavailable", "description": "HTTP Error 503" } """ self.pingdom_up = """ { "second_probe": {}, "check_type": "HTTP", "first_probe": { "ip": "185.70.76.23", "location": "Athens, Greece", "ipv6": "" }, "tags": [], "check_id": 803318, "current_state": "UP", "check_params": { "url": "/", "encryption": false, "hostname": "api.alerta.io", "basic_auth": false, "port": 80, "header": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)", "ipv6": false, "full_url": "http://api.alerta.io/" }, "previous_state": "DOWN", "check_name": "Alerta API on OpenShift", "version": 1, "state_changed_timestamp": 1498861843, "importance_level": "HIGH", "state_changed_utc_time": "2017-06-30T22:30:43", "long_description": "OK", "description": "OK" } """ self.prometheus_v3_alert = """ { "alerts": [ { "annotations": { "description": "Connect to host2 fails", "summary": "Connect fail" }, "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://prometheus.host:9090/...", "labels": { "__name__": "ping_success", "alertname": "failedConnect", "environment": "Production", "instance": "host2", "job": "pinger", "monitor": "testlab", "service": "System", "severity": "critical", "timeout": "600" }, "startsAt": "2016-08-01T13:27:08.008+03:00", "status": "firing" } ], "commonAnnotations": { "summary": "Connect fail" }, "commonLabels": { "__name__": "ping_success", "alertname": "failedConnect", "environment": "Production", "job": "pinger", "monitor": "testlab", "service": "System", "severity": "critical", "timeout": "600" }, "externalURL": "http://alertmanager.host:9093", "groupKey": 5615590933959184469, "groupLabels": { "alertname": "failedConnect" }, "receiver": "alerta", "status": "firing", "version": "3" } """ self.prometheus_v4_alert = """ { "receiver": "alerta", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "thing_dead", "severity": "critical" }, "annotations": { "description": "No things have been recorded for over 10 minutes. Something terrible is happening.", "severity": "critical", "summary": "No things for over 10 minutes", "runbookBad": "https://internal.myorg.net/wiki/alerts/{app}/{alertname}", "runbookGood": "https://internal.myorg.net/wiki/alerts/{alertname}" }, "startsAt": "2017-08-03T15:17:37.804-04:00", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://somehost:9090/graph?g0.expr=sum%28irate%28messages_received_total%5B5m%5D%29%29+%3D%3D+0&g0.tab=0" } ], "groupLabels": { "alertname": "thing_dead" }, "commonLabels": { "alertname": "thing_dead" }, "commonAnnotations": { "description": "No things have been recorded for over 10 minutes. Something terrible is happening.", "severity": "critical", "summary": "No things for over 10 minutes" }, "externalURL": "http://somehost:9093", "version": "4", "groupKey": "{}:{alertname=thing_dead}" } """ self.riemann_alert = """ { "host": "hostbob", "service": "servicejane", "state": "ok", "description": "This is a description", "metric": 1 } """ # server density # slack self.stackdriver_open = """ { "incident": { "incident_id": "f2e08c333dc64cb09f75eaab355393bz", "resource_id": "i-4a266a2d", "resource_name": "webserver-85", "state": "open", "started_at": 1499368214, "ended_at": null, "policy_name": "Webserver Health", "condition_name": "CPU usage", "url": "https://app.stackdriver.com/incidents/f2e08c333dc64cb09f75eaab355393bz", "summary": "CPU (agent) for webserver-85 is above the threshold of 1% with a value of 28.5%", "documentation": { "content": "{\\"summary\\": \\"CPU utilization for alerta-webserver-85 is over 95%\\", \ \\"resource_name\\": \\"alerta-webserver-85\\"}", "mime_type": "text/markdown" } }, "version": "1.1" } """ self.stackdriver_closed = """ { "incident": { "incident_id": "f2e08c333dc64cb09f75eaab355393bz", "resource_id": "i-4a266a2d", "resource_name": "webserver-85", "state": "closed", "started_at": 1499368214, "ended_at": 1499368836, "policy_name": "Webserver Health", "condition_name": "CPU usage", "url": "https://app.stackdriver.com/incidents/f2e08c333dc64cb09f75eaab355393bz", "summary": "CPU (agent) for webserver-85 is above the threshold of 1% with a value of 28.5%", "documentation": { "content": "This is a markdown text example", "mime_type": "text/markdown" } }, "version": "1.1" } """ self.telegram_alert = { 'event': 'node_down', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} } self.telegram_ack = """ { "update_id": 913527394, "callback_query": { "id": "688111769854308995", "from": { "id": 160213506, "first_name": "Nick", "last_name": "Satterly", "username": "******" }, "message": { "message_id": 37, "from": { "id": 264434259, "first_name": "alerta-bot", "username": "******" }, "chat": { "id": -163056465, "title": "Alerta Telegram", "type": "group", "all_members_are_administrators": true }, "date": 1481841548, "text": "", "entities": [ { "type": "text_link", "offset": 0, "length": 8, "url": "https://try.alerta.io/#/alert/a2b47856-1779-49a9-a2aa-5cbd2e539b56" } ] }, "chat_instance": "-428019502972440238", "data": "/ack %s" } } """ self.headers = { 'Content-type': 'application/json', 'X-Forwarded-For': ['10.1.1.1', '172.16.1.1', '192.168.1.1'], }
def setUp(self): # create dummy routing rules self.dist = pkg_resources.Distribution(__file__, project_name='alerta-routing', version='0.1') s = 'rules = tests.test_routing: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' # use default key }, 'API_KEY': 'default-key' } 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': 'Key %s' % 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 = { 'TESTING': True, 'AUTH_REQUIRED': False } self.app = create_app(test_config) self.client = self.app.test_client() correlate = ['node_down', 'node_marginal', 'node_up', 'node_pwned', 'node_trace'] self.auth_alert = { 'event': 'node_pwned', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'security', 'correlate': correlate, 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} } self.critical_alert = { 'event': 'node_down', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': correlate } self.major_alert = { 'event': 'node_marginal', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'major', 'correlate': correlate } self.warn_alert = { 'event': 'node_marginal', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': correlate } self.normal_alert = { 'event': 'node_up', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'normal', 'correlate': correlate } self.trace_alert = { 'event': 'node_trace', 'resource': 'node1', 'environment': 'Production', 'service': ['Network'], 'severity': 'trace', 'correlate': correlate } self.ok_alert = { 'event': 'node_ok', 'resource': 'node2', 'environment': 'Production', 'service': ['Network'], 'severity': 'ok', 'correlate': [] } self.inform_alert = { 'event': 'node_inform', 'resource': 'node3', 'environment': 'Production', 'service': ['Network'], 'severity': 'informational', 'correlate': [] } self.debug_alert = { 'event': 'node_debug', 'resource': 'node4', 'environment': 'Production', 'service': ['Network'], 'severity': 'debug', 'correlate': [] } self.headers = { 'Content-type': 'application/json' }
def setUp(self): test_config = { 'TESTING': True, 'ALARM_MODEL': 'ISA_18_2', 'AUTH_REQUIRED': False, 'PLUGINS': [], 'ALERT_TIMEOUT': 120, 'HISTORY_LIMIT': 5 } self.app = create_app(test_config, environment='development') self.client = self.app.test_client() self.fault_alarm = { 'severity': 'Critical', 'origin': 'LIC_101', 'value': 'ERROR', 'resource': 'LIC_101', 'event': 'FAILED_ALM', 'group': 'PROCESS', 'text': 'Shutdown/Interlocked', 'type': 'FAULT', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.critical_alarm = { 'severity': 'Critical', 'origin': 'PID1', 'value': '19', 'resource': 'LIC_101', 'event': 'HI_HI_ALM', 'group': 'PROCESS', 'text': 'High High Alarm Limit 15', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.high_alarm = { 'severity': 'High', 'origin': 'PID1', 'value': '13', 'resource': 'LIC_101', 'event': 'HI_ALM', 'group': 'PROCESS', 'text': 'High Alarm Limit 10', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.medium_alarm = { 'severity': 'Medium', 'origin': 'PID1', 'value': '6', 'resource': 'LIC_101', 'event': 'LO_ALM', 'group': 'PROCESS', 'text': 'Low Alarm Limit 5', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.low_alarm = { 'severity': 'Low', 'origin': 'PID1', 'value': '1', 'resource': 'LIC_101', 'event': 'LO_LO_ALM', 'group': 'PROCESS', 'text': 'Low Low Alarm Limit 0', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.advisory_alarm = { 'severity': 'Advisory', 'origin': 'PID1', 'value': '1', 'resource': 'LIC_101', 'event': 'ADVISE_ALM', 'group': 'PROCESS', 'text': 'Low Low Alarm Limit 0', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] } self.ok_alarm = { 'severity': 'OK', 'origin': 'PID1', 'value': '0', 'resource': 'LIC_101', 'event': 'RST_ALM', 'group': 'PROCESS', 'text': 'OK Alarm Limit 0', 'type': 'ALARM', 'environment': 'Production', 'service': ['REACTORS'], 'correlate': ['FAILED_ALM', 'HI_HI_ALM', 'HI_ALM', 'LO_ALM', 'LO_LO_ALM', 'ADVISE_ALM', 'RST_ALM'] }
def setUp(self): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False, 'ALERT_TIMEOUT': 120, 'HISTORY_LIMIT': 5, 'DEBUG': True, # 'PLUGINS': ['logstash'] } self.app = create_app(test_config) self.client = self.app.test_client() alerts = [ { 'resource': 'net01', 'event': 'node_marginal', 'environment': 'Production', 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'status': 'open', 'service': ['Network', 'Core'], 'group': 'Network', 'value': 'johno', 'text': 'panic: this is a foo alert', 'tags': ['aaa', 'bbb', 'ccc'], 'attributes': {'region': 'NORAM'}, 'origin': 'alpha', 'timeout': 100, 'rawData': '' }, { 'resource': 'network02', 'event': 'node_down', 'environment': 'Production', 'severity': 'major', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'status': 'ack', 'service': ['Network', 'Core', 'Shared'], 'group': 'Network', 'value': 'jonathon', 'text': 'Kernel Panic: this is a bar test alert', 'tags': ['bbb', 'ccc', 'ddd'], 'attributes': {'region': 'LATAM'}, 'origin': 'bravo', 'timeout': 200, 'rawData': '' }, { 'resource': 'netwrk03', 'event': 'node_up', 'environment': 'Production', 'severity': 'normal', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'status': 'closed', 'service': ['Network', 'Shared'], 'group': 'Netperf', 'value': 'jonathan', 'text': 'kernel panic: this is a foo bar text alert', 'tags': ['ccc', 'ddd', 'eee'], 'attributes': {'region': 'APAC'}, 'origin': 'charlie', 'timeout': 300, 'rawData': '' }, { 'resource': 'network4', 'event': 'node_up', 'environment': 'Production', 'severity': 'ok', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'status': 'closed', 'service': ['Core', 'Shared'], 'group': 'Performance', 'value': 'john', 'text': 'kernel panick: this is a fu bar baz quux tests alert (i have a boat)', 'tags': ['ddd', 'eee', 'aaa'], 'attributes': {'region': 'EMEA'}, 'origin': 'delta', 'timeout': 400, 'rawData': '' }, { 'resource': 'net5', 'event': 'node_down', 'environment': 'Production', 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'status': 'shelved', 'service': ['Network', 'Core', 'Shared'], 'group': 'Network', 'value': 'jon', 'text': 'don\'t panic: this is a foo bar baz quux tester alert (i have a moat)', 'tags': ['eee', 'aaa', 'bbb'], 'attributes': {}, 'origin': 'zulu', 'timeout': 500, 'rawData': '' }, ] for alert in alerts: response = self.client.post('/alert', json=alert, content_type='application/json') self.assertEqual(response.status_code, 201)
def _create_app(info): from alerta.app import create_app return create_app()
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): test_config = { 'TESTING': True, 'AUTH_REQUIRED': False } self.app = create_app(test_config) self.client = self.app.test_client() self.trigger_alert = { 'event': 'node_down', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} } self.resolve_alert = { 'event': 'node_marginal', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.pingdom_down = """ { "second_probe": { "ip": "185.39.146.214", "location": "Stockholm 2, Sweden", "ipv6": "2a02:752:100:e::4002" }, "check_type": "HTTP", "first_probe": { "ip": "85.93.93.123", "location": "Strasbourg 5, France", "ipv6": "" }, "tags": [], "check_id": 803318, "current_state": "DOWN", "check_params": { "url": "/", "encryption": false, "hostname": "api.alerta.io", "basic_auth": false, "port": 80, "header": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)", "ipv6": false, "full_url": "http://api.alerta.io/" }, "previous_state": "UP", "check_name": "Alerta API on OpenShift", "version": 1, "state_changed_timestamp": 1498861543, "importance_level": "HIGH", "state_changed_utc_time": "2017-06-30T22:25:43", "long_description": "HTTP Server Error 503 Service Unavailable", "description": "HTTP Error 503" } """ self.pingdom_up = """ { "second_probe": {}, "check_type": "HTTP", "first_probe": { "ip": "185.70.76.23", "location": "Athens, Greece", "ipv6": "" }, "tags": [], "check_id": 803318, "current_state": "UP", "check_params": { "url": "/", "encryption": false, "hostname": "api.alerta.io", "basic_auth": false, "port": 80, "header": "User-Agent:Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)", "ipv6": false, "full_url": "http://api.alerta.io/" }, "previous_state": "DOWN", "check_name": "Alerta API on OpenShift", "version": 1, "state_changed_timestamp": 1498861843, "importance_level": "HIGH", "state_changed_utc_time": "2017-06-30T22:30:43", "long_description": "OK", "description": "OK" } """ self.pagerduty_alert = """ { "messages": [ { "id": "bb8b8fe0-e8d5-11e2-9c1e-22000afd16cf", "created_on": "2013-07-09T20:25:44Z", "type": "incident.acknowledge", "data": { "incident": { "id": "PIJ90N7", "incident_number": 1, "created_on": "2013-07-09T20:25:44Z", "status": "triggered", "html_url": "https://acme.pagerduty.com/incidents/PIJ90N7", "incident_key": "%s", "service": { "id": "PBAZLIU", "name": "service", "html_url": "https://acme.pagerduty.com/services/PBAZLIU" }, "assigned_to_user": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" }, "trigger_summary_data": { "subject": "45645" }, "trigger_details_html_url": "https://acme.pagerduty.com/incidents/PIJ90N7/log_entries/PIJ90N7", "last_status_change_on": "2013-07-09T20:25:44Z", "last_status_change_by": "null" } } }, { "id": "8a1d6420-e9c4-11e2-b33e-f23c91699516", "created_on": "2013-07-09T20:25:45Z", "type": "incident.resolve", "data": { "incident": { "id": "PIJ90N7", "incident_number": 1, "created_on": "2013-07-09T20:25:44Z", "status": "resolved", "html_url": "https://acme.pagerduty.com/incidents/PIJ90N7", "incident_key": "%s", "service": { "id": "PBAZLIU", "name": "service", "html_url": "https://acme.pagerduty.com/services/PBAZLIU" }, "assigned_to_user": "******", "resolved_by_user": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" }, "trigger_summary_data": { "subject": "45645" }, "trigger_details_html_url": "https://acme.pagerduty.com/incidents/PIJ90N7/log_entries/PIJ90N7", "last_status_change_on": "2013-07-09T20:25:45Z", "last_status_change_by": { "id": "PPI9KUT", "name": "Alan Kay", "email": "*****@*****.**", "html_url": "https://acme.pagerduty.com/users/PPI9KUT" } } } } ] } """ self.riemann_alert = """ { "host": "hostbob", "service": "servicejane", "state": "ok", "description": "This is a description", "metric": 1 } """ self.stackdriver_open = """ { "incident": { "incident_id": "f2e08c333dc64cb09f75eaab355393bz", "resource_id": "i-4a266a2d", "resource_name": "webserver-85", "state": "open", "started_at": 1499368214, "ended_at": null, "policy_name": "Webserver Health", "condition_name": "CPU usage", "url": "https://app.stackdriver.com/incidents/f2e08c333dc64cb09f75eaab355393bz", "summary": "CPU (agent) for webserver-85 is above the threshold of 1% with a value of 28.5%" }, "version": "1.1" } """ self.stackdriver_closed = """ { "incident": { "incident_id": "f2e08c333dc64cb09f75eaab355393bz", "resource_id": "i-4a266a2d", "resource_name": "webserver-85", "state": "closed", "started_at": 1499368214, "ended_at": 1499368836, "policy_name": "Webserver Health", "condition_name": "CPU usage", "url": "https://app.stackdriver.com/incidents/f2e08c333dc64cb09f75eaab355393bz", "summary": "CPU (agent) for webserver-85 is above the threshold of 1% with a value of 28.5%" }, "version": "1.1" } """ self.prometheus_v3_alert = """ { "alerts": [ { "annotations": { "description": "Connect to host2 fails", "summary": "Connect fail" }, "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://prometheus.host:9090/...", "labels": { "__name__": "ping_success", "alertname": "failedConnect", "environment": "Production", "instance": "host2", "job": "pinger", "monitor": "testlab", "service": "System", "severity": "critical", "timeout": "600" }, "startsAt": "2016-08-01T13:27:08.008+03:00", "status": "firing" } ], "commonAnnotations": { "summary": "Connect fail" }, "commonLabels": { "__name__": "ping_success", "alertname": "failedConnect", "environment": "Production", "job": "pinger", "monitor": "testlab", "service": "System", "severity": "critical", "timeout": "600" }, "externalURL": "http://alertmanager.host:9093", "groupKey": 5615590933959184469, "groupLabels": { "alertname": "failedConnect" }, "receiver": "alerta", "status": "firing", "version": "3" } """ self.prometheus_v4_alert = """ { "receiver": "alerta", "status": "firing", "alerts": [ { "status": "firing", "labels": { "alertname": "thing_dead" }, "annotations": { "description": "No things have been recorded for over 10 minutes. Something terrible is happening.", "severity": "critical", "summary": "No things for over 10 minutes" }, "startsAt": "2017-08-03T15:17:37.804-04:00", "endsAt": "0001-01-01T00:00:00Z", "generatorURL": "http://somehost:9090/graph?g0.expr=sum%28irate%28messages_received_total%5B5m%5D%29%29+%3D%3D+0&g0.tab=0" } ], "groupLabels": { "alertname": "thing_dead" }, "commonLabels": { "alertname": "thing_dead" }, "commonAnnotations": { "description": "No things have been recorded for over 10 minutes. Something terrible is happening.", "severity": "critical", "summary": "No things for over 10 minutes" }, "externalURL": "http://somehost:9093", "version": "4", "groupKey": "{}:{alertname=thing_dead}" } """ self.grafana_alert_alerting = """ { "evalMatches": [ { "value": 97.007606, "metric": "user", "tags": { "__name__": "netdata_cpu_cpu_percentage_average", "chart": "cpu.cpu0", "dimension": "user", "family": "utilization", "instance": "zeta.domain", "job": "monitoring" } } ], "message": "boom!", "ruleId": 7, "ruleName": "Zeta CPU alert", "ruleUrl": "https://grafana.domain.tld/dashboard/db/alarms?fullscreen&edit&tab=alert&panelId=1&orgId=1", "state": "alerting", "title": "[Alerting] CPU alert" } """ self.grafana_alert_ok = """ { "evalMatches": [], "message": "boom!", "ruleId": 7, "ruleName": "Zeta CPU alert", "ruleUrl": "https://grafana.domain.tld/dashboard/db/alarms?fullscreen&edit&tab=alert&panelId=1&orgId=1", "state": "ok", "title": "[OK] CPU alert" } """ self.telegram_alert = { 'event': 'node_down', 'resource': str(uuid4()).upper()[:8], 'environment': 'Production', 'service': ['Network'], 'severity': 'critical', 'correlate': ['node_down', 'node_marginal', 'node_up'], 'tags': ['foo'], 'attributes': {'foo': 'abc def', 'bar': 1234, 'baz': False} } self.telegram_ack = """ { "update_id": 913527394, "callback_query": { "id": "688111769854308995", "from": { "id": 160213506, "first_name": "Nick", "last_name": "Satterly", "username": "******" }, "message": { "message_id": 37, "from": { "id": 264434259, "first_name": "alerta-bot", "username": "******" }, "chat": { "id": -163056465, "title": "Alerta Telegram", "type": "group", "all_members_are_administrators": true }, "date": 1481841548, "text": "", "entities": [ { "type": "text_link", "offset": 0, "length": 8, "url": "https://try.alerta.io/#/alert/a2b47856-1779-49a9-a2aa-5cbd2e539b56" } ] }, "chat_instance": "-428019502972440238", "data": "/ack %s" } } """ self.graylog_notification = """ { "check_result": { "result_description": "Stream had 2 messages in the last 1 minutes with trigger condition more than 1 messages. (Current grace time: 1 minutes)", "triggered_condition": { "id": "5e7a9c8d-9bb1-47b6-b8db-4a3a83a25e0c", "type": "MESSAGE_COUNT", "created_at": "2015-09-10T09:44:10.552Z", "creator_user_id": "admin", "grace": 1, "parameters": { "grace": 1, "threshold": 1, "threshold_type": "more", "backlog": 5, "time": 1 }, "description": "time: 1, threshold_type: more, threshold: 1, grace: 1", "type_string": "MESSAGE_COUNT", "backlog": 5 }, "triggered_at": "2015-09-10T09:45:54.749Z", "triggered": true, "matching_messages": [ { "index": "graylog2_7", "message": "WARN: System is failing", "fields": { "gl2_remote_ip": "127.0.0.1", "gl2_remote_port": 56498, "gl2_source_node": "41283fec-36b4-4352-a859-7b3d79846b3c", "gl2_source_input": "55f15092bee8e2841898eb53" }, "id": "b7b08150-57a0-11e5-b2a2-d6b4cd83d1d5", "stream_ids": [ "55f1509dbee8e2841898eb64" ], "source": "127.0.0.1", "timestamp": "2015-09-10T09:45:49.284Z" }, { "index": "graylog2_7", "message": "ERROR: This is an example error message", "fields": { "gl2_remote_ip": "127.0.0.1", "gl2_remote_port": 56481, "gl2_source_node": "41283fec-36b4-4352-a859-7b3d79846b3c", "gl2_source_input": "55f15092bee8e2841898eb53" }, "id": "afd71342-57a0-11e5-b2a2-d6b4cd83d1d5", "stream_ids": [ "55f1509dbee8e2841898eb64" ], "source": "127.0.0.1", "timestamp": "2015-09-10T09:45:36.116Z" } ] }, "stream": { "creator_user_id": "admin", "outputs": [], "matching_type": "AND", "description": "test stream", "created_at": "2015-09-10T09:42:53.833Z", "disabled": false, "rules": [ { "field": "gl2_source_input", "stream_id": "55f1509dbee8e2841898eb64", "id": "55f150b5bee8e2841898eb7f", "type": 1, "inverted": false, "value": "55f15092bee8e2841898eb53" } ], "alert_conditions": [ { "creator_user_id": "admin", "created_at": "2015-09-10T09:44:10.552Z", "id": "5e7a9c8d-9bb1-47b6-b8db-4a3a83a25e0c", "type": "message_count", "parameters": { "grace": 1, "threshold": 1, "threshold_type": "more", "backlog": 5, "time": 1 } } ], "id": "55f1509dbee8e2841898eb64", "title": "test", "content_pack": null } } """ self.headers = { 'Content-type': 'application/json', 'X-Forwarded-For': ['10.1.1.1', '172.16.1.1', '192.168.1.1'], }