blob: 2b6d5f947ea618cd6c50197f1e3ae8d4eccc4f00 [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,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053055 } = log;
Yoshie Muranakabe3af332020-05-11 08:23:04 -070056 return {
57 id: Id,
58 severity: Severity,
59 date: new Date(Created),
60 type: EntryType,
61 description: Message,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053062 name: Name,
63 modifiedDate: new Date(Modified),
Derick Montague602e98a2020-10-21 16:20:00 -050064 uri: log['@odata.id'],
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050065 filterByStatus: Resolved ? 'Resolved' : 'Unresolved',
66 status: Resolved, //true or false
Yoshie Muranakabe3af332020-05-11 08:23:04 -070067 };
68 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080069 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060070 })
Derick Montague602e98a2020-10-21 16:20:00 -050071 .catch((error) => {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060072 console.log('Event Log Data:', error);
73 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070074 },
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053075 async deleteAllEventLogs({ dispatch }, data) {
76 return await api
77 .post(
78 '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog'
79 )
80 .then(() => dispatch('getEventLogData'))
81 .then(() => i18n.tc('pageEventLogs.toast.successDelete', data))
82 .catch((error) => {
83 console.log(error);
84 throw new Error(i18n.tc('pageEventLogs.toast.errorDelete', data));
85 });
86 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070087 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050088 const promises = uris.map((uri) =>
89 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070090 console.log(error);
91 return error;
92 })
93 );
94 return await api
95 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -050096 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070097 dispatch('getEventLogData');
98 return response;
99 })
100 .then(
101 api.spread((...responses) => {
102 const { successCount, errorCount } = getResponseCount(responses);
103 const toastMessages = [];
104
105 if (successCount) {
106 const message = i18n.tc(
107 'pageEventLogs.toast.successDelete',
108 successCount
109 );
110 toastMessages.push({ type: 'success', message });
111 }
112
113 if (errorCount) {
114 const message = i18n.tc(
115 'pageEventLogs.toast.errorDelete',
116 errorCount
117 );
118 toastMessages.push({ type: 'error', message });
119 }
120
121 return toastMessages;
122 })
123 );
Derick Montague602e98a2020-10-21 16:20:00 -0500124 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500125 async resolveEventLogs({ dispatch }, logs) {
126 const promises = logs.map((log) =>
127 api.patch(log.uri, { Resolved: true }).catch((error) => {
128 console.log(error);
129 return error;
130 })
131 );
132 return await api
133 .all(promises)
134 .then((response) => {
135 dispatch('getEventLogData');
136 return response;
137 })
138 .then(
139 api.spread((...responses) => {
140 const { successCount, errorCount } = getResponseCount(responses);
141 const toastMessages = [];
142 if (successCount) {
143 const message = i18n.tc(
144 'pageEventLogs.toast.successResolveLogs',
145 successCount
146 );
147 toastMessages.push({ type: 'success', message });
148 }
149 if (errorCount) {
150 const message = i18n.tc(
151 'pageEventLogs.toast.errorResolveLogs',
152 errorCount
153 );
154 toastMessages.push({ type: 'error', message });
155 }
156 return toastMessages;
157 })
158 );
159 },
160 async unresolveEventLogs({ dispatch }, logs) {
161 const promises = logs.map((log) =>
162 api.patch(log.uri, { Resolved: false }).catch((error) => {
163 console.log(error);
164 return error;
165 })
166 );
167 return await api
168 .all(promises)
169 .then((response) => {
170 dispatch('getEventLogData');
171 return response;
172 })
173 .then(
174 api.spread((...responses) => {
175 const { successCount, errorCount } = getResponseCount(responses);
176 const toastMessages = [];
177 if (successCount) {
178 const message = i18n.tc(
179 'pageEventLogs.toast.successUnresolveLogs',
180 successCount
181 );
182 toastMessages.push({ type: 'success', message });
183 }
184 if (errorCount) {
185 const message = i18n.tc(
186 'pageEventLogs.toast.errorUnresolveLogs',
187 errorCount
188 );
189 toastMessages.push({ type: 'error', message });
190 }
191 return toastMessages;
192 })
193 );
194 },
195 async updateEventLogStatus({ dispatch }, log) {
196 const updatedEventLogStatus = log.status;
197 return await api
198 .patch(log.uri, { Resolved: updatedEventLogStatus })
199 .then(() => {
200 dispatch('getEventLogData');
201 })
202 .then(() => {
203 if (log.status) {
204 return i18n.t('pageEventLogs.toast.successResolveLog');
205 } else {
206 return i18n.t('pageEventLogs.toast.successUnresolveLog');
207 }
208 })
209 .catch((error) => {
210 console.log(error);
211 throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate'));
212 });
213 },
Derick Montague602e98a2020-10-21 16:20:00 -0500214 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600215};
216
217export default EventLogStore;