]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/logs.py
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / logs.py
CommitLineData
11fdf7f2 1# -*- coding: utf-8 -*-
11fdf7f2
TL
2
3import collections
4
11fdf7f2
TL
5from ..security import Scope
6from ..services.ceph_service import CephService
7from ..tools import NotificationQueue
a4b75251 8from . import APIDoc, APIRouter, BaseController, Endpoint, EndpointDoc, ReadPermission
11fdf7f2
TL
9
10LOG_BUFFER_SIZE = 30
11
f67539c2
TL
12LOGS_SCHEMA = {
13 "clog": ([str], ""),
14 "audit_log": ([{
15 "name": (str, ""),
16 "rank": (str, ""),
17 "addrs": ({
18 "addrvec": ([{
19 "type": (str, ""),
20 "addr": (str, "IP Address"),
21 "nonce": (int, ""),
22 }], ""),
23 }, ""),
24 "stamp": (str, ""),
25 "seq": (int, ""),
26 "channel": (str, ""),
27 "priority": (str, ""),
28 "message": (str, ""),
29 }], "Audit log")
30}
31
11fdf7f2 32
a4b75251
TL
33@APIRouter('/logs', Scope.LOG)
34@APIDoc("Logs Management API", "Logs")
11fdf7f2
TL
35class Logs(BaseController):
36 def __init__(self):
a4b75251 37 super().__init__()
11fdf7f2
TL
38 self._log_initialized = False
39 self.log_buffer = collections.deque(maxlen=LOG_BUFFER_SIZE)
40 self.audit_buffer = collections.deque(maxlen=LOG_BUFFER_SIZE)
41
42 def append_log(self, log_struct):
43 if log_struct['channel'] == 'audit':
44 self.audit_buffer.appendleft(log_struct)
45 else:
46 self.log_buffer.appendleft(log_struct)
47
48 def load_buffer(self, buf, channel_name):
49 lines = CephService.send_command(
f67539c2
TL
50 'mon', 'log last', channel=channel_name, num=LOG_BUFFER_SIZE, level='debug')
51 for line in lines:
52 buf.appendleft(line)
11fdf7f2
TL
53
54 def initialize_buffers(self):
55 if not self._log_initialized:
56 self._log_initialized = True
57
58 self.load_buffer(self.log_buffer, 'cluster')
59 self.load_buffer(self.audit_buffer, 'audit')
60
61 NotificationQueue.register(self.append_log, 'clog')
62
63 @Endpoint()
64 @ReadPermission
f67539c2
TL
65 @EndpointDoc("Display Logs Configuration",
66 responses={200: LOGS_SCHEMA})
11fdf7f2
TL
67 def all(self):
68 self.initialize_buffers()
69 return dict(
70 clog=list(self.log_buffer),
71 audit_log=list(self.audit_buffer),
72 )