24e8161262
- add base structure - unify the proto metrics creation and propagation - implement arp and openvpn - refactor to meet the prom exporter standart - add instance label to the metrics - refactor the call chain - add gateway, unbound_dns and openvpn implementations - add gateway stuff - structure refactor; mod clean; cron implementation - implement cron in the collector; refactor utils in the opnsense package refactor names and implement option functions to disable collectorInstances add GH action workflows Create codeql.yml - clean fix stuff
136 lines
3.9 KiB
Go
136 lines
3.9 KiB
Go
package opnsense
|
|
|
|
type systemInfoResponse struct {
|
|
System string `json:"system"`
|
|
Plugins []string `json:"plugins"`
|
|
Data struct {
|
|
Interfaces []struct {
|
|
Inpkts string `json:"inpkts"`
|
|
Outpkts string `json:"outpkts"`
|
|
Inbytes string `json:"inbytes"`
|
|
Outbytes string `json:"outbytes"`
|
|
InbytesFrmt string `json:"inbytes_frmt"`
|
|
OutbytesFrmt string `json:"outbytes_frmt"`
|
|
Inerrs string `json:"inerrs"`
|
|
Outerrs string `json:"outerrs"`
|
|
Collisions string `json:"collisions"`
|
|
Descr string `json:"descr"`
|
|
Name string `json:"name"`
|
|
Status string `json:"status"`
|
|
Ipaddr string `json:"ipaddr"`
|
|
Media string `json:"media"`
|
|
} `json:"interfaces"`
|
|
System struct {
|
|
Versions []string `json:"versions"`
|
|
CPU struct {
|
|
Used string `json:"used"`
|
|
User string `json:"user"`
|
|
Nice string `json:"nice"`
|
|
Sys string `json:"sys"`
|
|
Intr string `json:"intr"`
|
|
Idle string `json:"idle"`
|
|
Model string `json:"model"`
|
|
Cpus string `json:"cpus"`
|
|
Cores string `json:"cores"`
|
|
MaxFreq string `json:"max.freq"`
|
|
CurFreq string `json:"cur.freq"`
|
|
FreqTranslate string `json:"freq_translate"`
|
|
Load []string `json:"load"`
|
|
} `json:"cpu"`
|
|
DateFrmt string `json:"date_frmt"`
|
|
DateTime string `json:"date_time"`
|
|
Uptime string `json:"uptime"`
|
|
Config struct {
|
|
LastChange string `json:"last_change"`
|
|
LastChangeFrmt string `json:"last_change_frmt"`
|
|
} `json:"config"`
|
|
Kernel struct {
|
|
Pf struct {
|
|
Maxstates string `json:"maxstates"`
|
|
States string `json:"states"`
|
|
} `json:"pf"`
|
|
Mbuf struct {
|
|
Total string `json:"total"`
|
|
Max string `json:"max"`
|
|
} `json:"mbuf"`
|
|
Memory struct {
|
|
Total string `json:"total"`
|
|
Used string `json:"used"`
|
|
Arc string `json:"arc"`
|
|
ArcTxt string `json:"arc_txt"`
|
|
} `json:"memory"`
|
|
} `json:"kernel"`
|
|
Disk struct {
|
|
Swap []struct {
|
|
Device string `json:"device"`
|
|
Total string `json:"total"`
|
|
Used string `json:"used"`
|
|
} `json:"swap"`
|
|
Devices []struct {
|
|
Device string `json:"device"`
|
|
Type string `json:"type"`
|
|
Size string `json:"size"`
|
|
Used string `json:"used"`
|
|
Available string `json:"available"`
|
|
Capacity string `json:"capacity"`
|
|
Mountpoint string `json:"mountpoint"`
|
|
} `json:"devices"`
|
|
} `json:"disk"`
|
|
Firmware string `json:"firmware"`
|
|
} `json:"system"`
|
|
Temperature []struct {
|
|
Device string `json:"device"`
|
|
DeviceSeq string `json:"device_seq"`
|
|
Temperature string `json:"temperature"`
|
|
Type string `json:"type"`
|
|
TypeTranslated string `json:"type_translated"`
|
|
} `json:"temperature"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
type Temperature struct {
|
|
Device string
|
|
DeviceSeq string
|
|
Type string
|
|
TemperatureCelsuis int
|
|
TemperatureFahrenheit float32
|
|
}
|
|
|
|
type SystemInfo struct {
|
|
Temperature []Temperature
|
|
}
|
|
|
|
func (c *Client) FetchSystemInfo() (SystemInfo, *APICallError) {
|
|
var resp systemInfoResponse
|
|
var data SystemInfo
|
|
|
|
url, ok := c.endpoints["systemInfo"]
|
|
|
|
if !ok {
|
|
return data, &APICallError{
|
|
Endpoint: "system_info",
|
|
Message: "endpoint not found",
|
|
StatusCode: 0,
|
|
}
|
|
}
|
|
|
|
if err := c.do("GET", url, nil, &resp); err != nil {
|
|
return data, err
|
|
}
|
|
|
|
for _, v := range resp.Data.Temperature {
|
|
celsius, err := parseStringToInt(v.Temperature, url)
|
|
if err != nil {
|
|
return data, err
|
|
}
|
|
data.Temperature = append(data.Temperature, Temperature{
|
|
Device: v.Device,
|
|
DeviceSeq: v.DeviceSeq,
|
|
Type: v.Type,
|
|
TemperatureCelsuis: celsius,
|
|
TemperatureFahrenheit: (float32(celsius) * 1.8) + 32,
|
|
})
|
|
}
|
|
|
|
return data, nil
|
|
}
|