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