@@ -3,59 +3,32 @@ package database
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strings"
7
+ "time"
8
+
6
9
"github.com/analogj/scrutiny/webapp/backend/pkg/models/collector"
7
10
"github.com/analogj/scrutiny/webapp/backend/pkg/models/measurements"
8
11
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
9
- "strings"
10
- "time"
11
12
)
12
13
13
14
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14
15
// Temperature Data
15
16
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16
17
func (sr * scrutinyRepository ) SaveSmartTemperature (ctx context.Context , wwn string , deviceProtocol string , collectorSmartData collector.SmartInfo ) error {
17
- if len (collectorSmartData .AtaSctTemperatureHistory .Table ) > 0 {
18
-
19
- for ndx , temp := range collectorSmartData .AtaSctTemperatureHistory .Table {
20
- //temp value may be null, we must skip/ignore them. See #393
21
- if temp == 0 {
22
- continue
23
- }
24
-
25
- minutesOffset := collectorSmartData .AtaSctTemperatureHistory .LoggingIntervalMinutes * int64 (ndx ) * 60
26
- smartTemp := measurements.SmartTemperature {
27
- Date : time .Unix (collectorSmartData .LocalTime .TimeT - minutesOffset , 0 ),
28
- Temp : temp ,
29
- }
30
-
31
- tags , fields := smartTemp .Flatten ()
32
- tags ["device_wwn" ] = wwn
33
- p := influxdb2 .NewPoint ("temp" ,
34
- tags ,
35
- fields ,
36
- smartTemp .Date )
37
- err := sr .influxWriteApi .WritePoint (ctx , p )
38
- if err != nil {
39
- return err
40
- }
41
- }
42
- // also add the current temperature.
43
- } else {
44
-
45
- smartTemp := measurements.SmartTemperature {
46
- Date : time .Unix (collectorSmartData .LocalTime .TimeT , 0 ),
47
- Temp : collectorSmartData .Temperature .Current ,
48
- }
18
+ // collectorSmartData.AtaSctTemperatureHistory isn't reliable, only use current temperature
49
19
50
- tags , fields := smartTemp .Flatten ()
51
- tags ["device_wwn" ] = wwn
52
- p := influxdb2 .NewPoint ("temp" ,
53
- tags ,
54
- fields ,
55
- smartTemp .Date )
56
- return sr .influxWriteApi .WritePoint (ctx , p )
20
+ smartTemp := measurements.SmartTemperature {
21
+ Date : time .Unix (collectorSmartData .LocalTime .TimeT , 0 ),
22
+ Temp : collectorSmartData .Temperature .Current ,
57
23
}
58
- return nil
24
+
25
+ tags , fields := smartTemp .Flatten ()
26
+ tags ["device_wwn" ] = wwn
27
+ p := influxdb2 .NewPoint ("temp" ,
28
+ tags ,
29
+ fields ,
30
+ smartTemp .Date )
31
+ return sr .influxWriteApi .WritePoint (ctx , p )
59
32
}
60
33
61
34
func (sr * scrutinyRepository ) GetSmartTemperatureHistory (ctx context.Context , durationKey string ) (map [string ][]measurements.SmartTemperature , error ) {
0 commit comments