Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 1 | import api, { getResponseCount } from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 3 | |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 4 | const getHealthStatus = (events, loadedEvents) => { |
| 5 | let status = loadedEvents ? 'OK' : ''; |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 6 | for (const event of events) { |
Glukhov Mikhail | 7c26338 | 2023-02-13 16:07:35 +0300 | [diff] [blame] | 7 | 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 Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 15 | } |
| 16 | } |
| 17 | return status; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 18 | }; |
| 19 | |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 20 | // TODO: High priority events should also check if Log |
| 21 | // is resolved when the property is available in Redfish |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 22 | const getHighPriorityEvents = (events) => |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 23 | events.filter(({ severity }) => severity === 'Critical'); |
| 24 | |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 25 | const EventLogStore = { |
| 26 | namespaced: true, |
| 27 | state: { |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 28 | allEvents: [], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 29 | loadedEvents: false, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 30 | }, |
| 31 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 32 | allEvents: (state) => state.allEvents, |
| 33 | highPriorityEvents: (state) => getHighPriorityEvents(state.allEvents), |
| 34 | healthStatus: (state) => |
| 35 | getHealthStatus(state.allEvents, state.loadedEvents), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 36 | }, |
| 37 | mutations: { |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 38 | setAllEvents: (state, allEvents) => ( |
| 39 | (state.allEvents = allEvents), (state.loadedEvents = true) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 40 | ), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 41 | }, |
| 42 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 43 | async getEventLogData({ commit }) { |
| 44 | return await api |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 45 | .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') |
| 46 | .then(({ data: { Members = [] } = {} }) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 47 | const eventLogs = Members.map((log) => { |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 48 | const { |
| 49 | Id, |
| 50 | Severity, |
| 51 | Created, |
| 52 | EntryType, |
| 53 | Message, |
| 54 | Name, |
| 55 | Modified, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 56 | Resolved, |
Dixsie Wolmers | 8b1beff | 2021-06-14 11:29:44 -0500 | [diff] [blame] | 57 | AdditionalDataURI, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 58 | } = log; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 59 | return { |
| 60 | id: Id, |
| 61 | severity: Severity, |
| 62 | date: new Date(Created), |
| 63 | type: EntryType, |
| 64 | description: Message, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 65 | name: Name, |
| 66 | modifiedDate: new Date(Modified), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 67 | uri: log['@odata.id'], |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 68 | filterByStatus: Resolved ? 'Resolved' : 'Unresolved', |
| 69 | status: Resolved, //true or false |
Dixsie Wolmers | 8b1beff | 2021-06-14 11:29:44 -0500 | [diff] [blame] | 70 | additionalDataUri: AdditionalDataURI, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 71 | }; |
| 72 | }); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 73 | commit('setAllEvents', eventLogs); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 74 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 75 | .catch((error) => { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 76 | console.log('Event Log Data:', error); |
| 77 | }); |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 78 | }, |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 79 | async deleteAllEventLogs({ dispatch }, data) { |
| 80 | return await api |
| 81 | .post( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 82 | '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog', |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 83 | ) |
| 84 | .then(() => dispatch('getEventLogData')) |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 85 | .then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length)) |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 86 | .catch((error) => { |
| 87 | console.log(error); |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 88 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 89 | i18n.tc('pageEventLogs.toast.errorDelete', data.length), |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 90 | ); |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 91 | }); |
| 92 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 93 | async deleteEventLogs({ dispatch }, uris = []) { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 94 | const promises = uris.map((uri) => |
| 95 | api.delete(uri).catch((error) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 96 | console.log(error); |
| 97 | return error; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 98 | }), |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 99 | ); |
| 100 | return await api |
| 101 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 102 | .then((response) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 103 | 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 114 | successCount, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 115 | ); |
| 116 | toastMessages.push({ type: 'success', message }); |
| 117 | } |
| 118 | |
| 119 | if (errorCount) { |
| 120 | const message = i18n.tc( |
| 121 | 'pageEventLogs.toast.errorDelete', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 122 | errorCount, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 123 | ); |
| 124 | toastMessages.push({ type: 'error', message }); |
| 125 | } |
| 126 | |
| 127 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 128 | }), |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 129 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | }, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 131 | 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 136 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 137 | ); |
| 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 151 | successCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 152 | ); |
| 153 | toastMessages.push({ type: 'success', message }); |
| 154 | } |
| 155 | if (errorCount) { |
| 156 | const message = i18n.tc( |
| 157 | 'pageEventLogs.toast.errorResolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 158 | errorCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 159 | ); |
| 160 | toastMessages.push({ type: 'error', message }); |
| 161 | } |
| 162 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 163 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 164 | ); |
| 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 171 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 172 | ); |
| 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 186 | successCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 187 | ); |
| 188 | toastMessages.push({ type: 'success', message }); |
| 189 | } |
| 190 | if (errorCount) { |
| 191 | const message = i18n.tc( |
| 192 | 'pageEventLogs.toast.errorUnresolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 193 | errorCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 194 | ); |
| 195 | toastMessages.push({ type: 'error', message }); |
| 196 | } |
| 197 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame^] | 198 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 199 | ); |
| 200 | }, |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 201 | // Single log entry |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 202 | 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 Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 211 | return i18n.tc('pageEventLogs.toast.successResolveLogs', 1); |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 212 | } else { |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 213 | return i18n.tc('pageEventLogs.toast.successUnresolveLogs', 1); |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 214 | } |
| 215 | }) |
| 216 | .catch((error) => { |
| 217 | console.log(error); |
| 218 | throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate')); |
| 219 | }); |
| 220 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 221 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | export default EventLogStore; |