blob: 3de31aecaa840eb04b762fc2c57e28c3b794b8be [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'))
Surya Vde23ea22024-07-11 15:19:46 +053087 .then(() =>
88 i18n.global.t('pageEventLogs.toast.successDelete', data.length),
89 )
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053090 .catch((error) => {
91 console.log(error);
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050092 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053093 i18n.global.t('pageEventLogs.toast.errorDelete', data.length),
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050094 );
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053095 });
96 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070097 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050098 const promises = uris.map((uri) =>
99 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700100 console.log(error);
101 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800102 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700103 );
104 return await api
105 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -0500106 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700107 dispatch('getEventLogData');
108 return response;
109 })
110 .then(
111 api.spread((...responses) => {
112 const { successCount, errorCount } = getResponseCount(responses);
113 const toastMessages = [];
114
115 if (successCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530116 const message = i18n.global.t(
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700117 'pageEventLogs.toast.successDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800118 successCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700119 );
120 toastMessages.push({ type: 'success', message });
121 }
122
123 if (errorCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530124 const message = i18n.global.t(
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700125 'pageEventLogs.toast.errorDelete',
Ed Tanous81323992024-02-27 11:26:24 -0800126 errorCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700127 );
128 toastMessages.push({ type: 'error', message });
129 }
130
131 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800132 }),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700133 );
Derick Montague602e98a2020-10-21 16:20:00 -0500134 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500135 async resolveEventLogs({ dispatch }, logs) {
136 const promises = logs.map((log) =>
137 api.patch(log.uri, { Resolved: true }).catch((error) => {
138 console.log(error);
139 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800140 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500141 );
142 return await api
143 .all(promises)
144 .then((response) => {
145 dispatch('getEventLogData');
146 return response;
147 })
148 .then(
149 api.spread((...responses) => {
150 const { successCount, errorCount } = getResponseCount(responses);
151 const toastMessages = [];
152 if (successCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530153 const message = i18n.global.t(
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500154 'pageEventLogs.toast.successResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800155 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500156 );
157 toastMessages.push({ type: 'success', message });
158 }
159 if (errorCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530160 const message = i18n.global.t(
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500161 'pageEventLogs.toast.errorResolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800162 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500163 );
164 toastMessages.push({ type: 'error', message });
165 }
166 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800167 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500168 );
169 },
170 async unresolveEventLogs({ dispatch }, logs) {
171 const promises = logs.map((log) =>
172 api.patch(log.uri, { Resolved: false }).catch((error) => {
173 console.log(error);
174 return error;
Ed Tanous81323992024-02-27 11:26:24 -0800175 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500176 );
177 return await api
178 .all(promises)
179 .then((response) => {
180 dispatch('getEventLogData');
181 return response;
182 })
183 .then(
184 api.spread((...responses) => {
185 const { successCount, errorCount } = getResponseCount(responses);
186 const toastMessages = [];
187 if (successCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530188 const message = i18n.global.t(
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500189 'pageEventLogs.toast.successUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800190 successCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500191 );
192 toastMessages.push({ type: 'success', message });
193 }
194 if (errorCount) {
Surya Vde23ea22024-07-11 15:19:46 +0530195 const message = i18n.global.t(
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500196 'pageEventLogs.toast.errorUnresolveLogs',
Ed Tanous81323992024-02-27 11:26:24 -0800197 errorCount,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500198 );
199 toastMessages.push({ type: 'error', message });
200 }
201 return toastMessages;
Ed Tanous81323992024-02-27 11:26:24 -0800202 }),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500203 );
204 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500205 // Single log entry
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500206 async updateEventLogStatus({ dispatch }, log) {
207 const updatedEventLogStatus = log.status;
208 return await api
209 .patch(log.uri, { Resolved: updatedEventLogStatus })
210 .then(() => {
211 dispatch('getEventLogData');
212 })
213 .then(() => {
214 if (log.status) {
Surya Vde23ea22024-07-11 15:19:46 +0530215 return i18n.global.t('pageEventLogs.toast.successResolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500216 } else {
Surya Vde23ea22024-07-11 15:19:46 +0530217 return i18n.global.t('pageEventLogs.toast.successUnresolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500218 }
219 })
220 .catch((error) => {
221 console.log(error);
Surya Vde23ea22024-07-11 15:19:46 +0530222 throw new Error(
223 i18n.global.t('pageEventLogs.toast.errorLogStatusUpdate'),
224 );
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500225 });
226 },
Sean Zhang582e9542024-07-05 12:48:45 +0300227 async downloadEntry(_, uri) {
228 return await api
Sean Zhang51feb352024-09-27 11:39:50 +0300229 .get(uri, {
230 headers: {
231 Accept: 'application/octet-stream',
232 },
233 })
Sean Zhang582e9542024-07-05 12:48:45 +0300234 .then((response) => {
235 const blob = new Blob([response.data], {
236 type: response.headers['content-type'],
237 });
238 return blob;
239 })
240 .catch((error) => {
241 console.log(error);
242 throw new Error(
243 i18n.t('pageEventLogs.toast.errorDownloadEventEntry'),
244 );
245 });
246 },
Derick Montague602e98a2020-10-21 16:20:00 -0500247 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600248};
249
250export default EventLogStore;