-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Cleanup Exporter a bit - move unwieldy prom.MustNewConstMetric into a helper func - move fetching UNMS data into a helper func - reduce unnecessay allocation in intoDesc - make API tokens configurable via environment - run `go mod tidy` * remove redundant nil check
- Loading branch information
Showing
5 changed files
with
111 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package exporter | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ffddorf/unms-exporter/client/devices" | ||
"github.com/ffddorf/unms-exporter/models" | ||
) | ||
|
||
var defaultWithInterfaces = true | ||
|
||
func (e *Exporter) fetchDeviceData() ([]*models.DeviceStatusOverview, error) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
params := &devices.GetDevicesParams{ | ||
WithInterfaces: &defaultWithInterfaces, | ||
Context: ctx, | ||
} | ||
devicesResponse, err := e.api.Devices.GetDevices(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data := make([]*models.DeviceStatusOverview, 0, len(devicesResponse.Payload)) | ||
for _, overview := range devicesResponse.Payload { | ||
if overview.Identification == nil { | ||
continue | ||
} | ||
data = append(data, overview) | ||
} | ||
|
||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.