Dixsie Wolmers | f65ee34 | 2020-01-22 19:47:56 -0600 | [diff] [blame] | 1 | import api from '../../api'; |
| 2 | |
| 3 | const severityToPriorityMap = { |
| 4 | Emergency: 'High', |
| 5 | Alert: 'High', |
| 6 | Critical: 'High', |
| 7 | Error: 'High', |
| 8 | Warning: 'Medium', |
| 9 | Notice: 'Low', |
| 10 | Debug: 'Low', |
| 11 | Informational: 'Low' |
| 12 | }; |
| 13 | |
| 14 | const EventLogStore = { |
| 15 | namespaced: true, |
| 16 | state: { |
| 17 | eventLogData: null |
| 18 | }, |
| 19 | getters: { |
| 20 | eventLogData: state => state.eventLogData |
| 21 | }, |
| 22 | mutations: { |
| 23 | setEventLogData: (state, eventLogData) => |
| 24 | (state.eventLogData = eventLogData) |
| 25 | }, |
| 26 | actions: { |
| 27 | getEventLogData({ commit }) { |
| 28 | api |
| 29 | .get('/xyz/openbmc_project/logging/enumerate') |
| 30 | .then(response => { |
| 31 | const eventLog = response.data.data; |
| 32 | const entryNumber = /[1-9]/; |
| 33 | const eventLogEntries = []; |
| 34 | /** |
| 35 | * Entry log endpoints: |
| 36 | * 'entry' + entry id contain event log entry information |
| 37 | * 'callout' contains part number and serial number for part affected |
| 38 | */ |
| 39 | for (let key in eventLog) { |
| 40 | // Check for event log entry: |
| 41 | if ( |
| 42 | key.includes('entry') && |
| 43 | key.match(entryNumber) && |
| 44 | !key.includes('callout') |
| 45 | ) { |
| 46 | const eventKey = eventLog[key]; |
| 47 | const eventSeverity = eventKey.Severity.split('.').pop(); |
| 48 | const eventPriority = severityToPriorityMap[eventSeverity]; |
| 49 | eventLogEntries.push( |
| 50 | Object.assign( |
| 51 | { |
| 52 | logId: eventKey.Id, |
| 53 | priority: eventPriority, |
| 54 | timestamp: eventKey.Timestamp, |
| 55 | eventID: eventKey.EventID, |
| 56 | description: eventKey.Description |
| 57 | }, |
| 58 | eventKey |
| 59 | ) |
| 60 | ); |
| 61 | commit('setEventLogData', eventLogEntries); |
| 62 | } |
| 63 | } |
| 64 | }) |
| 65 | .catch(error => { |
| 66 | console.log('Event Log Data:', error); |
| 67 | }); |
| 68 | } |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | export default EventLogStore; |