Skip to content

Commit

Permalink
feat: add events API endpoint interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin120 committed Jan 23, 2024
1 parent 156185c commit 022692f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package api

import "github.com/maas/gomaasclient/entity"

// Events is an interface for node events
type Events interface {
Get(params *entity.EventParams) (*entity.EventResp, error)
}
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func constructClient(apiClient *APIClient) *Client {
DNSResources: &DNSResources{APIClient: *apiClient},
DNSResourceRecord: &DNSResourceRecord{APIClient: *apiClient},
DNSResourceRecords: &DNSResourceRecords{APIClient: *apiClient},
Events: &Events{APIClient: *apiClient},
Fabric: &Fabric{APIClient: *apiClient},
Fabrics: &Fabrics{APIClient: *apiClient},
VLAN: &VLAN{APIClient: *apiClient},
Expand Down Expand Up @@ -105,6 +106,7 @@ type Client struct {
DNSResourceRecords api.DNSResourceRecords
Domain api.Domain
Domains api.Domains
Events api.Events
Fabric api.Fabric
Fabrics api.Fabrics
VLAN api.VLAN
Expand Down
32 changes: 32 additions & 0 deletions client/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package client

import (
"encoding/json"

"github.com/google/go-querystring/query"
"github.com/maas/gomaasclient/entity"
)

// Events implements api.Events
type Events struct {
APIClient APIClient
}

func (e *Events) client() APIClient {
return e.APIClient.GetSubObject("events")
}

// Get events for nodes
func (e *Events) Get(params *entity.EventParams) (*entity.EventResp, error) {
qsp, err := query.Values(params)
if err != nil {
return nil, err
}

events := &entity.EventResp{}
err = e.client().Get("query", qsp, func(data []byte) error {
return json.Unmarshal(data, events)
})

return events, err
}
2 changes: 2 additions & 0 deletions entity/event/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package event contains entities related to events.
package event
13 changes: 13 additions & 0 deletions entity/event/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package event

// LogLevel correlates to a log level for MAAS events.
type LogLevel string

const (
AUDIT LogLevel = "AUDIT"
CRITICAL LogLevel = "CRITICAL"
DEBUG LogLevel = "DEBUG"
ERROR LogLevel = "ERROR"
WARNING LogLevel = "WARNING"
INFO LogLevel = "INFO"
)
35 changes: 35 additions & 0 deletions entity/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package entity

import "github.com/maas/gomaasclient/entity/event"

// Event represent an event for MAAS node
type Event struct {
UserName string `json:"username,omitempty"`
Node string `json:"node,omitempty"`
Hostname string `json:"hostname,omitempty"`
Created string `json:"created,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Level string `json:"level,omitempty"`
ID int `json:"id,omitempty"`
}

// EventResp represents the MAAS Events endpoint
type EventResp struct {

Check failure on line 18 in entity/events.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 16 pointer bytes could be 8 (govet)
Count int `json:"count,omitempty"`
Events []Event `json:"events,omitempty"`
}

// EventParams enumerates the parameters for the event get operation
type EventParams struct {
Hostname string `url:"hostname,omitempty"`
MACAddress string `url:"mac_address,omitempty"`
ID string `url:"id,omitempty"`
Zone string `url:"zone,omitempty"`
AgentName string `url:"agent_name,omitempty"`
Limit string `url:"limit,omitempty"`
Before string `url:"before,omitempty"`
After string `url:"after,omitempty"`
Owner string `url:"owner,omitempty"`
Level event.LogLevel `url:"level,omitempty"`
}

0 comments on commit 022692f

Please sign in to comment.