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