Skip to content

Commit

Permalink
client v2
Browse files Browse the repository at this point in the history
  • Loading branch information
STLVRTX committed Jun 17, 2022
1 parent 122240a commit 51e773a
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 22 deletions.
19 changes: 18 additions & 1 deletion alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ var AlertLogEntryTypes = struct {
UserResponseLogEntry: "UserResponseLogEntry",
}

var AlertInclude = struct {
EscalationRules string
NextEscalationUser string
}{
EscalationRules: "escalationRules",
NextEscalationUser: "nextEscalationUser",
}

// // AlertAction definition
// type AlertAction struct {
// Name string `json:"name"`
Expand All @@ -169,6 +177,9 @@ var AlertLogEntryTypes = struct {
type GetAlertInput struct {
_ struct{}
AlertID *int64

// describes optional properties that should be included in the response
Include []*string
}

// GetAlertOutput represents the output of a GetAlert operation.
Expand All @@ -186,7 +197,13 @@ func (c *Client) GetAlert(input *GetAlertInput) (*GetAlertOutput, error) {
return nil, errors.New("Alert id is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%d", apiRoutes.alerts, *input.AlertID))
q := url.Values{}

for _, include := range input.Include {
q.Add("include", *include)
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%d?%s", apiRoutes.alerts, *input.AlertID, q.Encode()))
if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions examples/alert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
var apiToken = "your API token"
var apiToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpbGVydCIsImlsX3QiOiJBUEkiLCJpbF92IjoxLCJpbF9rIjoiOGQ1ODU3NGY5Y2FhNGFlNGE2YmE1ZDVkZjRlNzgzZjYifQ.7rcm1EyqMNmLuuZ1v40ME5eiDL4T0QYGdfaxMQCQ_jY"
client := ilert.NewClient(ilert.WithAPIToken(apiToken))
result, err := client.GetAlerts(&ilert.GetAlertsInput{
States: []*string{ilert.String(ilert.AlertStatuses.Accepted)},
Expand All @@ -22,4 +22,12 @@ func main() {
log.Println(fmt.Sprintf("%+v\n", *alert))
}

// id := int64(your alert id)
// input := &ilert.GetAlertInput{Include: []*string{ilert.String("escalationRules")}, AlertID: &id}
// result, err := client.GetAlert(input)
// if err != nil {
// log.Println(result)
// log.Fatalln("ERROR:", err)
// }
// log.Println(fmt.Sprintf("%+v\n", *result.Alert))
}
2 changes: 1 addition & 1 deletion examples/alertaction/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/alertsource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/automationrules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/connectors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/escalationpolicy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/event/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/heartbeat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/incidents/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/incidenttemplate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/number/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/schedules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/statuspages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/uptimemonitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"

"github.com/iLert/ilert-go"
"github.com/iLert/ilert-go/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/iLert/ilert-go
module github.com/iLert/ilert-go/v2

go 1.16

Expand Down
16 changes: 14 additions & 2 deletions incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ type GetIncidentInput struct {
type GetIncidentOutput struct {
_ struct{}
Incident *Incident
ETag *string
}

// GetIncident gets an incident by ID. https://api.ilert.com/api-docs/#tag/Incidents/paths/~1incidents~1{id}/get
Expand Down Expand Up @@ -241,7 +242,13 @@ func (c *Client) GetIncident(input *GetIncidentInput) (*GetIncidentOutput, error
return nil, err
}

return &GetIncidentOutput{Incident: incident}, nil
output := &GetIncidentOutput{Incident: incident}
etag := resp.Header().Get("ETag")
if etag != "" {
output.ETag = String(etag)
}

return output, nil
}

// GetIncidentSubscribersInput represents the input of a GetIncidentSubscribers operation.
Expand Down Expand Up @@ -372,6 +379,7 @@ type UpdateIncidentInput struct {
_ struct{}
IncidentID *int64
Incident *Incident
ETag *string
}

// UpdateIncidentOutput represents the output of a UpdateIncident operation.
Expand All @@ -394,7 +402,11 @@ func (c *Client) UpdateIncident(input *UpdateIncidentInput) (*UpdateIncidentOutp

url := fmt.Sprintf("%s/%d", apiRoutes.incidents, *input.IncidentID)

resp, err := c.httpClient.R().SetBody(input.Incident).Put(url)
req := c.httpClient.R()
if input.ETag != nil && *input.ETag != "" {
req.SetHeader("If-Match", *input.ETag)
}
resp, err := req.SetBody(input.Incident).Put(url)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ilert

// Version package version
const Version = "v1.6.5"
const Version = "v2.0.0"

0 comments on commit 51e773a

Please sign in to comment.