Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 3 | const EVENT_SEVERITY = { |
| 4 | emergency: 'xyz.openbmc_project.Logging.Entry.Level.Emergency', |
| 5 | alert: 'xyz.openbmc_project.Logging.Entry.Level.Alert', |
| 6 | critical: 'xyz.openbmc_project.Logging.Entry.Level.Critical', |
| 7 | error: 'xyz.openbmc_project.Logging.Entry.Level.Error', |
| 8 | warning: 'xyz.openbmc_project.Logging.Entry.Level.Warning', |
| 9 | notice: 'xyz.openbmc_project.Logging.Entry.Level.Notice', |
| 10 | informational: 'xyz.openbmc_project.Logging.Entry.Level.Informational', |
| 11 | debug: 'xyz.openbmc_project.Logging.Entry.Level.Debug' |
| 12 | }; |
| 13 | |
| 14 | const priorityMapper = severity => { |
| 15 | switch (severity) { |
| 16 | case EVENT_SEVERITY.emergency: |
| 17 | case EVENT_SEVERITY.alert: |
| 18 | case EVENT_SEVERITY.critical: |
| 19 | case EVENT_SEVERITY.error: |
| 20 | return 'high'; |
| 21 | case EVENT_SEVERITY.warning: |
| 22 | return 'medium'; |
| 23 | case EVENT_SEVERITY.notice: |
| 24 | case EVENT_SEVERITY.debug: |
| 25 | case EVENT_SEVERITY.informational: |
| 26 | return 'low'; |
| 27 | default: |
| 28 | return ''; |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | const getHealthStatus = allEvents => { |
| 33 | let status = 'good'; |
| 34 | for (const event of allEvents) { |
| 35 | if (!event.Resolved && event.priority === 'medium') { |
| 36 | status = 'warning'; |
| 37 | } |
| 38 | if (!event.Resolved && event.priority === 'high') { |
| 39 | status = 'critical'; |
| 40 | break; |
| 41 | } |
| 42 | } |
| 43 | return status; |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | const EventLogStore = { |
| 47 | namespaced: true, |
| 48 | state: { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 49 | allEvents: [], |
| 50 | highPriorityEvents: [], |
| 51 | healthStatus: null |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 52 | }, |
| 53 | getters: { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 54 | allEvents: state => state.allEvents, |
| 55 | highPriorityEvents: state => state.highPriorityEvents, |
| 56 | healthStatus: state => state.healthStatus |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 57 | }, |
| 58 | mutations: { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 59 | setAllEvents: (state, allEvents) => (state.allEvents = allEvents), |
| 60 | setHighPriorityEvents: (state, highPriorityEvents) => |
| 61 | (state.highPriorityEvents = highPriorityEvents), |
| 62 | setHealthStatus: (state, status) => (state.healthStatus = status) |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 63 | }, |
| 64 | actions: { |
Yoshie Muranaka | 598bf7e | 2020-05-01 12:26:00 -0700 | [diff] [blame^] | 65 | async getEventLogData({ commit }) { |
| 66 | return await api |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 67 | .get('/xyz/openbmc_project/logging/enumerate') |
| 68 | .then(response => { |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 69 | const responseData = response.data.data; |
| 70 | const eventLogs = []; |
Dixsie Wolmers | 97f4187 | 2020-02-23 15:56:16 -0600 | [diff] [blame] | 71 | |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 72 | for (const key in responseData) { |
| 73 | const event = responseData[key]; |
| 74 | const { Id } = event; |
| 75 | if (responseData.hasOwnProperty(key) && Id) { |
| 76 | const { EventID, Description, Timestamp, Severity } = event; |
| 77 | eventLogs.push({ |
| 78 | logId: Id, |
| 79 | priority: priorityMapper(Severity), |
Dixsie Wolmers | 97f4187 | 2020-02-23 15:56:16 -0600 | [diff] [blame] | 80 | timestamp: new Date(Timestamp), |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 81 | eventID: EventID, |
| 82 | description: Description, |
| 83 | ...event |
| 84 | }); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 85 | } |
| 86 | } |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 87 | |
| 88 | const healthStatus = getHealthStatus(eventLogs); |
| 89 | const highPriorityEvents = eventLogs.filter( |
| 90 | ({ priority, Resolved }) => priority === 'high' && !Resolved |
| 91 | ); |
| 92 | |
| 93 | commit('setAllEvents', eventLogs); |
| 94 | commit('setHighPriorityEvents', highPriorityEvents); |
| 95 | commit('setHealthStatus', healthStatus); |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 96 | }) |
| 97 | .catch(error => { |
| 98 | console.log('Event Log Data:', error); |
| 99 | }); |
Yoshie Muranaka | 1ace1d9 | 2020-02-06 13:47:28 -0800 | [diff] [blame] | 100 | }, |
| 101 | checkHealth({ commit, getters }, interfaces) { |
| 102 | if (getters['healthStatus'] === 'critical') return; |
| 103 | for (const key in interfaces) { |
| 104 | const event = interfaces[key]; |
| 105 | const eventPriority = priorityMapper(event.Severity); |
| 106 | const isEventResolved = event.Resolved; |
| 107 | if (!isEventResolved) { |
| 108 | if (eventPriority === 'high') { |
| 109 | commit('setHealthStatus', 'critical'); |
| 110 | break; |
| 111 | } |
| 112 | if (eventPriority === 'medium') commit('setHealthStatus', 'warning'); |
| 113 | } |
| 114 | } |
Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | export default EventLogStore; |