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) { |
| 7 | if (event.severity === 'Warning') { |
| 8 | status = 'Warning'; |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 9 | } |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 10 | if (event.severity === 'Critical') { |
| 11 | status = 'Critical'; |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 12 | break; |
| 13 | } |
| 14 | } |
| 15 | return status; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 16 | }; |
| 17 | |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 18 | // TODO: High priority events should also check if Log |
| 19 | // is resolved when the property is available in Redfish |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 20 | const getHighPriorityEvents = (events) => |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 21 | events.filter(({ severity }) => severity === 'Critical'); |
| 22 | |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 23 | const EventLogStore = { |
| 24 | namespaced: true, |
| 25 | state: { |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 26 | allEvents: [], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 27 | loadedEvents: false, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 28 | }, |
| 29 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 30 | allEvents: (state) => state.allEvents, |
| 31 | highPriorityEvents: (state) => getHighPriorityEvents(state.allEvents), |
| 32 | healthStatus: (state) => |
| 33 | getHealthStatus(state.allEvents, state.loadedEvents), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 34 | }, |
| 35 | mutations: { |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 36 | setAllEvents: (state, allEvents) => ( |
| 37 | (state.allEvents = allEvents), (state.loadedEvents = true) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 38 | ), |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 39 | }, |
| 40 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 41 | async getEventLogData({ commit }) { |
| 42 | return await api |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 43 | .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') |
| 44 | .then(({ data: { Members = [] } = {} }) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 45 | const eventLogs = Members.map((log) => { |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 46 | const { |
| 47 | Id, |
| 48 | Severity, |
| 49 | Created, |
| 50 | EntryType, |
| 51 | Message, |
| 52 | Name, |
| 53 | Modified, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame^] | 54 | Resolved, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 55 | } = log; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 56 | return { |
| 57 | id: Id, |
| 58 | severity: Severity, |
| 59 | date: new Date(Created), |
| 60 | type: EntryType, |
| 61 | description: Message, |
Sukanya Pandey | 47b047c | 2020-12-23 13:18:55 +0530 | [diff] [blame] | 62 | name: Name, |
| 63 | modifiedDate: new Date(Modified), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 64 | uri: log['@odata.id'], |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame^] | 65 | filterByStatus: Resolved ? 'Resolved' : 'Unresolved', |
| 66 | status: Resolved, //true or false |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 67 | }; |
| 68 | }); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 69 | commit('setAllEvents', eventLogs); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 70 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 71 | .catch((error) => { |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 72 | console.log('Event Log Data:', error); |
| 73 | }); |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 74 | }, |
Sukanya Pandey | 2f6d552 | 2020-10-28 10:38:00 +0530 | [diff] [blame] | 75 | 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 Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 87 | async deleteEventLogs({ dispatch }, uris = []) { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 88 | const promises = uris.map((uri) => |
| 89 | api.delete(uri).catch((error) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 90 | console.log(error); |
| 91 | return error; |
| 92 | }) |
| 93 | ); |
| 94 | return await api |
| 95 | .all(promises) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 96 | .then((response) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 97 | 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 124 | }, |
Dixsie Wolmers | 27d68af | 2021-05-02 18:20:27 -0500 | [diff] [blame^] | 125 | 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 214 | }, |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | export default EventLogStore; |