1 import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
2 import { I18n } from '@ngx-translate/i18n-polyfill';
3 import * as _ from 'lodash';
9 } from '../../../../shared/api/osd.service';
10 import { CdTableColumn } from '../../../../shared/models/cd-table-column';
13 selector: 'cd-osd-smart-list',
14 templateUrl: './osd-smart-list.component.html',
15 styleUrls: ['./osd-smart-list.component.scss']
17 export class OsdSmartListComponent implements OnInit, OnChanges {
25 info: { [key: string]: number | string | boolean };
28 table: SmartAttribute[];
33 columns: CdTableColumn[];
35 constructor(private i18n: I18n, private osdService: OsdService) {}
37 private isSmartError(data: SmartDataV1 | SmartError): data is SmartError {
38 return (data as SmartError).error !== undefined;
41 private updateData(osdId: number) {
43 this.osdService.getSmartData(osdId).subscribe((data) => {
45 _.each(data, (smartData, deviceId) => {
46 if (this.isSmartError(smartData)) {
48 if (smartData.smartctl_error_code === -22) {
49 userMessage = this.i18n(
50 `Smartctl has received an unknown argument (error code
51 {{smartData.smartctl_error_code}}). You may be using an
52 incompatible version of smartmontools. Version >= 7.0 of
53 smartmontools is required to succesfully retrieve data.`,
54 { code: smartData.smartctl_error_code }
57 userMessage = this.i18n('An error with error code {{code}} occurred.', {
58 code: smartData.smartctl_error_code
62 error: smartData.error,
63 smartctl_error_code: smartData.smartctl_error_code,
64 smartctl_output: smartData.smartctl_output,
65 userMessage: userMessage,
66 device: smartData.dev,
67 identifier: smartData.nvme_vendor
72 // Prepare S.M.A.R.T data
73 if (smartData.json_format_version[0] === 1) {
76 'ata_smart_attributes',
77 'ata_smart_selective_self_test_log',
80 const info = _.pickBy(smartData, (_value, key) => !excludes.includes(key));
85 attributes: smartData.ata_smart_attributes,
86 data: smartData.ata_smart_data
88 device: info.device.name,
89 identifier: info.serial_number
92 this.incompatible = true;
102 { prop: 'id', name: this.i18n('ID') },
103 { prop: 'name', name: this.i18n('Name') },
104 { prop: 'raw.value', name: this.i18n('Raw') },
105 { prop: 'thresh', name: this.i18n('Threshold') },
106 { prop: 'value', name: this.i18n('Value') },
107 { prop: 'when_failed', name: this.i18n('When Failed') },
108 { prop: 'worst', name: this.i18n('Worst') }
112 ngOnChanges(changes: SimpleChanges): void {
113 this.data = {}; // Clear previous data
114 this.updateData(changes.osdId.currentValue);