]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/logs/logs.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / logs / logs.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import { LogsService } from '../../../shared/api/logs.service';
4
5 @Component({
6 selector: 'cd-logs',
7 templateUrl: './logs.component.html',
8 styleUrls: ['./logs.component.scss']
9 })
10 export class LogsComponent implements OnInit, OnDestroy {
11 contentData: any;
12 clog: Array<any>;
13 audit_log: Array<any>;
14
15 interval: number;
16 bsConfig = {
17 dateInputFormat: 'YYYY-MM-DD',
18 containerClass: 'theme-default'
19 };
20 prioritys: Array<{ name: string; value: string }> = [
21 { name: 'Info', value: '[INF]' },
22 { name: 'Warning', value: '[WRN]' },
23 { name: 'Error', value: '[ERR]' },
24 { name: 'All', value: 'All' }
25 ];
26 priority = 'All';
27 search = '';
28 selectedDate: Date;
29 startTime: Date = new Date();
30 endTime: Date = new Date();
31 constructor(private logsService: LogsService) {
32 this.startTime.setHours(0, 0);
33 this.endTime.setHours(23, 59);
34 }
35
36 ngOnInit() {
37 this.getInfo();
38 this.interval = window.setInterval(() => {
39 this.getInfo();
40 }, 5000);
41 }
42
43 ngOnDestroy() {
44 clearInterval(this.interval);
45 }
46
47 getInfo() {
48 this.logsService.getLogs().subscribe((data: any) => {
49 this.contentData = data;
50 this.filterLogs();
51 });
52 }
53
54 abstractfilters(): any {
55 const priority = this.priority;
56 const key = this.search.toLowerCase().replace(/,/g, '');
57
58 let yearMonthDay: string;
59 if (this.selectedDate) {
60 const m = this.selectedDate.getMonth() + 1;
61 const d = this.selectedDate.getDate();
62
63 const year = this.selectedDate.getFullYear().toString();
64 const month = m <= 9 ? `0${m}` : `${m}`;
65 const day = d <= 9 ? `0${d}` : `${d}`;
66 yearMonthDay = `${year}-${month}-${day}`;
67 } else {
68 yearMonthDay = '';
69 }
70
71 const sHour = this.startTime ? this.startTime.getHours() : 0;
72 const sMinutes = this.startTime ? this.startTime.getMinutes() : 0;
73 const sTime = sHour * 60 + sMinutes;
74
75 const eHour = this.endTime ? this.endTime.getHours() : 23;
76 const eMinutes = this.endTime ? this.endTime.getMinutes() : 59;
77 const eTime = eHour * 60 + eMinutes;
78
79 return { priority, key, yearMonthDay, sTime, eTime };
80 }
81
82 filterExecutor(logs: Array<any>, filters: any): Array<any> {
83 return logs.filter((line) => {
84 const hour = parseInt(line.stamp.slice(11, 13), 10);
85 const minutes = parseInt(line.stamp.slice(14, 16), 10);
86 let prio: string, y_m_d: string, timeSpan: number;
87
88 prio = filters.priority === 'All' ? line.priority : filters.priority;
89 y_m_d = filters.yearMonthDay ? filters.yearMonthDay : line.stamp;
90 timeSpan = hour * 60 + minutes;
91 return (
92 line.priority === prio &&
93 line.message.toLowerCase().indexOf(filters.key) !== -1 &&
94 line.stamp.indexOf(y_m_d) !== -1 &&
95 timeSpan >= filters.sTime &&
96 timeSpan <= filters.eTime
97 );
98 });
99 }
100
101 filterLogs() {
102 const filters = this.abstractfilters();
103 this.clog = this.filterExecutor(this.contentData.clog, filters);
104 this.audit_log = this.filterExecutor(this.contentData.audit_log, filters);
105 }
106
107 clearSearchKey() {
108 this.search = '';
109 this.filterLogs();
110 }
111 clearDate() {
112 this.selectedDate = null;
113 this.filterLogs();
114 }
115 }