def update(self, **kwargs) -> 'Blackout': if kwargs.get('startTime'): kwargs['startTime'] = DateTime.parse(kwargs['startTime']) if kwargs.get('endTime'): kwargs['endTime'] = DateTime.parse(kwargs['endTime']) blackout = Blackout.from_db(db.update_blackout(self.id, **kwargs)) process_blackout(blackout, action='update') return blackout
def parse(cls, json: JSON) -> 'Note': return Note(text=json.get('status', None), user=json.get('status', None), attributes=json.get('attributes', dict()), note_type=json.get('type', None), create_time=DateTime.parse(json['createTime']) if 'createTime' in json else None, update_time=DateTime.parse(json['updateTime']) if 'updateTime' in json else None, alert=json.get('related', {}).get('alert'), customer=json.get('customer', None))
def parse(cls, json): if not isinstance(json.get('correlate', []), list): raise ValueError('correlate must be a list') if not isinstance(json.get('service', []), list): raise ValueError('service must be a list') if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') if not isinstance(json.get('attributes', {}), dict): raise ValueError('attributes must be a JSON object') if not isinstance( json.get('timeout') if json.get('timeout', None) is not None else 0, int): raise ValueError('timeout must be an integer') if json.get('customer', None) == '': raise ValueError('customer must not be an empty string') return Alert(id=json.get('id', None), resource=json.get('resource', None), event=json.get('event', None), environment=json.get('environment', None), severity=json.get('severity', None), correlate=json.get('correlate', list()), status=json.get('status', None), service=json.get('service', list()), group=json.get('group', None), value=json.get('value', None), text=json.get('text', None), tags=json.get('tags', list()), attributes=json.get('attributes', dict()), origin=json.get('origin', None), event_type=json.get('type', None), create_time=DateTime.parse(json.get('createTime')), timeout=json.get('timeout', None), raw_data=json.get('rawData', None), customer=json.get('customer', None))
def parse(cls, json): if not isinstance(json.get('correlate', []), list): raise ValueError('correlate must be a list') if not isinstance(json.get('service', []), list): raise ValueError('service must be a list') if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') if not isinstance(json.get('attributes', {}), dict): raise ValueError('attributes must be a JSON object') if not isinstance(json.get('timeout') if json.get('timeout', None) is not None else 0, int): raise ValueError('timeout must be an integer') return Alert( resource=json.get('resource', None), event=json.get('event', None), environment=json.get('environment', None), severity=json.get('severity', None), correlate=json.get('correlate', list()), status=json.get('status', None), service=json.get('service', list()), group=json.get('group', None), value=json.get('value', None), text=json.get('text', None), tags=json.get('tags', list()), attributes=json.get('attributes', dict()), origin=json.get('origin', None), event_type=json.get('type', None), create_time=DateTime.parse(json.get('createTime')), timeout=json.get('timeout', None), raw_data=json.get('rawData', None), customer=json.get('customer', None) )
def parse(cls, json): if not isinstance(json.get('service', []), list): raise ValueError('service must be a list') if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') return Blackout(environment=json.get('environment'), service=json.get('service', list()), resource=json.get('resource', None), event=json.get('event', None), group=json.get('group', None), tags=json.get('tags', list()), customer=json.get('customer', None), start_time=DateTime.parse(json.get('startTime')), end_time=DateTime.parse(json.get('endTime')), duration=json.get('duration', None))
def parse(cls, json): if not isinstance(json.get('service', []), list): raise ValueError('service must be a list') if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') return Blackout( environment=json.get('environment'), service=json.get('service', list()), resource=json.get('resource', None), event=json.get('event', None), group=json.get('group', None), tags=json.get('tags', list()), customer=json.get('customer', None), start_time=DateTime.parse(json.get('startTime')), end_time=DateTime.parse(json.get('endTime')), duration=json.get('duration', None) )
def parse(cls, json: JSON) -> 'Blackout': if not isinstance(json.get('service', []), list): raise ValueError('service must be a list') if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') return Blackout(id=json.get('id', None), environment=json['environment'], service=json.get('service', list()), resource=json.get('resource', None), event=json.get('event', None), group=json.get('group', None), tags=json.get('tags', list()), customer=json.get('customer', None), start_time=DateTime.parse(json['startTime']) if 'startTime' in json else None, end_time=DateTime.parse(json['endTime']) if 'endTime' in json else None, duration=json.get('duration', None), user=json.get('user', None), text=json.get('text', None))
def parse(cls, json): if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') if not isinstance( json.get('timeout') if json.get('timeout', None) is not None else 0, int): raise ValueError('timeout must be an integer') return Heartbeat(origin=json.get('origin', None), tags=json.get('tags', list()), create_time=DateTime.parse(json.get('createTime')), timeout=json.get('timeout', None), customer=json.get('customer', None))
def parse(cls, json): if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') if not isinstance(json.get('timeout') if json.get('timeout', None) is not None else 0, int): raise ValueError('timeout must be an integer') return Heartbeat( origin=json.get('origin', None), tags=json.get('tags', list()), create_time=DateTime.parse(json.get('createTime')), timeout=json.get('timeout', None), customer=json.get('customer', None) )
def parse(cls, json): if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey(user=json.get('user', None), scopes=json.get('scopes', None) or list(), text=json.get('text', None), expire_time=DateTime.parse(json.get('expireTime')), customer=json.get('customer', None)) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json: JSON) -> 'ApiKey': if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=[Scope(s) for s in json.get('scopes', [])], text=json.get('text', None), expire_time=DateTime.parse(json['expireTime']) if 'expireTime' in json else None, customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json): if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=json.get('scopes', None) or list(), text=json.get('text', None), expire_time=DateTime.parse(json.get('expireTime')), customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def parse(cls, json: JSON) -> 'ApiKey': if not isinstance(json.get('scopes', []), list): raise ValueError('scopes must be a list') api_key = ApiKey( user=json.get('user', None), scopes=[Scope(s) for s in json.get('scopes', [])], text=json.get('text', None), expire_time=DateTime.parse(json['expireTime']) if 'expireTime' in json else None, customer=json.get('customer', None) ) if 'type' in json: api_key.scopes = key_helper.type_to_scopes(api_key.user, json['type']) return api_key
def test_user_info(self): self.headers = { 'Authorization': 'Key %s' % self.admin_api_key.key, 'Content-type': 'application/json' } # create new blackout response = self.client.post('/blackout', data=json.dumps({'environment': 'Production', 'service': [ 'Network'], 'text': 'administratively down'}), headers=self.headers) self.assertEqual(response.status_code, 201) data = json.loads(response.data.decode('utf-8')) self.assertEqual(data['blackout']['user'], '*****@*****.**') self.assertIsInstance(DateTime.parse(data['blackout']['createTime']), datetime) self.assertEqual(data['blackout']['text'], 'administratively down')
def test_user_info(self): self.headers = { 'Authorization': 'Key %s' % self.admin_api_key.key, 'Content-type': 'application/json' } # create new blackout response = self.client.post('/blackout', data=json.dumps({'environment': 'Production', 'service': [ 'Network'], 'text': 'administratively down'}), headers=self.headers) self.assertEqual(response.status_code, 201) data = json.loads(response.data.decode('utf-8')) self.assertEqual(data['blackout']['user'], '*****@*****.**') self.assertIsInstance(DateTime.parse(data['blackout']['createTime']), datetime) self.assertEqual(data['blackout']['text'], 'administratively down')
def parse(cls, json: JSON) -> 'Heartbeat': if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') if not isinstance(json.get('timeout') if json.get('timeout', None) is not None else 0, int): raise ValueError('timeout must be an integer') if json.get('customer', None) == '': raise ValueError('customer must not be an empty string') return Heartbeat( origin=json.get('origin', None), tags=json.get('tags', list()), create_time=DateTime.parse(json['createTime']) if 'createTime' in json else None, timeout=json.get('timeout', None), customer=json.get('customer', None) )
def update(self, **kwargs) -> 'Blackout': if kwargs.get('startTime'): kwargs['startTime'] = DateTime.parse(kwargs['startTime']) if kwargs.get('endTime'): kwargs['endTime'] = DateTime.parse(kwargs['endTime']) return Blackout.from_db(db.update_blackout(self.id, **kwargs))
def update(self, **kwargs) -> 'ApiKey': kwargs['expireTime'] = DateTime.parse(kwargs['expireTime']) if 'expireTime' in kwargs else None return ApiKey.from_db(db.update_key(self.key, **kwargs))
def update(self, **kwargs) -> 'ApiKey': kwargs['expireTime'] = DateTime.parse(kwargs['expireTime']) if 'expireTime' in kwargs else None return ApiKey.from_db(db.update_key(self.key, **kwargs))
def update(self, **kwargs) -> 'Blackout': if kwargs.get('startTime'): kwargs['startTime'] = DateTime.parse(kwargs['startTime']) if kwargs.get('endTime'): kwargs['endTime'] = DateTime.parse(kwargs['endTime']) return Blackout.from_db(db.update_blackout(self.id, **kwargs))
def update(self, **kwargs) -> 'Blackout': kwargs['startTime'] = DateTime.parse( kwargs['startTime']) if 'startTime' in kwargs else None kwargs['endTime'] = DateTime.parse( kwargs['endTime']) if 'endTime' in kwargs else None return Blackout.from_db(db.update_blackout(self.id, **kwargs))