blob: 2b93ffa73db17fadd2e5427788fbda896aa39fc2 [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
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -07004const getHealthStatus = events => {
5 let status = 'OK';
6 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: {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070026 allEvents: []
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060027 },
28 getters: {
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080029 allEvents: state => state.allEvents,
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070030 highPriorityEvents: state => getHighPriorityEvents(state.allEvents),
31 healthStatus: state => getHealthStatus(state.allEvents)
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060032 },
33 mutations: {
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070034 setAllEvents: (state, allEvents) => (state.allEvents = allEvents)
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060035 },
36 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070037 async getEventLogData({ commit }) {
38 return await api
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070039 .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
40 .then(({ data: { Members = [] } = {} }) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070041 const eventLogs = Members.map(log => {
42 const { Id, Severity, Created, EntryType, Message } = log;
43 return {
44 id: Id,
45 severity: Severity,
46 date: new Date(Created),
47 type: EntryType,
48 description: Message,
49 uri: log['@odata.id']
50 };
51 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080052 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060053 })
54 .catch(error => {
55 console.log('Event Log Data:', error);
56 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070057 },
58 async deleteEventLogs({ dispatch }, uris = []) {
59 const promises = uris.map(uri =>
60 api.delete(uri).catch(error => {
61 console.log(error);
62 return error;
63 })
64 );
65 return await api
66 .all(promises)
67 .then(response => {
68 dispatch('getEventLogData');
69 return response;
70 })
71 .then(
72 api.spread((...responses) => {
73 const { successCount, errorCount } = getResponseCount(responses);
74 const toastMessages = [];
75
76 if (successCount) {
77 const message = i18n.tc(
78 'pageEventLogs.toast.successDelete',
79 successCount
80 );
81 toastMessages.push({ type: 'success', message });
82 }
83
84 if (errorCount) {
85 const message = i18n.tc(
86 'pageEventLogs.toast.errorDelete',
87 errorCount
88 );
89 toastMessages.push({ type: 'error', message });
90 }
91
92 return toastMessages;
93 })
94 );
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060095 }
96 }
97};
98
99export default EventLogStore;