Esempio n. 1
0
    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))
Esempio n. 2
0
    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)
        )
Esempio n. 3
0
    def parse(cls, json: JSON) -> 'Alert':
        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['createTime']) if 'createTime' in json else None,
            timeout=json.get('timeout', None),
            raw_data=json.get('rawData', None),
            customer=json.get('customer', None)
        )
Esempio n. 4
0
 def get_body(self, history=True):
     body = self.serialize
     body.update({
         key: DateTime.iso8601(body[key]) for key in ['createTime', 'lastReceiveTime', 'receiveTime']
     })
     if not history:
         body['history'] = []
     return body
Esempio n. 5
0
 def get_body(self, history: bool=True) -> Dict[str, Any]:
     body = self.serialize
     body.update({
         key: DateTime.iso8601(body[key]) for key in ['createTime', 'lastReceiveTime', 'receiveTime']
     })
     if not history:
         body['history'] = []
     return body
Esempio n. 6
0
    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)
        )
Esempio n. 7
0
    def get_body(self, history: bool = True) -> Dict[str, Any]:
        body = self.serialize
        keys2Replace = ['createTime', 'lastReceiveTime', 'receiveTime']
        if 'updateTime' in body and body['updateTime'] != None:
            keys2Replace.append('updateTime')

        body.update({key: DateTime.iso8601(body[key]) for key in keys2Replace})
        if not history:
            body['history'] = []
        return body
Esempio n. 8
0
    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))
Esempio n. 9
0
    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)
        )
Esempio n. 10
0
    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))
Esempio n. 11
0
    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
Esempio n. 12
0
File: key.py Progetto: 3IWOH/alerta
    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
Esempio n. 13
0
    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
Esempio n. 14
0
    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')
Esempio n. 15
0
File: key.py Progetto: yrsdi/alerta
    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
Esempio n. 16
0
    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')
Esempio n. 17
0
    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)
        )
Esempio n. 18
0
 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))
Esempio n. 19
0
 def _adapt_datetime(dt):
     return AsIs("%s" % adapt(DateTime.iso8601(dt)))
Esempio n. 20
0
 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))
Esempio n. 21
0
 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))
Esempio n. 22
0
 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))
Esempio n. 23
0
 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))