summaryrefslogtreecommitdiff
path: root/src/store/modules/Settings/SnmpStore.js
diff options
context:
space:
mode:
authorVitalii Lysak <v.lysak@dunice.net>2022-09-20 13:35:38 +0300
committerVitalii Lysak <v.lysak@dunice.net>2022-09-20 13:35:38 +0300
commit4d04ae12f310f1bccf1270f1d3a4090b888ecf6e (patch)
tree793e75c70b133a1ddf2dbfe56134ef869ca7fc62 /src/store/modules/Settings/SnmpStore.js
parentab93e8470ddb49f4a522446dfb9c7882ff37daaf (diff)
parent37f6f72ff1ed6d4795c3f67ca2ba92367582e562 (diff)
downloadwebui-vue-4d04ae12f310f1bccf1270f1d3a4090b888ecf6e.tar.xz
merge smtp, snmp, syslog
Diffstat (limited to 'src/store/modules/Settings/SnmpStore.js')
-rw-r--r--src/store/modules/Settings/SnmpStore.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/store/modules/Settings/SnmpStore.js b/src/store/modules/Settings/SnmpStore.js
new file mode 100644
index 00000000..3fda494f
--- /dev/null
+++ b/src/store/modules/Settings/SnmpStore.js
@@ -0,0 +1,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(async () => {
+ await 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(async () => {
+ await 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 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;