blob: 418e45581c0bb5aa867da914da00fa2cc0aed22e [file] [log] [blame]
Dixsie Wolmersf65ee342020-01-22 19:47:56 -06001import api from '../../api';
2
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -08003const EVENT_SEVERITY = {
4 emergency: 'xyz.openbmc_project.Logging.Entry.Level.Emergency',
5 alert: 'xyz.openbmc_project.Logging.Entry.Level.Alert',
6 critical: 'xyz.openbmc_project.Logging.Entry.Level.Critical',
7 error: 'xyz.openbmc_project.Logging.Entry.Level.Error',
8 warning: 'xyz.openbmc_project.Logging.Entry.Level.Warning',
9 notice: 'xyz.openbmc_project.Logging.Entry.Level.Notice',
10 informational: 'xyz.openbmc_project.Logging.Entry.Level.Informational',
11 debug: 'xyz.openbmc_project.Logging.Entry.Level.Debug'
12};
13
14const priorityMapper = severity => {
15 switch (severity) {
16 case EVENT_SEVERITY.emergency:
17 case EVENT_SEVERITY.alert:
18 case EVENT_SEVERITY.critical:
19 case EVENT_SEVERITY.error:
20 return 'high';
21 case EVENT_SEVERITY.warning:
22 return 'medium';
23 case EVENT_SEVERITY.notice:
24 case EVENT_SEVERITY.debug:
25 case EVENT_SEVERITY.informational:
26 return 'low';
27 default:
28 return '';
29 }
30};
31
32const getHealthStatus = allEvents => {
33 let status = 'good';
34 for (const event of allEvents) {
35 if (!event.Resolved && event.priority === 'medium') {
36 status = 'warning';
37 }
38 if (!event.Resolved && event.priority === 'high') {
39 status = 'critical';
40 break;
41 }
42 }
43 return status;
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060044};
45
46const EventLogStore = {
47 namespaced: true,
48 state: {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080049 allEvents: [],
50 highPriorityEvents: [],
51 healthStatus: null
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060052 },
53 getters: {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080054 allEvents: state => state.allEvents,
55 highPriorityEvents: state => state.highPriorityEvents,
56 healthStatus: state => state.healthStatus
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060057 },
58 mutations: {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080059 setAllEvents: (state, allEvents) => (state.allEvents = allEvents),
60 setHighPriorityEvents: (state, highPriorityEvents) =>
61 (state.highPriorityEvents = highPriorityEvents),
62 setHealthStatus: (state, status) => (state.healthStatus = status)
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060063 },
64 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070065 async getEventLogData({ commit }) {
66 return await api
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060067 .get('/xyz/openbmc_project/logging/enumerate')
68 .then(response => {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080069 const responseData = response.data.data;
70 const eventLogs = [];
Dixsie Wolmers97f41872020-02-23 15:56:16 -060071
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080072 for (const key in responseData) {
73 const event = responseData[key];
74 const { Id } = event;
75 if (responseData.hasOwnProperty(key) && Id) {
76 const { EventID, Description, Timestamp, Severity } = event;
77 eventLogs.push({
78 logId: Id,
79 priority: priorityMapper(Severity),
Dixsie Wolmers97f41872020-02-23 15:56:16 -060080 timestamp: new Date(Timestamp),
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080081 eventID: EventID,
82 description: Description,
83 ...event
84 });
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060085 }
86 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080087
88 const healthStatus = getHealthStatus(eventLogs);
89 const highPriorityEvents = eventLogs.filter(
90 ({ priority, Resolved }) => priority === 'high' && !Resolved
91 );
92
93 commit('setAllEvents', eventLogs);
94 commit('setHighPriorityEvents', highPriorityEvents);
95 commit('setHealthStatus', healthStatus);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060096 })
97 .catch(error => {
98 console.log('Event Log Data:', error);
99 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -0800100 },
101 checkHealth({ commit, getters }, interfaces) {
102 if (getters['healthStatus'] === 'critical') return;
103 for (const key in interfaces) {
104 const event = interfaces[key];
105 const eventPriority = priorityMapper(event.Severity);
106 const isEventResolved = event.Resolved;
107 if (!isEventResolved) {
108 if (eventPriority === 'high') {
109 commit('setHealthStatus', 'critical');
110 break;
111 }
112 if (eventPriority === 'medium') commit('setHealthStatus', 'warning');
113 }
114 }
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600115 }
116 }
117};
118
119export default EventLogStore;