-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoring_manager.py
More file actions
35 lines (27 loc) · 1.3 KB
/
monitoring_manager.py
File metadata and controls
35 lines (27 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
from spaceone.core.manager import BaseManager
from cloudforet.monitoring.connector import CloudLoggingConnector
from cloudforet.monitoring.model.log_model import Event, Log
from cloudforet.monitoring.error.custom_error import ERROR_CONVERT_EVENT
_LOGGER = logging.getLogger(__name__)
class MonitoringManager(BaseManager):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def list_logs(self, params):
query = params.get('query', {})
if not query:
return Log({'results': []})
cloud_logging_conn: CloudLoggingConnector = self.locator.get_connector('CloudLoggingConnector', **params)
for logs in cloud_logging_conn.list_log_entries(params):
event_vos = []
for log in logs:
if proto_payload := log.get('protoPayload'):
principal_email = proto_payload.get('authenticationInfo', {}).get('principalEmail')
if not principal_email.startswith('system'):
try:
event_vos.append(Event(log))
except Exception as e:
raise ERROR_CONVERT_EVENT(event=log, error=e)
if not event_vos:
continue
yield Log({'results': event_vos})