blob: eaec7490072ce405f49d7ea29f91232fec0f83db [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
Derick Montague602e98a2020-10-21 16:20:00 -050020const getHighPriorityEvents = (events) =>
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070021 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: [],
Derick Montague602e98a2020-10-21 16:20:00 -050027 loadedEvents: false,
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060028 },
29 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050030 allEvents: (state) => state.allEvents,
31 highPriorityEvents: (state) => getHighPriorityEvents(state.allEvents),
32 healthStatus: (state) =>
33 getHealthStatus(state.allEvents, state.loadedEvents),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060034 },
35 mutations: {
Mateusz Gapski076ab272020-07-20 10:55:15 +020036 setAllEvents: (state, allEvents) => (
37 (state.allEvents = allEvents), (state.loadedEvents = true)
Derick Montague602e98a2020-10-21 16:20:00 -050038 ),
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060039 },
40 actions: {
Yoshie Muranaka598bf7e2020-05-01 12:26:00 -070041 async getEventLogData({ commit }) {
42 return await api
Yoshie Muranakace9a3ef2020-05-06 14:33:22 -070043 .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries')
44 .then(({ data: { Members = [] } = {} }) => {
Derick Montague602e98a2020-10-21 16:20:00 -050045 const eventLogs = Members.map((log) => {
Sukanya Pandey47b047c2020-12-23 13:18:55 +053046 const {
47 Id,
48 Severity,
49 Created,
50 EntryType,
51 Message,
52 Name,
53 Modified,
54 } = log;
Yoshie Muranakabe3af332020-05-11 08:23:04 -070055 return {
56 id: Id,
57 severity: Severity,
58 date: new Date(Created),
59 type: EntryType,
60 description: Message,
Sukanya Pandey47b047c2020-12-23 13:18:55 +053061 name: Name,
62 modifiedDate: new Date(Modified),
Derick Montague602e98a2020-10-21 16:20:00 -050063 uri: log['@odata.id'],
Yoshie Muranakabe3af332020-05-11 08:23:04 -070064 };
65 });
Yoshie Muranaka1ace1d92020-02-06 13:47:28 -080066 commit('setAllEvents', eventLogs);
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060067 })
Derick Montague602e98a2020-10-21 16:20:00 -050068 .catch((error) => {
Dixsie Wolmersf65ee342020-01-22 19:47:56 -060069 console.log('Event Log Data:', error);
70 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -070071 },
Sukanya Pandey2f6d5522020-10-28 10:38:00 +053072 async deleteAllEventLogs({ dispatch }, data) {
73 return await api
74 .post(
75 '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog'
76 )
77 .then(() => dispatch('getEventLogData'))
78 .then(() => i18n.tc('pageEventLogs.toast.successDelete', data))
79 .catch((error) => {
80 console.log(error);
81 throw new Error(i18n.tc('pageEventLogs.toast.errorDelete', data));
82 });
83 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070084 async deleteEventLogs({ dispatch }, uris = []) {
Derick Montague602e98a2020-10-21 16:20:00 -050085 const promises = uris.map((uri) =>
86 api.delete(uri).catch((error) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070087 console.log(error);
88 return error;
89 })
90 );
91 return await api
92 .all(promises)
Derick Montague602e98a2020-10-21 16:20:00 -050093 .then((response) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -070094 dispatch('getEventLogData');
95 return response;
96 })
97 .then(
98 api.spread((...responses) => {
99 const { successCount, errorCount } = getResponseCount(responses);
100 const toastMessages = [];
101
102 if (successCount) {
103 const message = i18n.tc(
104 'pageEventLogs.toast.successDelete',
105 successCount
106 );
107 toastMessages.push({ type: 'success', message });
108 }
109
110 if (errorCount) {
111 const message = i18n.tc(
112 'pageEventLogs.toast.errorDelete',
113 errorCount
114 );
115 toastMessages.push({ type: 'error', message });
116 }
117
118 return toastMessages;
119 })
120 );
Derick Montague602e98a2020-10-21 16:20:00 -0500121 },
122 },
Dixsie Wolmersf65ee342020-01-22 19:47:56 -0600123};
124
125export default EventLogStore;