Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 3 | const getHealthStatus = events => { |
| 4 | let status = 'OK'; |
| 5 | for (const event of events) { |
| 6 | if (event.severity === 'Warning') { |
| 7 | status = 'Warning'; |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 8 | } |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 9 | if (event.severity === 'Critical') { |
| 10 | status = 'Critical'; |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 11 | break; |
| 12 | } |
| 13 | } |
| 14 | return status; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 15 | }; |
| 16 | |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 17 | // TODO: High priority events should also check if Log |
| 18 | // is resolved when the property is available in Redfish |
| 19 | const getHighPriorityEvents = events => |
| 20 | events.filter(({ severity }) => severity === 'Critical'); |
| 21 | |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 22 | const EventLogStore = { |
| 23 | namespaced: true, |
| 24 | state: { |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 25 | allEvents: [] |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 26 | }, |
| 27 | getters: { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 28 | allEvents: state => state.allEvents, |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 29 | highPriorityEvents: state => getHighPriorityEvents(state.allEvents), |
| 30 | healthStatus: state => getHealthStatus(state.allEvents) |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 31 | }, |
| 32 | mutations: { |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 33 | setAllEvents: (state, allEvents) => (state.allEvents = allEvents) |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 34 | }, |
| 35 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame] | 36 | async getEventLogData({ commit }) { |
| 37 | return await api |
Yoshie Muranaka | ce9a3ef | 2020-05-06 14:33:22 -0700 | [diff] [blame] | 38 | .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') |
| 39 | .then(({ data: { Members = [] } = {} }) => { |
| 40 | const eventLogs = Members.map( |
| 41 | ({ Id, Severity, Created, EntryType, Message }) => { |
| 42 | return { |
| 43 | id: Id, |
| 44 | severity: Severity, |
| 45 | date: new Date(Created), |
| 46 | type: EntryType, |
| 47 | description: Message |
| 48 | }; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 49 | } |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 50 | ); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 51 | commit('setAllEvents', eventLogs); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 52 | }) |
| 53 | .catch(error => { |
| 54 | console.log('Event Log Data:', error); |
| 55 | }); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | export default EventLogStore; |