blob: 3f32ab16768866cfe111e7375d04b373be5e0bea [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: {
65 getEventLogData({ commit }) {
66 api
67 .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 = [];
71 for (const key in responseData) {
72 const event = responseData[key];
73 const { Id } = event;
74 if (responseData.hasOwnProperty(key) && Id) {
75 const { EventID, Description, Timestamp, Severity } = event;
76 eventLogs.push({
77 logId: Id,
78 priority: priorityMapper(Severity),
79 timestamp: Timestamp,
80 eventID: EventID,
81 description: Description,
82 ...event
83 });
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060084 }
85 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080086
87 const healthStatus = getHealthStatus(eventLogs);
88 const highPriorityEvents = eventLogs.filter(
89 ({ priority, Resolved }) => priority === 'high' && !Resolved
90 );
91
92 commit('setAllEvents', eventLogs);
93 commit('setHighPriorityEvents', highPriorityEvents);
94 commit('setHealthStatus', healthStatus);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060095 })
96 .catch(error => {
97 console.log('Event Log Data:', error);
98 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080099 },
100 checkHealth({ commit, getters }, interfaces) {
101 if (getters['healthStatus'] === 'critical') return;
102 for (const key in interfaces) {
103 const event = interfaces[key];
104 const eventPriority = priorityMapper(event.Severity);
105 const isEventResolved = event.Resolved;
106 if (!isEventResolved) {
107 if (eventPriority === 'high') {
108 commit('setHealthStatus', 'critical');
109 break;
110 }
111 if (eventPriority === 'medium') commit('setHealthStatus', 'warning');
112 }
113 }
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600114 }
115 }
116};
117
118export default EventLogStore;