blob: f302dffbe403ac089825b6baf8efbd4f85e28c2f [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
Sean Zhang8841b7d2024-06-15 08:42:41 +030045 .get(
46 `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Entries`,
47 )
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070048 .then(({ data: { Members = [] } = {} }) => {
Derick Montague602e98a2020-10-21 16:20:00 -050049 const eventLogs = Members.map((log) => {
Sukanya Pandey47b047c2020-12-23 13:18:55 +053050 const {
51 Id,
52 Severity,
53 Created,
54 EntryType,
55 Message,
56 Name,
57 Modified,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050058 Resolved,
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050059 AdditionalDataURI,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053060 } = log;
Yoshie Muranakabe3af332020-05-11 08:23:04 -070061 return {
62 id: Id,
63 severity: Severity,
64 date: new Date(Created),
65 type: EntryType,
66 description: Message,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053067 name: Name,
68 modifiedDate: new Date(Modified),
Derick Montague602e98a2020-10-21 16:20:00 -050069 uri: log['@odata.id'],
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050070 filterByStatus: Resolved ? 'Resolved' : 'Unresolved',
71 status: Resolved, //true or false
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050072 additionalDataUri: AdditionalDataURI,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070073 };
74 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080075 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060076 })
Derick Montague602e98a2020-10-21 16:20:00 -050077 .catch((error) => {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060078 console.log('Event Log Data:', error);
79 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070080 },
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053081 async deleteAllEventLogs({ dispatch }, data) {
82 return await api
83 .post(
Sean Zhang8841b7d2024-06-15 08:42:41 +030084 `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Actions/LogService.ClearLog`,
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053085 )
86 .then(() => dispatch('getEventLogData'))
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050087 .then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length))
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053088 .catch((error) => {
89 console.log(error);
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050090 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080091 i18n.tc('pageEventLogs.toast.errorDelete', data.length),
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050092 );
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053093 });
94 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070095 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050096 const promises = uris.map((uri) =>
97 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070098 console.log(error);
99 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800100 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700101 );
102 return await api
103 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -0500104 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700105 dispatch('getEventLogData');
106 return response;
107 })
108 .then(
109 api.spread((...responses) => {
110 const { successCount, errorCount } = getResponseCount(responses);
111 const toastMessages = [];
112
113 if (successCount) {
114 const message = i18n.tc(
115 'pageEventLogs.toast.successDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800116 successCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700117 );
118 toastMessages.push({ type: 'success', message });
119 }
120
121 if (errorCount) {
122 const message = i18n.tc(
123 'pageEventLogs.toast.errorDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800124 errorCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700125 );
126 toastMessages.push({ type: 'error', message });
127 }
128
129 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800130 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700131 );
Derick Montague602e98a2020-10-21 16:20:00 -0500132 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500133 async resolveEventLogs({ dispatch }, logs) {
134 const promises = logs.map((log) =>
135 api.patch(log.uri, { Resolved: true }).catch((error) => {
136 console.log(error);
137 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800138 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500139 );
140 return await api
141 .all(promises)
142 .then((response) => {
143 dispatch('getEventLogData');
144 return response;
145 })
146 .then(
147 api.spread((...responses) => {
148 const { successCount, errorCount } = getResponseCount(responses);
149 const toastMessages = [];
150 if (successCount) {
151 const message = i18n.tc(
152 'pageEventLogs.toast.successResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800153 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500154 );
155 toastMessages.push({ type: 'success', message });
156 }
157 if (errorCount) {
158 const message = i18n.tc(
159 'pageEventLogs.toast.errorResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800160 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500161 );
162 toastMessages.push({ type: 'error', message });
163 }
164 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800165 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500166 );
167 },
168 async unresolveEventLogs({ dispatch }, logs) {
169 const promises = logs.map((log) =>
170 api.patch(log.uri, { Resolved: false }).catch((error) => {
171 console.log(error);
172 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800173 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500174 );
175 return await api
176 .all(promises)
177 .then((response) => {
178 dispatch('getEventLogData');
179 return response;
180 })
181 .then(
182 api.spread((...responses) => {
183 const { successCount, errorCount } = getResponseCount(responses);
184 const toastMessages = [];
185 if (successCount) {
186 const message = i18n.tc(
187 'pageEventLogs.toast.successUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800188 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500189 );
190 toastMessages.push({ type: 'success', message });
191 }
192 if (errorCount) {
193 const message = i18n.tc(
194 'pageEventLogs.toast.errorUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800195 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500196 );
197 toastMessages.push({ type: 'error', message });
198 }
199 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800200 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500201 );
202 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500203 // Single log entry
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500204 async updateEventLogStatus({ dispatch }, log) {
205 const updatedEventLogStatus = log.status;
206 return await api
207 .patch(log.uri, { Resolved: updatedEventLogStatus })
208 .then(() => {
209 dispatch('getEventLogData');
210 })
211 .then(() => {
212 if (log.status) {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500213 return i18n.tc('pageEventLogs.toast.successResolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500214 } else {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500215 return i18n.tc('pageEventLogs.toast.successUnresolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500216 }
217 })
218 .catch((error) => {
219 console.log(error);
220 throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate'));
221 });
222 },
Sean Zhang582e9542024-07-05 12:48:45 +0300223 async downloadEntry(_, uri) {
224 return await api
225 .get(uri)
226 .then((response) => {
227 const blob = new Blob([response.data], {
228 type: response.headers['content-type'],
229 });
230 return blob;
231 })
232 .catch((error) => {
233 console.log(error);
234 throw new Error(
235 i18n.t('pageEventLogs.toast.errorDownloadEventEntry'),
236 );
237 });
238 },
Derick Montague602e98a2020-10-21 16:20:00 -0500239 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600240};
241
242export default EventLogStore;