Skip to content
Open
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
91 changes: 91 additions & 0 deletions _samples/notificationsv2/notification_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

identifier := &notificationv2.Identifier{
UserID: "0",
}

criteria := notificationv2.Criteria{
Type: notificationv2.MatchAllConditionsType,
Conditions: []notificationv2.Condition{
{
Field: notificationv2.ExtraPropertiesField,
Key: "system",
Not: true,
Operation: notificationv2.EqualsConditionOperation,
ExpectedValue: "mysql",
},
},
}

startHour := 3
endHour := 15
startMin := 5
endMin := 30

timeRestriction := notificationv2.TimeRestriction{
Type: notificationv2.WeekendAndTimeOfDayTimeRestriction,
Restrictions: []notificationv2.Restriction{
{
StartDay: notificationv2.Monday,
EndDay: notificationv2.Friday,
StartHour: &startHour,
EndHour: &endHour,
StartMin: &startMin,
EndMin: &endMin,
},
},
}

timeAmount := 1
steps := []notificationv2.Step{
{
SendAfter: &notificationv2.SendAfter{
TimeAmount: &timeAmount,
TimeUnit: notificationv2.Minutes,
},
Contact: notificationv2.Contact{
Method: notificationv2.EmailNotifyMethod,
To: "[email protected]",
},
Enabled: true,
},
}

repeat := notificationv2.Repeat{Enabled: false}

response, err := notificationCli.Create(notificationv2.CreateNotificationRequest{
Identifier: identifier,
Name: "Test create-alert",
ActionType: notificationv2.CreateAlertActionType,
Criteria: criteria,
TimeRestriction: &timeRestriction,
Order: 1,
Steps: steps,
Repeat: repeat,
Enabled: true,
})
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf(
"ID: %s, Name: %s, Enabled: %t\n",
response.Notification.ID,
response.Notification.Name,
response.Notification.Enabled,
)
}
}
29 changes: 29 additions & 0 deletions _samples/notificationsv2/notification_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

response, err := notificationCli.Delete(notificationv2.DeleteNotificationRequest{
Identifier: &notificationv2.Identifier{
UserID: "0",
RuleID: "0",
},
})

if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf("Result: %s, Request ID: %s\n", response.Result, response.RequestID)
}
}
29 changes: 29 additions & 0 deletions _samples/notificationsv2/notification_disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

response, err := notificationCli.Disable(notificationv2.DisableNotificationRequest{
Identifier: &notificationv2.Identifier{
UserID: "0",
RuleID: "0",
},
})

if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf("Result: %s, Request ID: %s\n", response.Result, response.RequestID)
}
}
29 changes: 29 additions & 0 deletions _samples/notificationsv2/notification_enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

response, err := notificationCli.Enable(notificationv2.EnableNotificationRequest{
Identifier: &notificationv2.Identifier{
UserID: "0",
RuleID: "0",
},
})

if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf("Result: %s, Request ID: %s\n", response.Result, response.RequestID)
}
}
33 changes: 33 additions & 0 deletions _samples/notificationsv2/notification_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"encoding/json"
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

response, err := notificationCli.Get(notificationv2.GetNotificationRequest{
Identifier: &notificationv2.Identifier{
UserID: "0",
RuleID: "0",
},
})

if err != nil {
fmt.Println(err.Error())
} else {
notification := response.Notification
notificationJson, _ := json.Marshal(notification)

fmt.Println(string(notificationJson))
}
}
29 changes: 29 additions & 0 deletions _samples/notificationsv2/notification_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

response, err := notificationCli.List(notificationv2.ListNotificationRequest{
Identifier: &notificationv2.Identifier{
UserID: "0",
},
})
if err != nil {
fmt.Println(err.Error())
} else {
for i, notification := range response.Notifications {
fmt.Printf("%d. %s\n", i, notification.Name)
}
}
}
72 changes: 72 additions & 0 deletions _samples/notificationsv2/notification_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/notificationv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

notificationCli, _ := cli.NotificationV2()

identifier := &notificationv2.Identifier{
UserID: "0",
RuleID: "0",
}

criteria := notificationv2.Criteria{
Type: notificationv2.MatchAllConditionsType,
Conditions: []notificationv2.Condition{
{
Field: "extra-properties",
Key: "system",
Not: true,
Operation: "equals",
ExpectedValue: "mysql",
},
},
}

startHour := 3
endHour := 15
startMin := 5
endMin := 30

timeRestriction := notificationv2.TimeRestriction{
Type: notificationv2.WeekendAndTimeOfDayTimeRestriction,
Restrictions: []notificationv2.Restriction{
{
StartDay: notificationv2.Monday,
EndDay: notificationv2.Friday,
StartHour: &startHour,
EndHour: &endHour,
StartMin: &startMin,
EndMin: &endMin,
},
},
}

response, err := notificationCli.Update(notificationv2.UpdateNotificationRequest{
Identifier: identifier,
Name: "Test create-alert(changed)",
Criteria: criteria,
TimeRestriction: timeRestriction,
Enabled: true,
Order: 2,
})
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf(
"ID: %s, Name: %s, Enabled: %t\n",
response.Notification.ID,
response.Notification.Name,
response.Notification.Enabled,
)
}
}
42 changes: 42 additions & 0 deletions _samples/usersv2/user_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/userv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

userCli, _ := cli.UserV2()

request := userv2.CreateUserRequest{
UserName: "[email protected]",
FullName: "User Name",
Role: userv2.Role{Name: userv2.UserRole},
SkypeUsername: "user.name",
UserAddress: userv2.UserAddress{
Country: "US",
State: "Indiana",
City: "Terre Haute",
Line: "567 Stratford Park",
ZipCode: "47802",
},
Tags: userv2.Tags{"advanced", "marked"},
Details: userv2.Details{"detail1key": []string{"detail1dvalue1", "detail1value2"}},
Timezone: "Europe/Moscow",
Locale: "en_US",
InvitationDisabled: false,
}

response, err := userCli.Create(request)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Id: %s, username: %#v\n", response.Data.ID, response.Data.Name)
}
}
27 changes: 27 additions & 0 deletions _samples/usersv2/user_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"

"github.com/opsgenie/opsgenie-go-sdk/_samples/constants"
ogcli "github.com/opsgenie/opsgenie-go-sdk/client"
"github.com/opsgenie/opsgenie-go-sdk/userv2"
)

func main() {
cli := new(ogcli.OpsGenieClient)
cli.SetAPIKey(constants.APIKey)

userCli, _ := cli.UserV2()

request := userv2.DeleteUserRequest{
Identifier: &userv2.Identifier{UserName: "[email protected]"},
}

response, err := userCli.Delete(request)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(response.Result)
}
}
Loading