summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorVitalii Lysak <v.lysak@dunice.net>2022-09-14 14:53:52 +0300
committerVitalii Lysak <v.lysak@dunice.net>2022-09-14 14:53:52 +0300
commit158e0373b621079a714086791113a7e021e326dc (patch)
tree989bcee5d27a24e8cb338ddfcfc8e475f70dd91d /src/store
parenta38f344867bba7e9770865d68990442acb632459 (diff)
downloadwebui-vue-158e0373b621079a714086791113a7e021e326dc.tar.xz
finish snmp component
Diffstat (limited to 'src/store')
-rw-r--r--src/store/index.js2
-rw-r--r--src/store/modules/Settings/SnmpStore.js73
2 files changed, 75 insertions, 0 deletions
diff --git a/src/store/index.js b/src/store/index.js
index ba7cdf99..a30f71e2 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -31,6 +31,7 @@ import FactoryResetStore from './modules/Operations/FactoryResetStore';
import KeyClearStore from './modules/Operations/KeyClearStore';
import PciStore from './modules/HardwareStatus/PciStore';
import SmtpStore from './modules/Settings/SmtpStore';
+import SnmpStore from './modules/Settings/SnmpStore';
import WebSocketPlugin from './plugins/WebSocketPlugin';
import DateTimeStore from './modules/Settings/DateTimeStore';
@@ -75,6 +76,7 @@ export default new Vuex.Store({
keyClear: KeyClearStore,
pciStore: PciStore,
smtpStore: SmtpStore,
+ snmpStore: SnmpStore,
},
plugins: [WebSocketPlugin],
});
diff --git a/src/store/modules/Settings/SnmpStore.js b/src/store/modules/Settings/SnmpStore.js
new file mode 100644
index 00000000..539b85f6
--- /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(() => {
+ 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;