1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import api from '../../api';
const EVENT_SEVERITY = {
emergency: 'xyz.openbmc_project.Logging.Entry.Level.Emergency',
alert: 'xyz.openbmc_project.Logging.Entry.Level.Alert',
critical: 'xyz.openbmc_project.Logging.Entry.Level.Critical',
error: 'xyz.openbmc_project.Logging.Entry.Level.Error',
warning: 'xyz.openbmc_project.Logging.Entry.Level.Warning',
notice: 'xyz.openbmc_project.Logging.Entry.Level.Notice',
informational: 'xyz.openbmc_project.Logging.Entry.Level.Informational',
debug: 'xyz.openbmc_project.Logging.Entry.Level.Debug'
};
const priorityMapper = severity => {
switch (severity) {
case EVENT_SEVERITY.emergency:
case EVENT_SEVERITY.alert:
case EVENT_SEVERITY.critical:
case EVENT_SEVERITY.error:
return 'high';
case EVENT_SEVERITY.warning:
return 'medium';
case EVENT_SEVERITY.notice:
case EVENT_SEVERITY.debug:
case EVENT_SEVERITY.informational:
return 'low';
default:
return '';
}
};
const getHealthStatus = allEvents => {
let status = 'good';
for (const event of allEvents) {
if (!event.Resolved && event.priority === 'medium') {
status = 'warning';
}
if (!event.Resolved && event.priority === 'high') {
status = 'critical';
break;
}
}
return status;
};
const EventLogStore = {
namespaced: true,
state: {
allEvents: [],
highPriorityEvents: [],
healthStatus: null
},
getters: {
allEvents: state => state.allEvents,
highPriorityEvents: state => state.highPriorityEvents,
healthStatus: state => state.healthStatus
},
mutations: {
setAllEvents: (state, allEvents) => (state.allEvents = allEvents),
setHighPriorityEvents: (state, highPriorityEvents) =>
(state.highPriorityEvents = highPriorityEvents),
setHealthStatus: (state, status) => (state.healthStatus = status)
},
actions: {
getEventLogData({ commit }) {
api
.get('/xyz/openbmc_project/logging/enumerate')
.then(response => {
const responseData = response.data.data;
const eventLogs = [];
for (const key in responseData) {
const event = responseData[key];
const { Id } = event;
if (responseData.hasOwnProperty(key) && Id) {
const { EventID, Description, Timestamp, Severity } = event;
eventLogs.push({
logId: Id,
priority: priorityMapper(Severity),
timestamp: Timestamp,
eventID: EventID,
description: Description,
...event
});
}
}
const healthStatus = getHealthStatus(eventLogs);
const highPriorityEvents = eventLogs.filter(
({ priority, Resolved }) => priority === 'high' && !Resolved
);
commit('setAllEvents', eventLogs);
commit('setHighPriorityEvents', highPriorityEvents);
commit('setHealthStatus', healthStatus);
})
.catch(error => {
console.log('Event Log Data:', error);
});
},
checkHealth({ commit, getters }, interfaces) {
if (getters['healthStatus'] === 'critical') return;
for (const key in interfaces) {
const event = interfaces[key];
const eventPriority = priorityMapper(event.Severity);
const isEventResolved = event.Resolved;
if (!isEventResolved) {
if (eventPriority === 'high') {
commit('setHealthStatus', 'critical');
break;
}
if (eventPriority === 'medium') commit('setHealthStatus', 'warning');
}
}
}
}
};
export default EventLogStore;
|