blob: c9bd82fd3a123e34b932c19c8b46a8b652263495 [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) {
7 if (event.severity === 'Warning') {
8 status = 'Warning';
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -08009 }
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070010 if (event.severity === 'Critical') {
11 status = 'Critical';
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080012 break;
13 }
14 }
15 return status;
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060016};
17
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070018// TODO: High priority events should also check if Log
19// is resolved when the property is available in Redfish
Derick Montague602e98a2020-10-21 16:20:00 -050020const getHighPriorityEvents = (events) =>
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070021 events.filter(({ severity }) => severity === 'Critical');
22
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060023const EventLogStore = {
24 namespaced: true,
25 state: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020026 allEvents: [],
Derick Montague602e98a2020-10-21 16:20:00 -050027 loadedEvents: false,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060028 },
29 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050030 allEvents: (state) => state.allEvents,
31 highPriorityEvents: (state) => getHighPriorityEvents(state.allEvents),
32 healthStatus: (state) =>
33 getHealthStatus(state.allEvents, state.loadedEvents),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060034 },
35 mutations: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020036 setAllEvents: (state, allEvents) => (
37 (state.allEvents = allEvents), (state.loadedEvents = true)
Derick Montague602e98a2020-10-21 16:20:00 -050038 ),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060039 },
40 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070041 async getEventLogData({ commit }) {
42 return await api
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070043 .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
44 .then(({ data: { Members = [] } = {} }) => {
Derick Montague602e98a2020-10-21 16:20:00 -050045 const eventLogs = Members.map((log) => {
Sukanya Pandey47b047c2020-12-23 13:18:55 +053046 const {
47 Id,
48 Severity,
49 Created,
50 EntryType,
51 Message,
52 Name,
53 Modified,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050054 Resolved,
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050055 AdditionalDataURI,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053056 } = log;
Yoshie Muranakabe3af332020-05-11 08:23:04 -070057 return {
58 id: Id,
59 severity: Severity,
60 date: new Date(Created),
61 type: EntryType,
62 description: Message,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053063 name: Name,
64 modifiedDate: new Date(Modified),
Derick Montague602e98a2020-10-21 16:20:00 -050065 uri: log['@odata.id'],
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050066 filterByStatus: Resolved ? 'Resolved' : 'Unresolved',
67 status: Resolved, //true or false
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -050068 additionalDataUri: AdditionalDataURI,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070069 };
70 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080071 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060072 })
Derick Montague602e98a2020-10-21 16:20:00 -050073 .catch((error) => {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060074 console.log('Event Log Data:', error);
75 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070076 },
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053077 async deleteAllEventLogs({ dispatch }, data) {
78 return await api
79 .post(
80 '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog'
81 )
82 .then(() => dispatch('getEventLogData'))
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050083 .then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length))
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053084 .catch((error) => {
85 console.log(error);
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050086 throw new Error(
87 i18n.tc('pageEventLogs.toast.errorDelete', data.length)
88 );
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053089 });
90 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070091 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050092 const promises = uris.map((uri) =>
93 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070094 console.log(error);
95 return error;
96 })
97 );
98 return await api
99 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -0500100 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700101 dispatch('getEventLogData');
102 return response;
103 })
104 .then(
105 api.spread((...responses) => {
106 const { successCount, errorCount } = getResponseCount(responses);
107 const toastMessages = [];
108
109 if (successCount) {
110 const message = i18n.tc(
111 'pageEventLogs.toast.successDelete',
112 successCount
113 );
114 toastMessages.push({ type: 'success', message });
115 }
116
117 if (errorCount) {
118 const message = i18n.tc(
119 'pageEventLogs.toast.errorDelete',
120 errorCount
121 );
122 toastMessages.push({ type: 'error', message });
123 }
124
125 return toastMessages;
126 })
127 );
Derick Montague602e98a2020-10-21 16:20:00 -0500128 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500129 async resolveEventLogs({ dispatch }, logs) {
130 const promises = logs.map((log) =>
131 api.patch(log.uri, { Resolved: true }).catch((error) => {
132 console.log(error);
133 return error;
134 })
135 );
136 return await api
137 .all(promises)
138 .then((response) => {
139 dispatch('getEventLogData');
140 return response;
141 })
142 .then(
143 api.spread((...responses) => {
144 const { successCount, errorCount } = getResponseCount(responses);
145 const toastMessages = [];
146 if (successCount) {
147 const message = i18n.tc(
148 'pageEventLogs.toast.successResolveLogs',
149 successCount
150 );
151 toastMessages.push({ type: 'success', message });
152 }
153 if (errorCount) {
154 const message = i18n.tc(
155 'pageEventLogs.toast.errorResolveLogs',
156 errorCount
157 );
158 toastMessages.push({ type: 'error', message });
159 }
160 return toastMessages;
161 })
162 );
163 },
164 async unresolveEventLogs({ dispatch }, logs) {
165 const promises = logs.map((log) =>
166 api.patch(log.uri, { Resolved: false }).catch((error) => {
167 console.log(error);
168 return error;
169 })
170 );
171 return await api
172 .all(promises)
173 .then((response) => {
174 dispatch('getEventLogData');
175 return response;
176 })
177 .then(
178 api.spread((...responses) => {
179 const { successCount, errorCount } = getResponseCount(responses);
180 const toastMessages = [];
181 if (successCount) {
182 const message = i18n.tc(
183 'pageEventLogs.toast.successUnresolveLogs',
184 successCount
185 );
186 toastMessages.push({ type: 'success', message });
187 }
188 if (errorCount) {
189 const message = i18n.tc(
190 'pageEventLogs.toast.errorUnresolveLogs',
191 errorCount
192 );
193 toastMessages.push({ type: 'error', message });
194 }
195 return toastMessages;
196 })
197 );
198 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500199 // Single log entry
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500200 async updateEventLogStatus({ dispatch }, log) {
201 const updatedEventLogStatus = log.status;
202 return await api
203 .patch(log.uri, { Resolved: updatedEventLogStatus })
204 .then(() => {
205 dispatch('getEventLogData');
206 })
207 .then(() => {
208 if (log.status) {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500209 return i18n.tc('pageEventLogs.toast.successResolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500210 } else {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500211 return i18n.tc('pageEventLogs.toast.successUnresolveLogs', 1);
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500212 }
213 })
214 .catch((error) => {
215 console.log(error);
216 throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate'));
217 });
218 },
Derick Montague602e98a2020-10-21 16:20:00 -0500219 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600220};
221
222export default EventLogStore;