Skip to content

Commit

Permalink
Move sensors to use sensor collection schema (#7)
Browse files Browse the repository at this point in the history
Before to get all the Sensors 3 of a chassis,
3 calls were made:
/redfish/v1/Chassis/{chassis}/Power
/redfish/v1/Chassis/{chassis}/Thermal
/redfish/v1/Chassis/{chassis}/Sensors

With this change:
https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/40169
All that is needed is a call to /redfish/v1/Chassis/{chassis}/Sensors

Note: The threshold property is optional on some sensors,
Optional chaining operator (?.) is used to return undefined
if a property does not exist.

Signed-off-by: Dixsie Wolmers <[email protected]>
  • Loading branch information
dixsie authored and rfrandse committed Jun 30, 2022
1 parent d45ebe1 commit fad8a1b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 35 deletions.
21 changes: 9 additions & 12 deletions src/store/modules/HardwareStatus/SensorsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@ const SensorsStore = {
},
},
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')
.get('/redfish/v1/')
.then((response) => api.get(response.data.Chassis['@odata.id']))
.then(({ data: { Members } }) =>
Members.map((member) => member['@odata.id'])
)
.catch((error) => console.log(error));
},
async getAllSensors({ dispatch }) {
const collection = await dispatch('getChassisCollection');
if (!collection) return;
return await api
.all(collection.map((chassis) => dispatch('getSensors', chassis)))
.catch((error) => console.log(error));
},
async getSensors({ commit }, id) {
const sensors = await api
.get(`${id}/Sensors`)
Expand Down
71 changes: 48 additions & 23 deletions src/views/HardwareStatus/Sensors/Sensors.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<template>
<b-container fluid="xl">
<page-title />
<b-row>
<b-col md="8" xl="6">
<alert variant="info" class="mb-4">
<span>
{{ $t('pageSensors.alert') }}
</span>
</alert>
</b-col>
</b-row>
<b-row class="align-items-end">
<b-col sm="6" md="5" xl="4">
<search
Expand Down Expand Up @@ -48,6 +57,8 @@
:no-border-collapse="true"
:items="filteredSensors"
:fields="fields"
:per-page="perPage"
:current-page="currentPage"
:sort-desc="true"
:sort-compare="sortCompare"
:filter="searchFilter"
Expand Down Expand Up @@ -97,18 +108,49 @@
</b-table>
</b-col>
</b-row>
<!-- Table pagination -->
<b-row>
<b-col sm="6">
<b-form-group
class="table-pagination-select"
:label="$t('global.table.itemsPerPage')"
label-for="pagination-items-per-page"
>
<b-form-select
id="pagination-items-per-page"
v-model="perPage"
:options="itemsPerPageOptions"
/>
</b-form-group>
</b-col>
<b-col sm="6">
<b-pagination
v-model="currentPage"
first-number
last-number
:per-page="perPage"
:total-rows="getTotalRowCount(filteredRows)"
aria-controls="table-sensors"
/>
</b-col>
</b-row>
</b-container>
</template>

<script>
import Alert from '@/components/Global/Alert';
import PageTitle from '@/components/Global/PageTitle';
import Search from '@/components/Global/Search';
import StatusIcon from '@/components/Global/StatusIcon';
import TableFilter from '@/components/Global/TableFilter';
import TableToolbar from '@/components/Global/TableToolbar';
import TableToolbarExport from '@/components/Global/TableToolbarExport';
import TableCellCount from '@/components/Global/TableCellCount';
import BVPaginationMixin, {
currentPage,
perPage,
itemsPerPageOptions,
} from '@/components/Mixins/BVPaginationMixin';
import BVTableSelectableMixin, {
selectedRows,
tableHeaderCheckboxModel,
Expand All @@ -121,10 +163,10 @@ import TableSortMixin from '@/components/Mixins/TableSortMixin';
import SearchFilterMixin, {
searchFilter,
} from '@/components/Mixins/SearchFilterMixin';
export default {
name: 'Sensors',
components: {
Alert,
PageTitle,
Search,
StatusIcon,
Expand All @@ -134,6 +176,7 @@ export default {
TableToolbarExport,
},
mixins: [
BVPaginationMixin,
TableFilterMixin,
BVTableSelectableMixin,
LoadingBarMixin,
Expand Down Expand Up @@ -165,32 +208,11 @@ export default {
label: this.$t('pageSensors.table.status'),
tdClass: 'text-nowrap',
},
{
key: 'lowerCritical',
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.lowerCritical'),
},
{
key: 'lowerCaution',
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.lowerWarning'),
},
{
key: 'currentValue',
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.currentValue'),
},
{
key: 'upperCaution',
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.upperWarning'),
},
{
key: 'upperCritical',
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.upperCritical'),
},
],
tableFilters: [
{
Expand All @@ -200,6 +222,9 @@ export default {
},
],
activeFilters: [],
currentPage: currentPage,
itemsPerPageOptions: itemsPerPageOptions,
perPage: perPage,
searchFilter: searchFilter,
searchTotalFilteredRows: 0,
selectedRows: selectedRows,
Expand Down

0 comments on commit fad8a1b

Please sign in to comment.