1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import api from '@/store/api';
import i18n from '@/i18n';
const SnmpStore = {
namespaced: true,
state: { subscribers: [] },
getters: { subscribers: (state) => state.subscribers },
mutations: {
setSubscribers: (state, data) => (state.subscribers = data),
},
actions: {
async deleteSubscriber({ dispatch }, index) {
return await api
.delete(`/redfish/v1/EventService/Subscriptions/${index}`)
.then(() => {
dispatch('getSubscribers');
return i18n.t('pageTransfer.snmp.deleteSubscriberSuсcess');
})
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageTransfer.snmp.deleteSubscriberError'));
});
},
async addSubscriber({ dispatch }, payload) {
return await api
.post('/redfish/v1/EventService/Subscriptions', payload)
.then(() => {
dispatch('getSubscribers');
return i18n.t('pageTransfer.snmp.saveSubscriberSuсcess');
})
.catch((error) => {
console.log(error);
throw new Error(i18n.t('pageTransfer.snmp.saveSubscriberError'));
});
},
async getSubscribers({ commit }) {
return await api
.get('/redfish/v1/EventService/Subscriptions')
.then(({ data: { Members } }) => {
return api.all(
Members.filter((member) => member['@odata.id'].includes('snmp'))
);
})
.then((members) => {
return api.all(members.map((member) => api.get(member['@odata.id'])));
})
.then((subscribersRow) => {
return subscribersRow.map((subscriberRow) => {
return subscriberRow.data;
});
})
.then((data) => {
return data.map((subscriber) => {
const host = subscriber.Destination.split('/')[2].split(':')[0];
const port = subscriber.Destination.split('/')[2].split(':')[1];
return {
...subscriber,
host,
port,
};
});
})
.then((subscribers) => commit('setSubscribers', subscribers))
.catch((error) => {
console.log(error);
const message = i18n.t('pageUserManagement.toast.errorLoadUsers');
throw new Error(message);
});
},
},
};
export default SnmpStore;
|