Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
652 changes: 343 additions & 309 deletions docs/gen/gen.md

Large diffs are not rendered by default.

73 changes: 46 additions & 27 deletions docs/gen/osapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ resp, err := client.Node.Exec(ctx, osapi.ExecRequest{
- [type Response](<#Response>)
- [func NewResponse\[T any\]\(data T, rawJSON \[\]byte\) \*Response\[T\]](<#NewResponse>)
- [func \(r \*Response\[T\]\) RawJSON\(\) \[\]byte](<#Response[T].RawJSON>)
- [type Route](<#Route>)
- [type ServerError](<#ServerError>)
- [func \(e \*ServerError\) Unwrap\(\) error](<#ServerError.Unwrap>)
- [type ShellRequest](<#ShellRequest>)
Expand Down Expand Up @@ -151,32 +152,34 @@ func (e *APIError) Error() string
Error returns a formatted error string.

<a name="Agent"></a>
## type [Agent](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L30-L51>)
## type [Agent](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L30-L53>)

Agent represents a registered OSAPI agent.

```go
type Agent struct {
Hostname string
Status string
State string
Labels map[string]string
Architecture string
CPUCount int
Fqdn string
KernelVersion string
PackageMgr string
ServiceMgr string
LoadAverage *LoadAverage
Memory *Memory
OSInfo *OSInfo
Interfaces []NetworkInterface
Conditions []Condition
Timeline []TimelineEvent
Uptime string
StartedAt time.Time
RegisteredAt time.Time
Facts map[string]any
Hostname string
Status string
State string
Labels map[string]string
Architecture string
CPUCount int
Fqdn string
KernelVersion string
PackageMgr string
ServiceMgr string
LoadAverage *LoadAverage
Memory *Memory
OSInfo *OSInfo
PrimaryInterface string
Interfaces []NetworkInterface
Routes []Route
Conditions []Condition
Timeline []TimelineEvent
Uptime string
StartedAt time.Time
RegisteredAt time.Time
Facts map[string]any
}
```

Expand All @@ -195,7 +198,7 @@ type AgentJobResponse struct {
```

<a name="AgentList"></a>
## type [AgentList](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L62-L65>)
## type [AgentList](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L64-L67>)

AgentList is a collection of agents.

Expand Down Expand Up @@ -462,7 +465,7 @@ type ComponentHealth struct {
```

<a name="Condition"></a>
## type [Condition](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L54-L59>)
## type [Condition](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L56-L61>)

Condition represents a node condition evaluated agent\-side.

Expand Down Expand Up @@ -824,7 +827,7 @@ type ListParams struct {
```

<a name="LoadAverage"></a>
## type [LoadAverage](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L77-L81>)
## type [LoadAverage](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L89-L93>)

LoadAverage represents system load averages.

Expand All @@ -850,7 +853,7 @@ type LoadResult struct {
```

<a name="Memory"></a>
## type [Memory](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L84-L88>)
## type [Memory](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L96-L100>)

Memory represents memory usage information.

Expand Down Expand Up @@ -919,7 +922,7 @@ type NATSInfo struct {
```

<a name="NetworkInterface"></a>
## type [NetworkInterface](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L68-L74>)
## type [NetworkInterface](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L70-L76>)

NetworkInterface represents a network interface on an agent.

Expand Down Expand Up @@ -1090,7 +1093,7 @@ func (e *NotFoundError) Unwrap() error
Unwrap returns the underlying APIError.

<a name="OSInfo"></a>
## type [OSInfo](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L91-L94>)
## type [OSInfo](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L103-L106>)

OSInfo represents operating system information.

Expand Down Expand Up @@ -1216,6 +1219,22 @@ func (r *Response[T]) RawJSON() []byte

RawJSON returns the raw HTTP response body.

<a name="Route"></a>
## type [Route](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/agent_types.go#L79-L86>)

Route represents a network routing table entry.

```go
type Route struct {
Destination string
Gateway string
Interface string
Mask string
Flags string
Metric int
}
```

<a name="ServerError"></a>
## type [ServerError](<https://github.com/osapi-io/osapi-sdk/blob/main/pkg/osapi/errors.go#L71-L73>)

Expand Down
83 changes: 63 additions & 20 deletions pkg/osapi/agent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ import (

// Agent represents a registered OSAPI agent.
type Agent struct {
Hostname string
Status string
State string
Labels map[string]string
Architecture string
CPUCount int
Fqdn string
KernelVersion string
PackageMgr string
ServiceMgr string
LoadAverage *LoadAverage
Memory *Memory
OSInfo *OSInfo
Interfaces []NetworkInterface
Conditions []Condition
Timeline []TimelineEvent
Uptime string
StartedAt time.Time
RegisteredAt time.Time
Facts map[string]any
Hostname string
Status string
State string
Labels map[string]string
Architecture string
CPUCount int
Fqdn string
KernelVersion string
PackageMgr string
ServiceMgr string
LoadAverage *LoadAverage
Memory *Memory
OSInfo *OSInfo
PrimaryInterface string
Interfaces []NetworkInterface
Routes []Route
Conditions []Condition
Timeline []TimelineEvent
Uptime string
StartedAt time.Time
RegisteredAt time.Time
Facts map[string]any
}

// Condition represents a node condition evaluated agent-side.
Expand All @@ -73,6 +75,16 @@ type NetworkInterface struct {
MAC string
}

// Route represents a network routing table entry.
type Route struct {
Destination string
Gateway string
Interface string
Mask string
Flags string
Metric int
}

// LoadAverage represents system load averages.
type LoadAverage struct {
OneMin float32
Expand Down Expand Up @@ -134,6 +146,37 @@ func agentFromGen(
a.Memory = memoryFromGen(g.Memory)
a.OSInfo = osInfoFromGen(g.OsInfo)

if g.PrimaryInterface != nil {
a.PrimaryInterface = *g.PrimaryInterface
}

if g.Routes != nil {
routes := make([]Route, 0, len(*g.Routes))
for _, r := range *g.Routes {
route := Route{
Destination: r.Destination,
Gateway: r.Gateway,
Interface: r.Interface,
}

if r.Mask != nil {
route.Mask = *r.Mask
}

if r.Flags != nil {
route.Flags = *r.Flags
}

if r.Metric != nil {
route.Metric = *r.Metric
}

routes = append(routes, route)
}

a.Routes = routes
}

if g.Interfaces != nil {
ifaces := make([]NetworkInterface, 0, len(*g.Interfaces))
for _, iface := range *g.Interfaces {
Expand Down
27 changes: 27 additions & 0 deletions pkg/osapi/agent_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (suite *AgentTypesTestSuite) TestAgentFromGen() {
kernelVersion := "5.15.0-generic"
packageMgr := "apt"
serviceMgr := "systemd"
primaryIface := "eth0"
routeMask := "255.255.255.0"
routeFlags := "UG"
routeMetric := 100
uptime := "5d 3h 22m"
family := gen.NetworkInterfaceResponseFamily("inet")
ipv4 := "192.168.1.10"
Expand Down Expand Up @@ -89,6 +93,7 @@ func (suite *AgentTypesTestSuite) TestAgentFromGen() {
Distribution: "Ubuntu",
Version: "22.04",
},
PrimaryInterface: &primaryIface,
Interfaces: &[]gen.NetworkInterfaceResponse{
{
Name: "eth0",
Expand All @@ -98,6 +103,16 @@ func (suite *AgentTypesTestSuite) TestAgentFromGen() {
Mac: &mac,
},
},
Routes: &[]gen.RouteResponse{
{
Destination: "0.0.0.0",
Gateway: "192.168.1.1",
Interface: "eth0",
Mask: &routeMask,
Flags: &routeFlags,
Metric: &routeMetric,
},
},
Uptime: &uptime,
StartedAt: &startedAt,
RegisteredAt: &now,
Expand Down Expand Up @@ -153,13 +168,23 @@ func (suite *AgentTypesTestSuite) TestAgentFromGen() {
suite.Equal("Ubuntu", a.OSInfo.Distribution)
suite.Equal("22.04", a.OSInfo.Version)

suite.Equal("eth0", a.PrimaryInterface)

suite.Require().Len(a.Interfaces, 1)
suite.Equal("eth0", a.Interfaces[0].Name)
suite.Equal("inet", a.Interfaces[0].Family)
suite.Equal("192.168.1.10", a.Interfaces[0].IPv4)
suite.Equal("fe80::1", a.Interfaces[0].IPv6)
suite.Equal("00:11:22:33:44:55", a.Interfaces[0].MAC)

suite.Require().Len(a.Routes, 1)
suite.Equal("0.0.0.0", a.Routes[0].Destination)
suite.Equal("192.168.1.1", a.Routes[0].Gateway)
suite.Equal("eth0", a.Routes[0].Interface)
suite.Equal("255.255.255.0", a.Routes[0].Mask)
suite.Equal("UG", a.Routes[0].Flags)
suite.Equal(100, a.Routes[0].Metric)

suite.Equal("5d 3h 22m", a.Uptime)
suite.Equal(startedAt, a.StartedAt)
suite.Equal(now, a.RegisteredAt)
Expand Down Expand Up @@ -208,7 +233,9 @@ func (suite *AgentTypesTestSuite) TestAgentFromGen() {
suite.Nil(a.LoadAverage)
suite.Nil(a.Memory)
suite.Nil(a.OSInfo)
suite.Empty(a.PrimaryInterface)
suite.Nil(a.Interfaces)
suite.Nil(a.Routes)
suite.Nil(a.Conditions)
suite.Nil(a.Timeline)
suite.Empty(a.Uptime)
Expand Down
Loading