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