opnsense-exporter/opnsense/services.go
ihatemodels 24e8161262 Add initial project structure
- 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
2023-11-26 16:06:03 +02:00

72 lines
1.4 KiB
Go

package opnsense
type servicesSearchResponse struct {
Total int `json:"total"`
RowCount int `json:"rowCount"`
Current int `json:"current"`
Rows []struct {
ID string `json:"id"`
Locked int `json:"locked"`
Running int `json:"running"`
Description string `json:"description"`
Name string `json:"name"`
} `json:"rows"`
}
type ServiceStatus int
const (
ServiceStatusStopped ServiceStatus = iota
ServiceStatusRunning
ServiceStatusUnknown
)
type Service struct {
Status ServiceStatus
Description string
Name string
}
type Services struct {
TotalRunning int
TotalStopped int
Services []Service
}
func (c *Client) FetchServices() (Services, *APICallError) {
var resp servicesSearchResponse
var services Services
url, ok := c.endpoints["services"]
if !ok {
return services, &APICallError{
Endpoint: "services",
Message: "endpoint not found",
StatusCode: 0,
}
}
err := c.do("GET", url, nil, &resp)
if err != nil {
return services, err
}
for _, service := range resp.Rows {
switch service.Running {
case 0:
services.TotalStopped++
case 1:
services.TotalRunning++
}
s := Service{
Status: ServiceStatus(service.Running),
Description: service.Description,
Name: service.Name,
}
services.Services = append(services.Services, s)
}
return services, nil
}