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
|
import api from '@/store/api';
import { uniqBy } from 'lodash';
const SensorsStore = {
namespaced: true,
state: {
sensors: [],
},
getters: {
sensors: (state) => state.sensors,
},
mutations: {
setSensors: (state, sensors) => {
state.sensors = uniqBy([...state.sensors, ...sensors], 'name');
},
},
actions: {
async getAllSensors({ dispatch }) {
const collection = await dispatch('getChassisCollection');
if (!collection) return;
const promises = collection.reduce((acc, id) => {
acc.push(dispatch('getSensors', id));
acc.push(dispatch('getThermalSensors', id));
acc.push(dispatch('getPowerSensors', id));
return acc;
}, []);
return await api.all(promises);
},
async getChassisCollection() {
return await api
.get('/redfish/v1/Chassis')
.then(({ data: { Members } }) =>
Members.map((member) => member['@odata.id'])
)
.catch((error) => console.log(error));
},
async getSensors({ commit }, id) {
const sensors = await api
.get(`${id}/Sensors`)
.then((response) => response.data.Members)
.catch((error) => console.log(error));
if (!sensors) return;
const promises = sensors.map((sensor) => {
return api.get(sensor['@odata.id']).catch((error) => {
console.log(error);
return error;
});
});
return await api.all(promises).then(
api.spread((...responses) => {
const sensorData = responses.map(({ data }) => {
return {
name: data.Name,
status: data.Status.Health,
currentValue: data.Reading,
lowerCaution: data.Thresholds?.LowerCaution?.Reading,
upperCaution: data.Thresholds?.UpperCaution?.Reading,
lowerCritical: data.Thresholds?.LowerCritical?.Reading,
upperCritical: data.Thresholds?.UpperCritical?.Reading,
units: data.ReadingUnits,
};
});
commit('setSensors', sensorData);
})
);
},
async getThermalSensors({ commit }, id) {
return await api
.get(`${id}/Thermal`)
.then(({ data: { Fans = [], Temperatures = [] } }) => {
const sensorData = [];
Fans.forEach((sensor) => {
sensorData.push({
name: sensor.Name,
status: sensor.Status.Health,
currentValue: sensor.Reading,
lowerCaution: sensor.LowerThresholdNonCritical,
upperCaution: sensor.UpperThresholdNonCritical,
lowerCritical: sensor.LowerThresholdCritical,
upperCritical: sensor.UpperThresholdCritical,
units: sensor.ReadingUnits,
});
});
Temperatures.forEach((sensor) => {
sensorData.push({
name: sensor.Name,
status: sensor.Status.Health,
currentValue: sensor.ReadingCelsius,
lowerCaution: sensor.LowerThresholdNonCritical,
upperCaution: sensor.UpperThresholdNonCritical,
lowerCritical: sensor.LowerThresholdCritical,
upperCritical: sensor.UpperThresholdCritical,
units: '℃',
});
});
commit('setSensors', sensorData);
})
.catch((error) => console.log(error));
},
async getPowerSensors({ commit }, id) {
return await api
.get(`${id}/Power`)
.then(({ data: { Voltages = [] } }) => {
const sensorData = Voltages.map((sensor) => {
return {
name: sensor.Name,
status: sensor.Status.Health,
currentValue: sensor.ReadingVolts,
lowerCaution: sensor.LowerThresholdNonCritical,
upperCaution: sensor.UpperThresholdNonCritical,
lowerCritical: sensor.LowerThresholdCritical,
upperCritical: sensor.UpperThresholdCritical,
units: 'V',
};
});
commit('setSensors', sensorData);
})
.catch((error) => console.log(error));
},
},
};
export default SensorsStore;
|