Skip to content

Commit

Permalink
Merge pull request #5 from dnwe/housekeeping
Browse files Browse the repository at this point in the history
chore: bump go-pagerduty to latest version
  • Loading branch information
frese authored Oct 6, 2022
2 parents 5861b2e + e71025e commit 8a68150
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 49 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/trustpilot/pagerduty-notifier
go 1.13

require (
github.com/PagerDuty/go-pagerduty v1.1.2
github.com/go-ini/ini v1.55.0
github.com/PagerDuty/go-pagerduty v1.5.0
github.com/go-ini/ini v1.66.4
github.com/shurcooL/trayhost v0.0.0-20181020202213-114974ef9e16
github.com/smartystreets/goconvey v1.6.4 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
)

require github.com/google/go-querystring v1.1.0 // indirect
34 changes: 14 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
github.com/PagerDuty/go-pagerduty v1.1.2 h1:pTY5GKmmR88EeeI+9/LR+dKL2Chohz3L5yroqoUl+lQ=
github.com/PagerDuty/go-pagerduty v1.1.2/go.mod h1:ZKUzEnyuEMTCMwuzP5NyQIwPx+ThSKBNUva2/ns0Op8=
github.com/PagerDuty/go-pagerduty v1.5.0 h1:/p8FGD32G8HGm7MQIjlTPTGXRJ62Qkm8Lmt5BcUVJOo=
github.com/PagerDuty/go-pagerduty v1.5.0/go.mod h1:txr8VbObXdk2RkqF+C2an4qWssdGY99fK26XYUDjh+4=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-ini/ini v1.55.0 h1:0wVcG9udk2C3TGgmdIGKK9ScOZHZB5nbG+gwji9fhhc=
github.com/go-ini/ini v1.55.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/go-ini/ini v1.66.4 h1:dKjMqkcbkzfddhIhyglTPgMoJnkvmG+bSLrU9cTHc5M=
github.com/go-ini/ini v1.66.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/shurcooL/trayhost v0.0.0-20181020202213-114974ef9e16 h1:7EdFnfVUAu1Rv5bNVjaygc2dWu7RiZV804h3qOJtlbM=
github.com/shurcooL/trayhost v0.0.0-20181020202213-114974ef9e16/go.mod h1:jCGK0NF4lbbRrPGyl1Eonb4Xicbeiy2Ry6okvvZWlnQ=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.55.0 h1:E8yzL5unfpW3M6fz/eB7Cb5MQAYSZ7GKo4Qth+N2sgQ=
gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
52 changes: 27 additions & 25 deletions src/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -45,8 +46,11 @@ func pdInit(cfg *ini.File) {
}
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2)
defer cancel()

// get team ids
teamList, err := pd.ListTeams(pagerduty.ListTeamOptions{Query: ""})
teamList, err := pd.ListTeamsWithContext(ctx, pagerduty.ListTeamOptions{Query: ""})
if err != nil {
log.Println("Error: Cannot retrieve teams from Pagerduty API")
os.Exit(1)
Expand All @@ -63,7 +67,7 @@ func pdInit(cfg *ini.File) {
}

// get use ids
userList, err := pd.ListUsers(pagerduty.ListUsersOptions{Query: ""})
userList, err := pd.ListUsersWithContext(ctx, pagerduty.ListUsersOptions{Query: ""})
if err != nil {
log.Println("Error: Cannot retrieve user list from Pagerduty API")
os.Exit(1)
Expand All @@ -87,17 +91,15 @@ func pdInit(cfg *ini.File) {

ok := true
opts := pagerduty.ListServiceOptions{
APIListObject: pagerduty.APIListObject{
Limit: 25,
Offset: 0,
},
Limit: 25,
Offset: 0,
}

for k := range serviceConf {
for ok {
// get service ids that match given name
opts.Query = k
serviceList, err := pd.ListServices(opts)
serviceList, err := pd.ListServicesWithContext(ctx, opts)
if err != nil {
log.Println("Error: Cannot retrieve service list from Pagerduty API")
os.Exit(1)
Expand Down Expand Up @@ -135,7 +137,7 @@ func pdGetIncidents(cfg *ini.File) []pagerduty.Incident {
INCIDENTS:
for _, i := range pdGetIncidentsSince(lastdate) {
lastdate, _ = time.Parse(time.RFC3339, i.CreatedAt)
log.Printf("Incident: %s", i.APIObject.Summary)
log.Printf("Incident: %s", i.Summary)
for _, team := range i.Teams {
log.Printf("Team: %s", team.Summary)
}
Expand All @@ -149,16 +151,16 @@ INCIDENTS:
switch filter.property {
case "service":
if (filter.notmatch && (i.Service.Summary != filter.match)) || (!filter.notmatch && (i.Service.Summary == filter.match)) {
if filter.filter.Find([]byte(i.APIObject.Summary)) != nil {
log.Printf("Included - service:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.APIObject.Summary)
if filter.filter.Find([]byte(i.Summary)) != nil {
log.Printf("Included - service:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.Summary)
goto EXCLUDES
}
}
case "team":
for _, t := range i.Teams {
if (filter.notmatch && (t.Summary != filter.match)) || (!filter.notmatch && (t.Summary == filter.match)) {
if filter.filter.Find([]byte(i.APIObject.Summary)) != nil {
log.Printf("Included - team:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.APIObject.Summary)
if filter.filter.Find([]byte(i.Summary)) != nil {
log.Printf("Included - team:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.Summary)
goto EXCLUDES
}
}
Expand All @@ -175,16 +177,16 @@ INCIDENTS:
switch filter.property {
case "service":
if (filter.notmatch && i.Service.Summary != filter.match) || (!filter.notmatch && (i.Service.Summary == filter.match)) {
if filter.filter.Find([]byte(i.APIObject.Summary)) != nil {
log.Printf("Excluded - service:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.APIObject.Summary)
if filter.filter.Find([]byte(i.Summary)) != nil {
log.Printf("Excluded - service:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.Summary)
continue INCIDENTS
}
}
case "team":
for _, t := range i.Teams {
if (filter.notmatch && t.Summary != filter.match) || (!filter.notmatch && (t.Summary == filter.match)) {
if filter.filter.Find([]byte(i.APIObject.Summary)) != nil {
log.Printf("Excluded - team:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.APIObject.Summary)
if filter.filter.Find([]byte(i.Summary)) != nil {
log.Printf("Excluded - team:%v, notmatch: %t, alert:<%s>", filter.match, filter.notmatch, i.Summary)
continue INCIDENTS
}
}
Expand All @@ -203,35 +205,35 @@ INCIDENTS:
}

func pdGetIncidentsSince(since time.Time) []pagerduty.Incident {

incidents := make([]pagerduty.Incident, 0)

opts := pagerduty.ListIncidentsOptions{
Limit: 25,
Offset: 0,
Since: since.Format(time.RFC3339),
Statuses: statuses,
TeamIDs: teamIDs,
UserIDs: userIDs,
ServiceIDs: serviceIDs,
SortBy: "created_at:ASC",
TimeZone: "UTC",
APIListObject: pagerduty.APIListObject{
Limit: 25,
Offset: 0,
},
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2)
defer cancel()

ok := true
for ok {
log.Printf("API query since: %s, Limit: %v Offset: %v", since, opts.APIListObject.Limit, opts.APIListObject.Offset)
resp, err := pd.ListIncidents(opts)
log.Printf("API query since: %s, Limit: %v Offset: %v", since, opts.Limit, opts.Offset)
resp, err := pd.ListIncidentsWithContext(ctx, opts)
if err != nil {
log.Println("Error: Cannot list incidents from Pagerduty API:", err)
return incidents
}
ok = resp.APIListObject.More
ok = resp.More
log.Printf("Got %d incidents", len(resp.Incidents))
incidents = append(incidents, resp.Incidents...)
opts.APIListObject.Offset = opts.APIListObject.Offset + opts.APIListObject.Limit
opts.Offset = opts.Offset + opts.Limit
}
log.Printf("Returning %d incidents total.", len(incidents))
return incidents
Expand Down

0 comments on commit 8a68150

Please sign in to comment.