Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Service Event Rules #304

Merged
merged 9 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 4 additions & 3 deletions command/addon_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"os"
"strings"

"github.com/mitchellh/cli"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
)

type AddonInstall struct {
Expand Down
8 changes: 7 additions & 1 deletion command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
"github.com/mitchellh/cli"
"os"

"github.com/mitchellh/cli"
)

const (
Expand Down Expand Up @@ -69,6 +70,11 @@ func loadCommands() map[string]cli.CommandFactory {
"service integration create": ServiceIntegrationCreateCommand,
"service integration show": ServiceIntegrationShowCommand,
"service integration update": ServiceIntegrationUpdateCommand,
"service rule create": ServiceRuleCreateCommand,
"service rule delete": ServiceRuleDeleteCommand,
"service rule list": ServiceRuleListCommand,
"service rule show": ServiceRuleShowCommand,
"service rule update": ServiceRuleUpdateCommand,

"team list": TeamListCommand,
"team create": TeamShowCommand,
Expand Down
9 changes: 5 additions & 4 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package main
import (
"flag"
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/go-homedir"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/mitchellh/go-homedir"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type ArrayFlags []string
Expand Down
7 changes: 4 additions & 3 deletions command/service_integration_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
"os"
"strings"

"github.com/mitchellh/cli"
"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
)

type ServiceIntegrationCreate struct {
Expand Down
5 changes: 3 additions & 2 deletions command/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"strings"

"github.com/PagerDuty/go-pagerduty"
log "github.com/sirupsen/logrus"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"strings"
)

type ServiceList struct {
Expand Down
28 changes: 28 additions & 0 deletions command/service_rule_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"strings"

"github.com/mitchellh/cli"
)

type ServiceRuleCreate struct {
}

func ServiceRuleCreateCommand() (cli.Command, error) {
return &ServiceRuleCreate{}, nil
}

func (c *ServiceRuleCreate) Help() string {
helpText := `
`
return strings.TrimSpace(helpText)
}

func (c *ServiceRuleCreate) Synopsis() string {
return "Get details about an integration belonging to a service"
}

func (c *ServiceRuleCreate) Run(args []string) int {
return 0
}
28 changes: 28 additions & 0 deletions command/service_rule_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"strings"

"github.com/mitchellh/cli"
)

type ServiceRuleDelete struct {
}

func ServiceRuleDeleteCommand() (cli.Command, error) {
return &ServiceRuleDelete{}, nil
}

func (c *ServiceRuleDelete) Help() string {
helpText := `
`
return strings.TrimSpace(helpText)
}

func (c *ServiceRuleDelete) Synopsis() string {
return "Get details about an integration belonging to a service"
}

func (c *ServiceRuleDelete) Run(args []string) int {
return 0
}
65 changes: 65 additions & 0 deletions command/service_rule_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"context"
"fmt"
"strings"

"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type ServiceRuleList struct {
Meta
}

func ServiceRuleListCommand() (cli.Command, error) {
return &ServiceRuleList{}, nil
}

func (c *ServiceRuleList) Help() string {
helpText := `
pd service rules list <SERVICE_ID> List rules for service
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}

func (c *ServiceRuleList) Synopsis() string {
return "List existing Rules for a service"
}

func (c *ServiceRuleList) Run(args []string) int {
flags := c.Meta.FlagSet("service rules list")
flags.Usage = func() { fmt.Println(c.Help()) }
if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
if len(flags.Args()) != 1 {
log.Error("Please specify service id")
return -1
}
log.Info("Service id is:", flags.Arg(0))

client := c.Meta.Client()
if rulesList, err := client.ListServiceRulesPaginated(context.Background(), flags.Arg(0)); err != nil {
log.Error(err)
return -1
} else {
for i, rule := range rulesList {
fmt.Println("Entry: ", i+1)
data, err := yaml.Marshal(rule)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
}
}
return 0
}
63 changes: 63 additions & 0 deletions command/service_rule_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"context"
"fmt"
"strings"

"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

type ServiceRuleShow struct {
Meta
}

func ServiceRuleShowCommand() (cli.Command, error) {
return &ServiceRuleShow{}, nil
}

func (c *ServiceRuleShow) Help() string {
helpText := `
pd service rules show <SERVICE_ID> <RULE_ID> Show specific service
` + c.Meta.Help()
return strings.TrimSpace(helpText)
}

func (c *ServiceRuleShow) Synopsis() string {
return "Get details about an existing service rule"
}

func (c *ServiceRuleShow) Run(args []string) int {
flags := c.Meta.FlagSet("service rules show")
flags.Usage = func() { fmt.Println(c.Help()) }
if err := flags.Parse(args); err != nil {
log.Error(err)
return -1
}
if err := c.Meta.Setup(); err != nil {
log.Error(err)
return -1
}
if len(flags.Args()) != 2 {
log.Error("Please specify service id and rule id")
return -1
}
log.Info("Service id is:", flags.Arg(0))
log.Info("Rule id is:", flags.Arg(1))

client := c.Meta.Client()
rule, err := client.GetServiceRule(context.Background(), flags.Arg(0), flags.Arg(1))
if err != nil {
log.Error(err)
return -1
}
data, err := yaml.Marshal(rule)
if err != nil {
log.Error(err)
return -1
}
fmt.Println(string(data))
return 0
}
28 changes: 28 additions & 0 deletions command/service_rule_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"strings"

"github.com/mitchellh/cli"
)

type ServiceRuleUpdate struct {
}

func ServiceRuleUpdateCommand() (cli.Command, error) {
return &ServiceRuleUpdate{}, nil
}

func (c *ServiceRuleUpdate) Help() string {
helpText := `
`
return strings.TrimSpace(helpText)
}

func (c *ServiceRuleUpdate) Synopsis() string {
return "Get details about an integration belonging to a service"
}

func (c *ServiceRuleUpdate) Run(args []string) int {
return 0
}
14 changes: 10 additions & 4 deletions ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ type ListRulesetRulesResponse struct {

// RuleActions represents a rule action
type RuleActions struct {
Suppress *RuleActionSuppress `json:"suppress,omitempty"`
Annotate *RuleActionParameter `json:"annotate,omitempty"`
Severity *RuleActionParameter `json:"severity,omitempty"`
Priority *RuleActionParameter `json:"priority,omitempty"`
Route *RuleActionParameter `json:"route"`
EventAction *RuleActionParameter `json:"event_action,omitempty"`
Extractions []*RuleActionExtraction `json:"extractions,omitempty"`
Priority *RuleActionParameter `json:"priority,omitempty"`
Severity *RuleActionParameter `json:"severity,omitempty"`
Suppress *RuleActionSuppress `json:"suppress,omitempty"`
Suspend *RuleActionSuspend `json:"suspend,omitempty"`
Route *RuleActionParameter `json:"route"`
theckman marked this conversation as resolved.
Show resolved Hide resolved
}

// RuleActionParameter represents a generic parameter object on a rule action
Expand All @@ -126,6 +127,11 @@ type RuleActionSuppress struct {
ThresholdTimeAmount int `json:"threshold_time_amount,omitempty"`
}

// RuleActionSuspend represents a rule suspend action object
type RuleActionSuspend struct {
Value bool `json:"value,omitempty"`
theckman marked this conversation as resolved.
Show resolved Hide resolved
}

// RuleActionExtraction represents a rule extraction action object
type RuleActionExtraction struct {
Target string `json:"target,omitempty"`
Expand Down
Loading