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 |
| 20 | const getHighPriorityEvents = events => |
| 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: [], |
| 27 | loadedEvents: false |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 28 | }, |
| 29 | getters: { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 30 | allEvents: state => state.allEvents, |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 31 | highPriorityEvents: state => getHighPriorityEvents(state.allEvents), |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 32 | healthStatus: state => getHealthStatus(state.allEvents, state.loadedEvents) |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 33 | }, |
| 34 | mutations: { |
Mateusz Gapski | 076ab27 | 2020-07-20 10:55:15 +0200 | [diff] [blame] | 35 | setAllEvents: (state, allEvents) => ( |
| 36 | (state.allEvents = allEvents), (state.loadedEvents = true) |
| 37 | ) |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 38 | }, |
| 39 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 40 | async getEventLogData({ commit }) { |
| 41 | return await api |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 42 | .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') |
| 43 | .then(({ data: { Members = [] } = {} }) => { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 44 | const eventLogs = Members.map(log => { |
| 45 | const { Id, Severity, Created, EntryType, Message } = log; |
| 46 | return { |
| 47 | id: Id, |
| 48 | severity: Severity, |
| 49 | date: new Date(Created), |
| 50 | type: EntryType, |
| 51 | description: Message, |
| 52 | uri: log['@odata.id'] |
| 53 | }; |
| 54 | }); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 55 | commit('setAllEvents', eventLogs); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 56 | }) |
| 57 | .catch(error => { |
| 58 | console.log('Event Log Data:', error); |
| 59 | }); |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 60 | }, |
| 61 | async deleteEventLogs({ dispatch }, uris = []) { |
| 62 | const promises = uris.map(uri => |
| 63 | api.delete(uri).catch(error => { |
| 64 | console.log(error); |
| 65 | return error; |
| 66 | }) |
| 67 | ); |
| 68 | return await api |
| 69 | .all(promises) |
| 70 | .then(response => { |
| 71 | dispatch('getEventLogData'); |
| 72 | return response; |
| 73 | }) |
| 74 | .then( |
| 75 | api.spread((...responses) => { |
| 76 | const { successCount, errorCount } = getResponseCount(responses); |
| 77 | const toastMessages = []; |
| 78 | |
| 79 | if (successCount) { |
| 80 | const message = i18n.tc( |
| 81 | 'pageEventLogs.toast.successDelete', |
| 82 | successCount |
| 83 | ); |
| 84 | toastMessages.push({ type: 'success', message }); |
| 85 | } |
| 86 | |
| 87 | if (errorCount) { |
| 88 | const message = i18n.tc( |
| 89 | 'pageEventLogs.toast.errorDelete', |
| 90 | errorCount |
| 91 | ); |
| 92 | toastMessages.push({ type: 'error', message }); |
| 93 | } |
| 94 | |
| 95 | return toastMessages; |
| 96 | }) |
| 97 | ); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | export default EventLogStore; |