summaryrefslogtreecommitdiff
path: root/src/store/modules/HardwareStatus/FanStore.js
blob: 69e18532329d9d3cb368914326e875a1e0250dd6 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import api from '@/store/api';
import i18n from '@/i18n';

const FanStore = {
  namespaced: true,
  state: {
    fans: [],
    fansLastHour: [],
    limits: [],
    isLoading: false,
  },
  getters: {
    fans: (state) => state.fans,
    fansLastHour: (state) => state.fansLastHour,
    limits: (state) => state.limits,
    isLoading: (state) => state.isLoading,
  },
  mutations: {
    setFanInfo: (state, data) => {
      state.fans = data.map((fan) => {
        const {
          IndicatorLED,
          Location,
          MemberId,
          Name,
          Reading,
          ReadingUnits,
          Status = {},
          PartNumber,
          SerialNumber,
        } = fan;
        return {
          id: MemberId,
          health: Status.Health,
          partNumber: PartNumber,
          serialNumber: SerialNumber,
          healthRollup: Status.HealthRollup,
          identifyLed: IndicatorLED,
          locationNumber: Location,
          name: Name,
          speed: Reading + ' ' + ReadingUnits,
          speedRPM: Reading,
          statusState: Status.State,
        };
      });
    },

    setFans: (state, data) => {
      state.fans = data;
    },
    setFansLastHour: (state, data) => {
      state.fansLastHour = data;
    },
    setLimits: (state, data) => {
      state.limits = data;
    },
    setIsLoading: (state, data) => {
      state.isLoading = data;
    },
  },
  actions: {
    async patchLimits({ dispatch }, { warning, critical, groups }) {
      return await api
        .patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', {
          Fans: groups.map((group) => {
            return {
              MemberId: group,
              UpperThresholdNonCritical: warning,
            };
          }),
        })
        .then(async () => {
          return await api.patch('/redfish/v1/Chassis/SILA_Baseboard/Thermal', {
            Fans: groups.map((group) => {
              return {
                MemberId: group,
                UpperThresholdCritical: critical,
              };
            }),
          });
        })
        .catch((error) => {
          console.log(error);
          throw new Error(i18n.t('pageMemory.toast.errorLimitUpdate'));
        })
        .finally(() => dispatch('getLimits'));
    },
    async getLimits({ commit }) {
      return await api
        .get('/redfish/v1/Chassis/SILA_Baseboard/Thermal')
        .then(({ data: { Fans = [] } }) => {
          commit('setLimits', Fans);
        })
        .catch((error) => console.log(error));
    },
    async getFans({ commit }, { lastHour }) {
      let url = null;
      if (lastHour) {
        url =
          '/redfish/v1/TelemetryService/MetricReports/fans&period=last_hour';
      } else {
        url = '/redfish/v1/TelemetryService/MetricReports/fans';
      }
      return await api
        .get(url)
        .then(({ data: { MetricValues = [] } }) => {
          if (lastHour) {
            commit('setFansLastHour', MetricValues);
          } else {
            commit('setFans', MetricValues);
          }
        })
        .catch((error) => console.log(error));
    },
    async getFanInfo({ commit }) {
      return await api
        .get('/redfish/v1/Chassis/chassis/Thermal')
        .then(({ data: { Fans = [] } }) => commit('setFanInfo', Fans))
        .catch((error) => console.log(error));
    },
  },
};

export default FanStore;