]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/logs.py
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / logs.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import collections
5
6 from ..security import Scope
7 from ..services.ceph_service import CephService
8 from ..tools import NotificationQueue
9 from . import APIDoc, APIRouter, BaseController, Endpoint, EndpointDoc, ReadPermission
10
11 LOG_BUFFER_SIZE = 30
12
13 LOGS_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
33
34 @APIRouter('/logs', Scope.LOG)
35 @APIDoc("Logs Management API", "Logs")
36 class Logs(BaseController):
37 def __init__(self):
38 super().__init__()
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(
51 'mon', 'log last', channel=channel_name, num=LOG_BUFFER_SIZE, level='debug')
52 for line in lines:
53 buf.appendleft(line)
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
66 @EndpointDoc("Display Logs Configuration",
67 responses={200: LOGS_SCHEMA})
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 )