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 |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 45 | .get( |
| 46 | `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Entries`, |
| 47 | ) |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 48 | .then(({ data: { Members = [] } = {} }) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 49 | const eventLogs = Members.map((log) => { |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 50 | const { |
| 51 | Id, |
| 52 | Severity, |
| 53 | Created, |
| 54 | EntryType, |
| 55 | Message, |
| 56 | Name, |
| 57 | Modified, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 58 | Resolved, |
Dixsie Wolmers | 8b1beff | 2021-06-14 11:29:44 -0500 | [diff] [blame] | 59 | AdditionalDataURI, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 60 | } = log; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 61 | return { |
| 62 | id: Id, |
| 63 | severity: Severity, |
| 64 | date: new Date(Created), |
| 65 | type: EntryType, |
| 66 | description: Message, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 67 | name: Name, |
| 68 | modifiedDate: new Date(Modified), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | uri: log['@odata.id'], |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 70 | filterByStatus: Resolved ? 'Resolved' : 'Unresolved', |
| 71 | status: Resolved, //true or false |
Dixsie Wolmers | 8b1beff | 2021-06-14 11:29:44 -0500 | [diff] [blame] | 72 | additionalDataUri: AdditionalDataURI, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 73 | }; |
| 74 | }); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 75 | commit('setAllEvents', eventLogs); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 76 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | .catch((error) => { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 78 | console.log('Event Log Data:', error); |
| 79 | }); |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 80 | }, |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 81 | async deleteAllEventLogs({ dispatch }, data) { |
| 82 | return await api |
| 83 | .post( |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 84 | `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Actions/LogService.ClearLog`, |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 85 | ) |
| 86 | .then(() => dispatch('getEventLogData')) |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 87 | .then(() => |
| 88 | i18n.global.t('pageEventLogs.toast.successDelete', data.length), |
| 89 | ) |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 90 | .catch((error) => { |
| 91 | console.log(error); |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 92 | throw new Error( |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 93 | i18n.global.t('pageEventLogs.toast.errorDelete', data.length), |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 94 | ); |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 95 | }); |
| 96 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 97 | async deleteEventLogs({ dispatch }, uris = []) { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 98 | const promises = uris.map((uri) => |
| 99 | api.delete(uri).catch((error) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 100 | console.log(error); |
| 101 | return error; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 102 | }), |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 103 | ); |
| 104 | return await api |
| 105 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 106 | .then((response) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 107 | 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 V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 116 | const message = i18n.global.t( |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 117 | 'pageEventLogs.toast.successDelete', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 118 | successCount, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 119 | ); |
| 120 | toastMessages.push({ type: 'success', message }); |
| 121 | } |
| 122 | |
| 123 | if (errorCount) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 124 | const message = i18n.global.t( |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 125 | 'pageEventLogs.toast.errorDelete', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 126 | errorCount, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 127 | ); |
| 128 | toastMessages.push({ type: 'error', message }); |
| 129 | } |
| 130 | |
| 131 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 132 | }), |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 133 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 134 | }, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 135 | 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 140 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 141 | ); |
| 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 V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 153 | const message = i18n.global.t( |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 154 | 'pageEventLogs.toast.successResolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 155 | successCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 156 | ); |
| 157 | toastMessages.push({ type: 'success', message }); |
| 158 | } |
| 159 | if (errorCount) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 160 | const message = i18n.global.t( |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 161 | 'pageEventLogs.toast.errorResolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 162 | errorCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 163 | ); |
| 164 | toastMessages.push({ type: 'error', message }); |
| 165 | } |
| 166 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 167 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 168 | ); |
| 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 Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 175 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 176 | ); |
| 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 V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 188 | const message = i18n.global.t( |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 189 | 'pageEventLogs.toast.successUnresolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 190 | successCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 191 | ); |
| 192 | toastMessages.push({ type: 'success', message }); |
| 193 | } |
| 194 | if (errorCount) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 195 | const message = i18n.global.t( |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 196 | 'pageEventLogs.toast.errorUnresolveLogs', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 197 | errorCount, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 198 | ); |
| 199 | toastMessages.push({ type: 'error', message }); |
| 200 | } |
| 201 | return toastMessages; |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 202 | }), |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 203 | ); |
| 204 | }, |
Dixsie Wolmers | 7e2ba54 | 2021-06-03 07:38:12 -0500 | [diff] [blame] | 205 | // Single log entry |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 206 | 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 V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 215 | return i18n.global.t('pageEventLogs.toast.successResolveLogs', 1); |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 216 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 217 | return i18n.global.t('pageEventLogs.toast.successUnresolveLogs', 1); |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 218 | } |
| 219 | }) |
| 220 | .catch((error) => { |
| 221 | console.log(error); |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 222 | throw new Error( |
| 223 | i18n.global.t('pageEventLogs.toast.errorLogStatusUpdate'), |
| 224 | ); |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame] | 225 | }); |
| 226 | }, |
Sean Zhang | 582e954 | 2024-07-05 12:48:45 +0300 | [diff] [blame] | 227 | async downloadEntry(_, uri) { |
| 228 | return await api |
Sean Zhang | 51feb35 | 2024-09-27 11:39:50 +0300 | [diff] [blame] | 229 | .get(uri, { |
| 230 | headers: { |
| 231 | Accept: 'application/octet-stream', |
| 232 | }, |
| 233 | }) |
Sean Zhang | 582e954 | 2024-07-05 12:48:45 +0300 | [diff] [blame] | 234 | .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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 247 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | export default EventLogStore; |