heimweh / go-pagerduty Goto Github PK
View Code? Open in Web Editor NEWPagerDuty API client (used by the PagerDuty provider in Terraform)
License: Mozilla Public License 2.0
PagerDuty API client (used by the PagerDuty provider in Terraform)
License: Mozilla Public License 2.0
Having NumLoops
serialized as json:"num_loops,omitempty"
prevents resetting its value to zero:
We have run into an issue when using this in the PagerDuty Terraform provider we get malformed URLs when a request with a query string is rate limited.
In our specific case it was a call to /members?offset=100 would result in /members?offset=100?offset=100 on the retry, which would cause a 400 to be returned.
Fixed by this PR: #145
Jut curious if we can override the schedules with PagerDuty API, thanks!!
It is now possible via the pagerduty API to manage response plays being added to a service. In particular, it would be useful to be able to manage this via the terraform provider and implement PagerDuty/terraform-provider-pagerduty#400
I've also put together a simple PR that I think will add this support; #90. I'd be grateful for any feedback around this and pointers if I've missed anything
ListSchedulesOptions
doesn't currently have a way to pull ScheduledLayers on the Schedule object. Can this be included in the options as flag please? ๐
Once in a while the test case TestListAllWithLicenses
fails with the following ouput...
==> Testing go-pagerduty
2023/05/30 16:16:27 ===== PagerDuty Cache Skipping Init =====
2023/05/30 16:16:27 ==== Getting users at offset 0
2023/05/30 16:16:27 ==== Getting users at offset 1
2023/05/30 16:16:27 ==== Getting license_allocations at offset 0
2023/05/30 16:16:27 ==== Getting license_allocations at offset 1
--- FAIL: TestListAllWithLicenses (0.00s)
user_test.go:264: returned []*pagerduty.User{(*pagerduty.User)(0x14000252140), (*pagerduty.User)(0x14000252000)}; want []*pagerduty.User{(*pagerduty.User)(0x14000252280), (*pagerduty.User)(0x140002523c0)}
FAIL
FAIL github.com/heimweh/go-pagerduty/pagerduty 0.171s
FAIL
make: *** [test] Error 1
The API for https://api.pagerduty.com/escalation_policies
supports setting on_call_handoff_notifications
, but this is not exposed in Terraform. Which always ends up as the default if_has_services
.
We'll like to override this default and set to always
, however this seems to be missing from the Go library too.
Example resource for this setting would be:
resource "pagerduty_escalation_policy" "example" {
name = "Engineering Escalation Policy"
num_loops = 2
teams = [pagerduty_team.example.id]
on_call_handoff_notifications = "always"
rule {
escalation_delay_in_minutes = 10
target {
type = "user_reference"
id = pagerduty_user.example.id
}
target {
type = "user_reference"
id = pagerduty_user.example2.id
}
}
}
Escalation rules have assignment strategies that can be used to define "round robin" or "assign to everyone".
We can configure this in the UI but the fields are not documented in the API reference.
By inspecting network calls when editing policies in the UI we can see the field in play though. When querying the API endpoint with escalation_rule_assignment_strategies
as an include we can see the current value.
// https://api.pagerduty.com/escalation_policies?include%5B%5D=escalation_rule_assignment_strategies
{
"escalation_policies": [
{
"id": "MASKED_ID_1",
"type": "escalation_policy",
// ...
"escalation_rules": [
{
"id": "MASKED_ID_2",
// ...
"escalation_rule_assignment_strategy": {
"type": "assign_to_everyone"
}
}
],
// ...
},
{
"id": "MASKED_ID_3",
"type": "escalation_policy",
// ...
"escalation_rules": [
{
"id": "MASKED_ID_4",
// ...
"escalation_rule_assignment_strategy": {
"type": "round_robin"
}
}
],
// ...
}
],
// ...
}
We can also modify it as usual with a PUT request
curl 'https://api.pagerduty.com/escalation_policies/PE3BU60' \
-X 'PUT' \
-H "authorization: Token token=$PAGERDUTY_API_TOKEN" \
-H 'content-type: application/json' \
--data-raw '{
"escalation_policy": {
"id": "MASKED_ID_1",
// ...
"escalation_rules": [
{
"id": "MASKED_ID_2",
// ...
"escalation_rule_assignment_strategy": {
"type": "round_robin"
}
}
],
// ...
}
}'
Would it be possible to add this field to the library specifically to enable PagerDuty/terraform-provider-pagerduty#518? I'd be happy to provide a PR.
Hello, I just tried to create an escalation policies with terraform and I got this error:
Error: POST API call to https://api.pagerduty.com/escalation_policies failed 404 Not Found. Code: 2100, Errors: <nil>, Message: Not Found
Reading the source code there:
I can see that the endpoint used is effectively /escalation_policies
Reading the documention there, https://api-reference.pagerduty.com/#!/Escalation_Policies/get_escalation_policies, the correct endpoint seems to be /escalation
Could you confirm the issue ?
Did Pagerduty changed there api ?
Thanks for you help
I'd love to see support for Service Extensions in the Go SDK. This is particularly a blocker for the Terraform PD provider.
terraform-providers/terraform-provider-pagerduty#46
I am looking to IaC the slack and slack_v2 extension, looking at the documentation in the website, https://www.terraform.io/docs/providers/pagerduty/r/extension.html, there is no way that I can map to something as below:
"config": {
"notify_types": {
"resolve": true,
"trigger": true,
"escalate": true,
"acknowledge": true,
"assignments": true,
"annotate": true
},
"urgency": {
"high": true,
"low": true
},
"referer": "https://meetup.pagerduty.com/services/zzz/integrations",
"ok": true,
"scope": "identify,bot,commands,incoming-webhook,channels:read,groups:read,im:read,team:read,users:read,users:read.email,channels:write,chat:write:user,chat:write:bot,groups:write",
"user_id": "sss",
"team_id": "xxx",
"enterprise_id": null,
"team_name": "meetup",
"incoming_webhook": {
"channel": "#android",
"channel_id": "C03T7F23S",
"configuration_url": "https://meetuphq.slack.com/services/kkk",
"url": "https://hooks.slack.com/services/kkk/ddd/bbb"
},
"bot": {
"bot_user_id": "xxx"
}
},
"extension_schema": {
"id": "PII3QUR",
"type": "extension_schema_reference",
"summary": "Slack V2",
"self": "https://api.pagerduty.com/extension_schemas/PII3QUR",
"html_url": null
},
Is there any type definition in plan for slack and slack_v2 (I think those two are the most popular extensions, right?).
Thanks!
Could you at least give me any comment? This is a small change that would fix some of my issues. If I need to do sth more please tell me.
#38
We can see issue with plan for our services because it fail with error message:
โ Error: timeout while waiting for state to become 'success' (timeout: 2m0s)
โ
โ with pagerduty_service.all_services["HSP Silver Pro Restaurant GOOGLE PLAY STORE"],
โ on services.tf line 31, in resource "pagerduty_service" "all_services":
โ 31: resource "pagerduty_service" "all_services" {
โ
True is that we try to control 152 services in one loop and probably 2m0s timeout is not enough. It it possible to somehow increase this threshold please?
Thanks a lot.
I have some issue run the example specified in the README.
Here is what I experienced, I tried to install the package, go get github.com/heimweh/go-pagerduty
And then encountered the issue:
$ go get github.com/heimweh/go-pagerduty
can't load package: package github.com/heimweh/go-pagerduty: no Go files in /Users/rchen/go/src/github.com/heimweh/go-pagerduty
Then I tried, go get github.com/heimweh/go-pagerduty/pagerduty
, seems working. But when I tried to run the program, I have issue:
`main.go` import section:
import (
"fmt"
pagerduty "github.com/heimweh/go-pagerduty"
)
$ go run main.go
main.go:6:2: no Go files in /Users/rchen/go/src/github.com/heimweh/go-pagerduty
The "Disabled" field of the Rule struct is defined with the annotation json:"disabled,omitempty"
. This leads to the field not being marshalled when we make a request to the PagerDuty API. This issue impacts PagerDuty/terraform-provider-pagerduty#250.
The bool fields of a Rule should be made pointers to distinguish between nil and false values.
Currently the client doesn't support enabling the processing of events for a service via orchestrations. Having this functionality in the underlying client would make possible to configure this property also in the Terraform provider and solve this issue PagerDuty/terraform-provider-pagerduty#565
Hi! The API supports pagination for extension ressources:
https://developer.pagerduty.com/api-reference/b3A6Mjc0ODEzMg-list-extensions
There is no coverage for this functionality in the code yet.
// ListExtensionsOptions represents options when listing extensions.
type ListExtensionsOptions struct {
ExtensionObjectID string `url:"extension_object_id,omitempty"`
Query string `url:"query,omitempty"`
ExtensionSchemaID string `url:"extension_schema_id,omitempty"`
Include []string `url:"include,omitempty,brackets"`
}
It seems like business service list request is not paginated. It is not passing offset
parameter here:
https://github.com/heimweh/go-pagerduty/blob/master/pagerduty/business_service.go#L48
// List lists existing business services.
func (s *BusinessServiceService) List() (*ListBusinessServicesResponse, *Response, error) {
u := "/business_services"
v := new(ListBusinessServicesResponse)
resp, err := s.client.newRequestDo("GET", u, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
I saw this issue using Terraform Pagerduty Provider. I have a high number of business services. The last ones I added are created on Terraform but provider cannot find them.
Checking the pagerduty provider, it is calling this lib to list all business services and then finding match one here:
Since the very first commit, there is a Service
attribute in the Service
struct:
// Service represents a service.
type Service struct {
AcknowledgementTimeout int `json:"acknowledgement_timeout,omitempty"`
Addons []*AddonReference `json:"addons,omitempty"`
AlertCreation string `json:"alert_creation,omitempty"`
AutoResolveTimeout int `json:"auto_resolve_timeout,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Description string `json:"description,omitempty"`
EscalationPolicy *EscalationPolicyReference `json:"escalation_policy,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
ID string `json:"id,omitempty"`
IncidentUrgencyRule *IncidentUrgencyRule `json:"incident_urgency_rule,omitempty"`
Integrations []*IntegrationReference `json:"integrations,omitempty"`
LastIncidentTimestamp string `json:"last_incident_timestamp,omitempty"`
Name string `json:"name,omitempty"`
ScheduledActions []*ScheduledAction `json:"scheduled_actions,omitempty"`
Self string `json:"self,omitempty"`
Service *Service `json:"service,omitempty"`
Status string `json:"status,omitempty"`
Summary string `json:"summary,omitempty"`
SupportHours *SupportHours `json:"support_hours,omitempty"`
Teams []*TeamReference `json:"teams,omitempty"`
Type string `json:"type,omitempty"`
}
a458ce4#diff-3a590e889ca6befd01b803e4b0af6fb3041552eead1463e0dca0b087c343f692R78
This looks like a copy/paste error from other structs as there is no matching attribute in the API for the https://api.pagerduty.com/services
endpoint: https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1services/post
FWIW, I noticed this while debugging weird issues with the behaviour of terraform provider when running acceptance tests:
2021/08/20 09:17:11 [INFO] Creating PagerDuty service tf-d60pe
2021/08/20 09:17:11 [DEBUG] PagerDuty - Preparing POST request to /services with body: {"acknowledgement_timeout":null,"alert_grouping":null,"auto_resolve_timeout":null,"service":{"acknowledgement_timeout":1800,"alert_creation":"create_alerts_and_incidents","alert_grouping":"time","alert_grouping_timeout":1800,"alert_grouping_parameters":{},"auto_resolve_timeout":1800,"description":"foo","escalation_policy":{"id":"PX530JT","type":"escalation_policy_reference"},"name":"tf-d60pe"}}
2021/08/20 09:17:11 [DEBUG] PagerDuty API Request Details:
---[ REQUEST ]---------------------------------------
POST /services HTTP/1.1
Host: api.pagerduty.com
User-Agent: heimweh/go-pagerduty(terraform)
Content-Length: 398
Accept: application/vnd.pagerduty+json;version=2
Authorization: Token token=******
Content-Type: application/json
Accept-Encoding: gzip
{
"acknowledgement_timeout": null,
"alert_grouping": null,
"auto_resolve_timeout": null,
"service": {
"acknowledgement_timeout": 1800,
"alert_creation": "create_alerts_and_incidents",
"alert_grouping": "time",
"alert_grouping_timeout": 1800,
"alert_grouping_parameters": {},
"auto_resolve_timeout": 1800,
"description": "foo",
"escalation_policy": {
"id": "PX530JT",
"type": "escalation_policy_reference"
},
"name": "tf-d60pe"
}
}
-----------------------------------------------------
2021/08/20 09:17:11 [DEBUG] PagerDuty API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 201 Created
Content-Length: 976
Access-Control-Allow-Headers: Authorization, Content-Type, AuthorizationOauth, X-EARLY-ACCESS
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers:
Access-Control-Max-Age: 1728000
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Fri, 20 Aug 2021 07:17:11 GMT
Etag: W/"517f34e20ed8089259a734bb0137b371"
Feature-Policy: accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Request-Id: 513fe44f47c4cc052001d152acb18a20
X-Xss-Protection: 1; mode=block
{
"service": {
"id": "P71DGB9",
"name": "tf-d60pe",
"description": "foo",
"created_at": "2021-08-20T09:17:11+02:00",
"updated_at": "2021-08-20T09:17:11+02:00",
"status": "active",
"teams": [],
"alert_creation": "create_alerts_and_incidents",
"addons": [],
"scheduled_actions": [],
"support_hours": null,
"last_incident_timestamp": null,
"escalation_policy": {
"id": "PX530JT",
"type": "escalation_policy_reference",
"summary": "tf-lrua3",
"self": "https://api.pagerduty.com/escalation_policies/PX530JT",
"html_url": "https://dev-claranet.pagerduty.com/escalation_policies/PX530JT"
},
"incident_urgency_rule": {
"type": "constant",
"urgency": "high"
},
"acknowledgement_timeout": 1800,
"auto_resolve_timeout": 1800,
"alert_grouping": null,
"alert_grouping_timeout": null,
"alert_grouping_parameters": {
"type": null,
"config": null
},
"integrations": [],
"response_play": null,
"type": "service",
"summary": "tf-d60pe",
"self": "https://api.pagerduty.com/services/P71DGB9",
"html_url": "https://dev-claranet.pagerduty.com/service-directory/P71DGB9"
}
}
-----------------------------------------------------
As you can see, some fields like alert_grouping
are passed twice, once at the root defined as null
and once in the nested service
attribute as alert_grouping
, and the response only returns the one at the root.
I started writing a fix for PagerDuty/terraform-provider-pagerduty#261, but found that this library also needs support for the Teams property of Schedules.
pagerduty/resource_pagerduty_schedule.go:147:11: schedule.Teams undefined (type *pagerduty.Schedule has no field or method Teams)
Raising the issue here to see if we can support this property end-to-end.
Cheers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.