blob: f7b2ead60ae70bfe9890abb220ab69c022497315 [file] [log] [blame]
Yoshie Muranakabe3af332020-05-11 08:23:04 -07001import api, { getResponseCount } from '@/store/api';
2import i18n from '@/i18n';
Dixsie Wolmersf65ee342020-01-22 19:47:56 -06003
Mateusz Gapski076ab272020-07-20 10:55:15 +02004const getHealthStatus = (events, loadedEvents) => {
5 let status = loadedEvents ? 'OK' : '';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -07006 for (const event of events) {
Glukhov Mikhail7c263382023-02-13 16:07:35 +03007 if (event.filterByStatus === 'Unresolved') {
8 if (event.severity === 'Warning') {
9 status = 'Warning';
10 }
11 if (event.severity === 'Critical') {
12 status = 'Critical';
13 break;
14 }
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080015 }
16 }
17 return status;
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060018};
19
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070020// TODO: High priority events should also check if Log
21// is resolved when the property is available in Redfish
Derick Montague602e98a2020-10-21 16:20:00 -050022const getHighPriorityEvents = (events) =>
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070023 events.filter(({ severity }) => severity === 'Critical');
24
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060025const EventLogStore = {
26 namespaced: true,
27 state: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020028 allEvents: [],
Derick Montague602e98a2020-10-21 16:20:00 -050029 loadedEvents: false,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060030 },
31 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050032 allEvents: (state) => state.allEvents,
33 highPriorityEvents: (state) => getHighPriorityEvents(state.allEvents),
34 healthStatus: (state) =>
35 getHealthStatus(state.allEvents, state.loadedEvents),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060036 },
37 mutations: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020038 setAllEvents: (state, allEvents) => (
39 (state.allEvents = allEvents), (state.loadedEvents = true)
Derick Montague602e98a2020-10-21 16:20:00 -050040 ),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060041 },
42 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070043 async getEventLogData({ commit }) {
44 return await api
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070045 .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
46 .then(({ data: { Members = [] } = {} }) => {
Derick Montague602e98a2020-10-21 16:20:00 -050047 const eventLogs = Members.map((log) => {
Sukanya Pandey47b047c2020-12-23 13:18:55 +053048 const {
49 Id,
50 Severity,
51 Created,
52 EntryType,
53 Message,
54 Name,
55 Modified,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050056 Resolved,
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050057 AdditionalDataURI,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053058 } = log;
Yoshie Muranakabe3af332020-05-11 08:23:04 -070059 return {
60 id: Id,
61 severity: Severity,
62 date: new Date(Created),
63 type: EntryType,
64 description: Message,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053065 name: Name,
66 modifiedDate: new Date(Modified),
Derick Montague602e98a2020-10-21 16:20:00 -050067 uri: log['@odata.id'],
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050068 filterByStatus: Resolved ? 'Resolved' : 'Unresolved',
69 status: Resolved, //true or false
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050070 additionalDataUri: AdditionalDataURI,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070071 };
72 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080073 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060074 })
Derick Montague602e98a2020-10-21 16:20:00 -050075 .catch((error) => {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060076 console.log('Event Log Data:', error);
77 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 },
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053079 async deleteAllEventLogs({ dispatch }, data) {
80 return await api
81 .post(
Ed Tanous81323992024-02-27 11:26:24 -080082 '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog',
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053083 )
84 .then(() => dispatch('getEventLogData'))
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050085 .then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length))
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053086 .catch((error) => {
87 console.log(error);
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050088 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080089 i18n.tc('pageEventLogs.toast.errorDelete', data.length),
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050090 );
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053091 });
92 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050094 const promises = uris.map((uri) =>
95 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070096 console.log(error);
97 return error;
Ed Tanous81323992024-02-27 11:26:24 -080098 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -070099 );
100 return await api
101 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -0500102 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700103 dispatch('getEventLogData');
104 return response;
105 })
106 .then(
107 api.spread((...responses) => {
108 const { successCount, errorCount } = getResponseCount(responses);
109 const toastMessages = [];
110
111 if (successCount) {
112 const message = i18n.tc(
113 'pageEventLogs.toast.successDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800114 successCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700115 );
116 toastMessages.push({ type: 'success', message });
117 }
118
119 if (errorCount) {
120 const message = i18n.tc(
121 'pageEventLogs.toast.errorDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800122 errorCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700123 );
124 toastMessages.push({ type: 'error', message });
125 }
126
127 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800128 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700129 );
Derick Montague602e98a2020-10-21 16:20:00 -0500130 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500131 async resolveEventLogs({ dispatch }, logs) {
132 const promises = logs.map((log) =>
133 api.patch(log.uri, { Resolved: true }).catch((error) => {
134 console.log(error);
135 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800136 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500137 );
138 return await api
139 .all(promises)
140 .then((response) => {
141 dispatch('getEventLogData');
142 return response;
143 })
144 .then(
145 api.spread((...responses) => {
146 const { successCount, errorCount } = getResponseCount(responses);
147 const toastMessages = [];
148 if (successCount) {
149 const message = i18n.tc(
150 'pageEventLogs.toast.successResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800151 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500152 );
153 toastMessages.push({ type: 'success', message });
154 }
155 if (errorCount) {
156 const message = i18n.tc(
157 'pageEventLogs.toast.errorResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800158 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500159 );
160 toastMessages.push({ type: 'error', message });
161 }
162 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800163 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500164 );
165 },
166 async unresolveEventLogs({ dispatch }, logs) {
167 const promises = logs.map((log) =>
168 api.patch(log.uri, { Resolved: false }).catch((error) => {
169 console.log(error);
170 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800171 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500172 );
173 return await api
174 .all(promises)
175 .then((response) => {
176 dispatch('getEventLogData');
177 return response;
178 })
179 .then(
180 api.spread((...responses) => {
181 const { successCount, errorCount } = getResponseCount(responses);
182 const toastMessages = [];
183 if (successCount) {
184 const message = i18n.tc(
185 'pageEventLogs.toast.successUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800186 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500187 );
188 toastMessages.push({ type: 'success', message });
189 }
190 if (errorCount) {
191 const message = i18n.tc(
192 'pageEventLogs.toast.errorUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800193 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500194 );
195 toastMessages.push({ type: 'error', message });
196 }
197 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800198 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500199 );
200 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500201 // Single log entry
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500202 async updateEventLogStatus({ dispatch }, log) {
203 const updatedEventLogStatus = log.status;
204 return await api
205 .patch(log.uri, { Resolved: updatedEventLogStatus })
206 .then(() => {
207 dispatch('getEventLogData');
208 })
209 .then(() => {
210 if (log.status) {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500211 return i18n.tc('pageEventLogs.toast.successResolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500212 } else {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500213 return i18n.tc('pageEventLogs.toast.successUnresolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500214 }
215 })
216 .catch((error) => {
217 console.log(error);
218 throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate'));
219 });
220 },
Derick Montague602e98a2020-10-21 16:20:00 -0500221 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600222};
223
224export default EventLogStore;