summaryrefslogtreecommitdiff
path: root/src/store/modules/Health
diff options
context:
space:
mode:
authorYoshie Muranaka <yoshiemuranaka@gmail.com>2020-02-07 00:47:28 +0300
committerYoshie Muranaka <yoshiemuranaka@gmail.com>2020-02-17 21:48:43 +0300
commit1ace1d91e80425eeed482b33e21838acb7f7325a (patch)
tree86700b60471ae41222bdba6902b3cb308978953a /src/store/modules/Health
parentc031b6988d6381ae1d2ecefd04e8c2af47f0ff4a (diff)
downloadwebui-vue-1ace1d91e80425eeed482b33e21838acb7f7325a.tar.xz
Add Health status to app header
Added logging path and interface to websocket subscription data filter, to dynamically indicate Health status in the app header. - Update OverviewEvents to use highPriorityEvents data - Refactor EventLogStore Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com> Change-Id: I35ad30b005c70625a5f6a69488d45db0fa049374
Diffstat (limited to 'src/store/modules/Health')
-rw-r--r--src/store/modules/Health/EventLogStore.js134
1 files changed, 90 insertions, 44 deletions
diff --git a/src/store/modules/Health/EventLogStore.js b/src/store/modules/Health/EventLogStore.js
index 404a9639..3f32ab16 100644
--- a/src/store/modules/Health/EventLogStore.js
+++ b/src/store/modules/Health/EventLogStore.js
@@ -1,70 +1,116 @@
import api from '../../api';
-const severityToPriorityMap = {
- Emergency: 'High',
- Alert: 'High',
- Critical: 'High',
- Error: 'High',
- Warning: 'Medium',
- Notice: 'Low',
- Debug: 'Low',
- Informational: 'Low'
+const EVENT_SEVERITY = {
+ emergency: 'xyz.openbmc_project.Logging.Entry.Level.Emergency',
+ alert: 'xyz.openbmc_project.Logging.Entry.Level.Alert',
+ critical: 'xyz.openbmc_project.Logging.Entry.Level.Critical',
+ error: 'xyz.openbmc_project.Logging.Entry.Level.Error',
+ warning: 'xyz.openbmc_project.Logging.Entry.Level.Warning',
+ notice: 'xyz.openbmc_project.Logging.Entry.Level.Notice',
+ informational: 'xyz.openbmc_project.Logging.Entry.Level.Informational',
+ debug: 'xyz.openbmc_project.Logging.Entry.Level.Debug'
+};
+
+const priorityMapper = severity => {
+ switch (severity) {
+ case EVENT_SEVERITY.emergency:
+ case EVENT_SEVERITY.alert:
+ case EVENT_SEVERITY.critical:
+ case EVENT_SEVERITY.error:
+ return 'high';
+ case EVENT_SEVERITY.warning:
+ return 'medium';
+ case EVENT_SEVERITY.notice:
+ case EVENT_SEVERITY.debug:
+ case EVENT_SEVERITY.informational:
+ return 'low';
+ default:
+ return '';
+ }
+};
+
+const getHealthStatus = allEvents => {
+ let status = 'good';
+ for (const event of allEvents) {
+ if (!event.Resolved && event.priority === 'medium') {
+ status = 'warning';
+ }
+ if (!event.Resolved && event.priority === 'high') {
+ status = 'critical';
+ break;
+ }
+ }
+ return status;
};
const EventLogStore = {
namespaced: true,
state: {
- eventLogData: null
+ allEvents: [],
+ highPriorityEvents: [],
+ healthStatus: null
},
getters: {
- eventLogData: state => state.eventLogData
+ allEvents: state => state.allEvents,
+ highPriorityEvents: state => state.highPriorityEvents,
+ healthStatus: state => state.healthStatus
},
mutations: {
- setEventLogData: (state, eventLogData) =>
- (state.eventLogData = eventLogData)
+ setAllEvents: (state, allEvents) => (state.allEvents = allEvents),
+ setHighPriorityEvents: (state, highPriorityEvents) =>
+ (state.highPriorityEvents = highPriorityEvents),
+ setHealthStatus: (state, status) => (state.healthStatus = status)
},
actions: {
getEventLogData({ commit }) {
api
.get('/xyz/openbmc_project/logging/enumerate')
.then(response => {
- const eventLog = response.data.data;
- const entryNumber = /[1-9]/;
- const eventLogEntries = [];
- /**
- * Entry log endpoints:
- * 'entry' + entry id contain event log entry information
- * 'callout' contains part number and serial number for part affected
- */
- for (let key in eventLog) {
- // Check for event log entry:
- if (
- key.includes('entry') &&
- key.match(entryNumber) &&
- !key.includes('callout')
- ) {
- const eventKey = eventLog[key];
- const eventSeverity = eventKey.Severity.split('.').pop();
- const eventPriority = severityToPriorityMap[eventSeverity];
- eventLogEntries.push(
- Object.assign(
- {
- logId: eventKey.Id,
- priority: eventPriority,
- timestamp: eventKey.Timestamp,
- eventID: eventKey.EventID,
- description: eventKey.Description
- },
- eventKey
- )
- );
- commit('setEventLogData', eventLogEntries);
+ const responseData = response.data.data;
+ const eventLogs = [];
+ for (const key in responseData) {
+ const event = responseData[key];
+ const { Id } = event;
+ if (responseData.hasOwnProperty(key) && Id) {
+ const { EventID, Description, Timestamp, Severity } = event;
+ eventLogs.push({
+ logId: Id,
+ priority: priorityMapper(Severity),
+ timestamp: Timestamp,
+ eventID: EventID,
+ description: Description,
+ ...event
+ });
}
}
+
+ const healthStatus = getHealthStatus(eventLogs);
+ const highPriorityEvents = eventLogs.filter(
+ ({ priority, Resolved }) => priority === 'high' && !Resolved
+ );
+
+ commit('setAllEvents', eventLogs);
+ commit('setHighPriorityEvents', highPriorityEvents);
+ commit('setHealthStatus', healthStatus);
})
.catch(error => {
console.log('Event Log Data:', error);
});
+ },
+ checkHealth({ commit, getters }, interfaces) {
+ if (getters['healthStatus'] === 'critical') return;
+ for (const key in interfaces) {
+ const event = interfaces[key];
+ const eventPriority = priorityMapper(event.Severity);
+ const isEventResolved = event.Resolved;
+ if (!isEventResolved) {
+ if (eventPriority === 'high') {
+ commit('setHealthStatus', 'critical');
+ break;
+ }
+ if (eventPriority === 'medium') commit('setHealthStatus', 'warning');
+ }
+ }
}
}
};