From 1c7ca35ea716e48afe04d7db584e5db6ee620139 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sat, 3 Oct 2020 14:38:19 -0600 Subject: [PATCH] build freebsd binaries for CI (not included in releases yet) --- .github/workflows/build.yaml | 14 +++++++ collector/pkg/detect/devices_freebsd.go | 49 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 collector/pkg/detect/devices_freebsd.go diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 94d6042..a7a1843 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -68,6 +68,18 @@ jobs: go build -ldflags "-X main.goos=windows -X main.goarch=amd64" -o scrutiny-web-windows-amd64.exe -tags "static" webapp/backend/cmd/scrutiny/scrutiny.go go build -ldflags "-X main.goos=windows -X main.goarch=amd64" -o scrutiny-collector-metrics-windows-amd64.exe -tags "static" collector/cmd/collector-metrics/collector-metrics.go + - name: Build freebsd + env: + GOOS: freebsd + GOARCH: amd64 + run: | + cd $PROJECT_PATH + go build -ldflags "-X main.goos=freebsd -X main.goarch=amd64" -o scrutiny-web-freebsd-amd64 -tags "static" webapp/backend/cmd/scrutiny/scrutiny.go + go build -ldflags "-X main.goos=freebsd -X main.goarch=amd64" -o scrutiny-collector-metrics-freebsd-amd64 -tags "static" collector/cmd/collector-metrics/collector-metrics.go + + chmod +x scrutiny-web-freebsd-amd64 + chmod +x scrutiny-collector-metrics-freebsd-amd64 + - name: Archive uses: actions/upload-artifact@v2 with: @@ -81,6 +93,8 @@ jobs: ${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-linux-arm ${{ env.PROJECT_PATH }}/scrutiny-web-windows-amd64.exe ${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-windows-amd64.exe + ${{ env.PROJECT_PATH }}/scrutiny-web-freebsd-amd64 + ${{ env.PROJECT_PATH }}/scrutiny-collector-metrics-freebsd-amd64 - uses: codecov/codecov-action@v1 with: file: ${{ env.PROJECT_PATH }}/coverage.txt diff --git a/collector/pkg/detect/devices_freebsd.go b/collector/pkg/detect/devices_freebsd.go new file mode 100644 index 0000000..912070a --- /dev/null +++ b/collector/pkg/detect/devices_freebsd.go @@ -0,0 +1,49 @@ +package detect + +import ( + "github.com/analogj/scrutiny/collector/pkg/models" + "github.com/jaypipes/ghw" + "strings" +) + +func DevicePrefix() string { + return "/dev/" +} + +func (d *Detect) Start() ([]models.Device, error) { + // call the base/common functionality to get a list of devices + detectedDevices, err := d.smartctlScan() + if err != nil { + return nil, err + } + + //inflate device info for detected devices. + for ndx, _ := range detectedDevices { + d.smartCtlInfo(&detectedDevices[ndx]) //ignore errors. + } + + return detectedDevices, nil +} + +//WWN values NVMe and SCSI +func (d *Detect) wwnFallback(detectedDevice *models.Device) { + block, err := ghw.Block() + if err == nil { + for _, disk := range block.Disks { + if disk.Name == detectedDevice.DeviceName { + d.Logger.Debugf("Found matching block device. WWN: %s", disk.WWN) + detectedDevice.WWN = disk.WWN + break + } + } + } + + //no WWN found, or could not open Block devices. Either way, fallback to serial number + if len(detectedDevice.WWN) == 0 { + d.Logger.Debugf("WWN is empty, falling back to serial number: %s", detectedDevice.SerialNumber) + detectedDevice.WWN = detectedDevice.SerialNumber + } + + //wwn must always be lowercase. + detectedDevice.WWN = strings.ToLower(detectedDevice.WWN) +}