blob: 79bee02a2526d89f07eb775d5b08c41ffa826bf4 [file] [log] [blame]
Yoshie Muranakabe3af332020-05-11 08:23:04 -07001import api, { getResponseCount } from '@/store/api';
2import i18n from '@/i18n';
Dixsie Wolmersf65ee342020-01-22 19:47:56 -06003
Mateusz Gapski076ab272020-07-20 10:55:15 +02004const getHealthStatus = (events, loadedEvents) => {
5 let status = loadedEvents ? 'OK' : '';
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -07006 for (const event of events) {
7 if (event.severity === 'Warning') {
8 status = 'Warning';
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -08009 }
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070010 if (event.severity === 'Critical') {
11 status = 'Critical';
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080012 break;
13 }
14 }
15 return status;
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060016};
17
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070018// TODO: High priority events should also check if Log
19// is resolved when the property is available in Redfish
20const getHighPriorityEvents = events =>
21 events.filter(({ severity }) => severity === 'Critical');
22
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060023const EventLogStore = {
24 namespaced: true,
25 state: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020026 allEvents: [],
27 loadedEvents: false
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060028 },
29 getters: {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080030 allEvents: state => state.allEvents,
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070031 highPriorityEvents: state => getHighPriorityEvents(state.allEvents),
Mateusz Gapski076ab272020-07-20 10:55:15 +020032 healthStatus: state => getHealthStatus(state.allEvents, state.loadedEvents)
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060033 },
34 mutations: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020035 setAllEvents: (state, allEvents) => (
36 (state.allEvents = allEvents), (state.loadedEvents = true)
37 )
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060038 },
39 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070040 async getEventLogData({ commit }) {
41 return await api
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070042 .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
43 .then(({ data: { Members = [] } = {} }) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070044 const eventLogs = Members.map(log => {
45 const { Id, Severity, Created, EntryType, Message } = log;
46 return {
47 id: Id,
48 severity: Severity,
49 date: new Date(Created),
50 type: EntryType,
51 description: Message,
52 uri: log['@odata.id']
53 };
54 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080055 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060056 })
57 .catch(error => {
58 console.log('Event Log Data:', error);
59 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070060 },
61 async deleteEventLogs({ dispatch }, uris = []) {
62 const promises = uris.map(uri =>
63 api.delete(uri).catch(error => {
64 console.log(error);
65 return error;
66 })
67 );
68 return await api
69 .all(promises)
70 .then(response => {
71 dispatch('getEventLogData');
72 return response;
73 })
74 .then(
75 api.spread((...responses) => {
76 const { successCount, errorCount } = getResponseCount(responses);
77 const toastMessages = [];
78
79 if (successCount) {
80 const message = i18n.tc(
81 'pageEventLogs.toast.successDelete',
82 successCount
83 );
84 toastMessages.push({ type: 'success', message });
85 }
86
87 if (errorCount) {
88 const message = i18n.tc(
89 'pageEventLogs.toast.errorDelete',
90 errorCount
91 );
92 toastMessages.push({ type: 'error', message });
93 }
94
95 return toastMessages;
96 })
97 );
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060098 }
99 }
100};
101
102export default EventLogStore;