-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathhardwareinfo.go
More file actions
128 lines (106 loc) · 3.88 KB
/
hardwareinfo.go
File metadata and controls
128 lines (106 loc) · 3.88 KB
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
125
126
127
128
// Copyright (c) 2022 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package zedagent
import (
"bytes"
"fmt"
"time"
"github.com/lf-edge/eve-api/go/info"
"github.com/lf-edge/eve/pkg/pillar/agentlog"
"github.com/lf-edge/eve/pkg/pillar/hardware"
"github.com/lf-edge/eve/pkg/pillar/types"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
func hardwareInfoTask(ctxPtr *zedagentContext, triggerHwInfo <-chan destinationBitset) {
wdName := agentName + "hwinfo"
stillRunning := time.NewTicker(30 * time.Second)
ctxPtr.ps.StillRunning(wdName, warningTime, errorTime)
ctxPtr.ps.RegisterFileWatchdog(wdName)
for {
select {
case dest := <-triggerHwInfo:
start := time.Now()
log.Function("HardwareInfoTask got message")
PublishHardwareInfoToZedCloud(ctxPtr, dest)
ctxPtr.iteration++
log.Function("HardwareInfoTask done with message")
ctxPtr.ps.CheckMaxTimeTopic(wdName, "PublishHardwareInfo", start,
warningTime, errorTime)
case <-stillRunning.C:
}
ctxPtr.ps.StillRunning(wdName, warningTime, errorTime)
}
}
func triggerPublishHwInfoToDest(ctxPtr *zedagentContext, dest destinationBitset) {
log.Function("Triggered PublishHardwareInfo")
select {
case ctxPtr.triggerHwInfo <- dest:
// Do nothing more
default:
// This occurs if we are already trying to send a hardware info
// and we get a second and third trigger before that is complete.
log.Warnf("Failed to send on PublishHardwareInfo")
}
}
func triggerPublishHwInfo(ctxPtr *zedagentContext) {
triggerPublishHwInfoToDest(ctxPtr, AllDest)
}
// PublishHardwareInfoToZedCloud send ZInfoHardware message
func PublishHardwareInfoToZedCloud(ctx *zedagentContext, dest destinationBitset) {
var ReportHwInfo = &info.ZInfoMsg{}
hwInfoKey := devUUID.String() + "hwinfo"
bailOnHTTPErr := true
hwType := new(info.ZInfoTypes)
*hwType = info.ZInfoTypes_ZiHardware
ReportHwInfo.Ztype = *hwType
ReportHwInfo.DevId = *proto.String(devUUID.String())
ReportHwInfo.AtTimeStamp = timestamppb.Now()
log.Functionf("PublishHardwareInfoToZedCloud uuid %s", hwInfoKey)
hwInfo := new(info.ZInfoHardware)
hwInfo.EveRelease = agentlog.EveVersion()
hwInfo.EvePlatform = hardware.GetHardwareModel(log)
hwInfo.Partition = agentlog.EveCurrentPartition()
hwInfo.KernelVersion = hardware.GetKernelVersion()
hwInfo.KernelCmdline = hardware.GetKernelCmdline()
hwInfo.KernelFlavor = hardware.GetKernelFlavor()
// Get information about disks
disksInfo, err := hardware.ReadSMARTinfoForDisks()
if err != nil {
log.Fatal("PublishHardwareInfoToZedCloud get information about disks failed. Error: ", err)
return
}
for _, disk := range disksInfo.Disks {
stDiskInfo := new(info.StorageDiskInfo)
if disk.CollectingStatus != types.SmartCollectingStatusSuccess {
stDiskInfo.DiskName = *proto.String(disk.DiskName)
stDiskInfo.CollectorErrors = *proto.String(disk.Errors.Error())
hwInfo.Disks = append(hwInfo.Disks, stDiskInfo)
continue
}
stDiskInfo.DiskName = *proto.String(disk.DiskName)
stDiskInfo.SerialNumber = *proto.String(disk.SerialNumber)
stDiskInfo.Model = *proto.String(disk.ModelNumber)
stDiskInfo.Wwn = *proto.String(fmt.Sprintf("%x", disk.Wwn))
stDiskInfo.SmartAttr = getSmartAttr(disk.SmartAttrs)
hwInfo.Disks = append(hwInfo.Disks, stDiskInfo)
}
if ctx.hwInventory != nil {
hwInfo.Inventory = ctx.hwInventory
}
ReportHwInfo.InfoContent = new(info.ZInfoMsg_Hwinfo)
if x, ok := ReportHwInfo.GetInfoContent().(*info.ZInfoMsg_Hwinfo); ok {
x.Hwinfo = hwInfo
}
log.Tracef("PublishHardwareInfoToZedCloud sending %v", ReportHwInfo)
data, err := proto.Marshal(ReportHwInfo)
if err != nil {
log.Fatal("PublishHardwareInfoToZedCloud proto marshaling error: ", err)
}
buf := bytes.NewBuffer(data)
if buf == nil {
log.Fatal("PublishHardwareInfoToZedCloud malloc error")
}
queueInfoToDest(ctx, dest, hwInfoKey, buf, bailOnHTTPErr, false, false,
info.ZInfoTypes_ZiHardware)
}