Categorygithub.com/nytimes/go-pagerduty
modulepackage
1.3.3
Repository: https://github.com/nytimes/go-pagerduty.git
Documentation: pkg.go.dev

# README

GoDoc Go Report Card License

go-pagerduty

go-pagerduty is a CLI and go client library for the PagerDuty v2 API.

Installation

First, download the source code

go get github.com/PagerDuty/go-pagerduty

Next build the application.

cd $GOPATH/src/github.com/PagerDuty/go-pagerduty
make install

Usage

CLI

The CLI requires an authentication token, which can be specified in .pd.yml file in the home directory of the user, or passed as a command-line argument. Example of config file:

---
authtoken: fooBar

Commands

pd command provides a single entrypoint for all the API endpoints, with individual API represented by their own sub commands. For an exhaustive list of sub-commands, try:

pd --help

An example of the service sub-command

pd service list

Client Library

package main

import (
	"fmt"
	"github.com/PagerDuty/go-pagerduty"
)

var	authtoken = "" // Set your auth token here

func main() {
	var opts pagerduty.ListEscalationPoliciesOptions
	client := pagerduty.NewClient(authtoken)
	eps, err := client.ListEscalationPolicies(opts)
	if err != nil {
		panic(err)
	}
	for _, p := range eps.EscalationPolicies {
		fmt.Println(p.Name)
	}
}

The PagerDuty API client also exposes its HTTP client as the HTTPClient field. If you need to use your own HTTP client, for doing things like defining your own transport settings, you can replace the default HTTP client with your own by simply by setting a new value in the HTTPClient field.

API Error Responses

For cases where your request results in an error from the API, you can use the errors.As() function from the standard library to extract the pagerduty.APIError error value and inspect more details about the error, including the HTTP response code and PagerDuty API Error Code.

package main

import (
	"fmt"
	"github.com/PagerDuty/go-pagerduty"
)

var	authtoken = "" // Set your auth token here

func main() {
	client := pagerduty.NewClient(authtoken)
	user, err := client.GetUser("NOTREAL", pagerduty.GetUserOptions{})
	if err != nil {
		var aerr pagerduty.APIError

		if errors.As(err, &aerr) {
			if aerr.RateLimited() {
				fmt.Println("rate limited")
				return
			}

			fmt.Println("unknown status code:", aerr.StatusCode)

			return
		}

		panic(err)
	}
	fmt.Println(user)
}

Contributing

  1. Fork it ( https://github.com/PagerDuty/go-pagerduty/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

Apache 2

# Packages

No description provided by the author
No description provided by the author

# Functions

CreateEvent sends PagerDuty an event to trigger, acknowledge, or resolve a problem.
CreateEventWithHTTPClient sends PagerDuty an event to trigger, acknowledge, or resolve a problem.
DecodeWebhook decodes a webhook from a response object.
ManageEvent handles the trigger, acknowledge, and resolve methods for an event.
NewClient creates an API client using an account/user API token.
NewOAuthClient creates an API client using an OAuth token.
WithAPIEndpoint allows for a custom API endpoint to be passed into the the client.
WithOAuth allows for an OAuth token to be passed into the the client.
WithV2EventsAPIEndpoint allows for a custom V2 Events API endpoint to be passed into the client.

# Constants

No description provided by the author

# Structs

Acknowledgement is the data structure of an acknowledgement of an incident.
ActiveBetween represents an active_between object for setting a timeline for rules.
Addon is a third-party add-on to PagerDuty's UI.
AlertCounts is the data structure holding a summary of the number of alerts by status of an incident.
AlertGroupingParameters defines how alerts on the servicewill be automatically grouped into incidents.
AlertGroupParamsConfig is the config object on alert_grouping_parameters.
No description provided by the author
APIError represents the error response received when an API call fails.
APIErrorObject represents the object returned by the API when an error occurs.
APIListObject are the fields used to control pagination when listing objects.
APIObject represents generic api json response that is shared by most domain object (like escalation.
APIReference are the fields required to reference another API object.
No description provided by the author
Assignment is the data structure for an assignment of an incident.
BusinessService represents a business service.
BusinessServicePayload represents payload with a business service object.
BusinessServiceTeam represents a team object in a business service.
ChangeEvent represents a ChangeEvent's request parameters https://developer.pagerduty.com/docs/events-api-v2/send-change-events/#parameters.
ChangeEventLink represents a single link in a ChangeEvent https://developer.pagerduty.com/docs/events-api-v2/send-change-events/#the-links-property.
ChangeEventPayload ChangeEvent ChangeEventPayload https://developer.pagerduty.com/docs/events-api-v2/send-change-events/#example-request-payload.
ChangeEventResponse is the json response body for an event.
Channel is the means by which the action was carried out.
Client wraps http client.
CommonLogEntryField is the list of shared log entry between Incident and LogEntry.
ConditionParameter represents parameters in a rule condition.
ConferenceBridge is a struct for the conference_bridge object on an incident.
ContactMethod is a way of contacting the user.
Context are to be included with the trigger such as links to graphs or images.
CreateIncidentNoteResponse is returned from the API as a response to creating an incident note.
CreateIncidentOptions is the structure used when POSTing to the CreateIncident API endpoint.
EscalationPolicy is a collection of escalation rules.
EscalationRule is a rule for an escalation policy to trigger.
Event stores data for problem reporting, acknowledgement, and resolution.
EventResponse is the data returned from the CreateEvent API endpoint.
No description provided by the author
No description provided by the author
FirstTriggerLogEntry is the first LogEntry.
GetCurrentUserOptions is the data structure used when calling the GetCurrentUser API endpoint.
GetEscalationPolicyOptions is the data structure used when calling the GetEscalationPolicy API endpoint.
GetEscalationRuleOptions is the data structure used when calling the GetEscalationRule API endpoint.
GetIntegrationOptions is the data structure used when calling the GetIntegration API endpoint.
GetLogEntryOptions is the data structure used when calling the GetLogEntry API endpoint.
GetMaintenanceWindowOptions is the data structure used when calling the GetMaintenanceWindow API endpoint.
GetScheduleOptions is the data structure used when calling the GetSchedule API endpoint.
GetServiceOptions is the data structure used when calling the GetService API endpoint.
GetUserOptions is the data structure used when calling the GetUser API endpoint.
Incident is a normalized, de-duplicated event generated by a PagerDuty integration.
IncidentAlert is a alert for the specified incident.
IncidentAlertList is the generic structure of a list of alerts.
IncidentAlertResponse is the response of a sincle incident alert.
IncidentBody is the datastructure containing data describing the incident.
IncidentDetails contains a representation of the incident associated with the action that caused this webhook message.
IncidentNote is a note for the specified incident.
IncidentResponders contains details about responders to an incident.
IncidentUrgencyRule is the default urgency for new incidents.
IncidentUrgencyType are the incidents urgency during or outside support hours.
InlineModel represents when a scheduled action will occur.
Integration is an endpoint (like Nagios, email, or an API call) that generates events, which are normalized and de-duplicated by PagerDuty to create incidents.
ListAbilityResponse is the response when calling the ListAbility API endpoint.
ListAddonOptions are the options available when calling the ListAddons API endpoint.
ListAddonResponse is the response when calling the ListAddons API endpoint.
ListAlertsResponse is the response structure when calling the ListAlert API endpoint.
ListBusinessServiceOptions is the data structure used when calling the ListBusinessServices API endpoint.
ListBusinessServicesResponse represents a list response of business services.
ListContactMethodsResponse is the data structure returned from calling the GetUserContactMethod API endpoint.
ListEPResponse is the structure used to list escalation policies assigned a given tag.
ListEscalationPoliciesOptions is the data structure used when calling the ListEscalationPolicies API endpoint.
ListEscalationPoliciesResponse is the data structure returned from calling the ListEscalationPolicies API endpoint.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ListIncidentAlertsOptions is the structure used when passing parameters to the ListIncidentAlerts API endpoint.
ListIncidentLogEntriesOptions is the structure used when passing parameters to the ListIncidentLogEntries API endpoint.
ListIncidentLogEntriesResponse is the response structure when calling the ListIncidentLogEntries API endpoint.
ListIncidentsOptions is the structure used when passing parameters to the ListIncident API endpoint.
ListIncidentsResponse is the response structure when calling the ListIncident API endpoint.
ListLogEntriesOptions is the data structure used when calling the ListLogEntry API endpoint.
ListLogEntryResponse is the response data when calling the ListLogEntry API endpoint.
ListMaintenanceWindowsOptions is the data structure used when calling the ListMaintenanceWindows API endpoint.
ListMaintenanceWindowsResponse is the data structur returned from calling the ListMaintenanceWindows API endpoint.
ListMembersOptions are the optional parameters for a members request.
ListMembersResponse is the response from the members endpoint.
ListNotificationOptions is the data structure used when calling the ListNotifications API endpoint.
ListNotificationsResponse is the data structure returned from the ListNotifications API endpoint.
ListOnCallOptions is the data structure used when calling the ListOnCalls API endpoint.
ListOnCallsResponse is the data structure returned from calling the ListOnCalls API endpoint.
ListOnCallUsersOptions is the data structure used when calling the ListOnCallUsers API endpoint.
ListOverridesOptions is the data structure used when calling the ListOverrides API endpoint.
ListOverridesResponse is the data structure returned from calling the ListOverrides API endpoint.
ListRulesetRulesResponse represents a list of rules in a ruleset.
ListRulesetsResponse represents a list response of rulesets.
ListSchedulesOptions is the data structure used when calling the ListSchedules API endpoint.
ListSchedulesResponse is the data structure returned from calling the ListSchedules API endpoint.
ListServiceDependencies represents a list of dependencies for a service.
ListServiceOptions is the data structure used when calling the ListServices API endpoint.
ListServiceResponse is the data structure returned from calling the ListServices API endpoint.
ListServiceRulesResponse represents a list of rules in a service.
ListTagOptions are the input parameters used when calling the ListTags API endpoint.
ListTagResponse is the structure used when calling the ListTags API endpoint.
ListTeamOptions are the input parameters used when calling the ListTeams API endpoint.
ListTeamResponse is the structure used when calling the ListTeams API endpoint.
ListTeamsForTagResponse is the structure used to list teams assigned a given tag.
ListUserNotificationRulesResponse the data structure returned from calling the ListNotificationRules API endpoint.
ListUserResponse is the structure used to list users assigned a given tag.
ListUsersOptions is the data structure used when calling the ListUsers API endpoint.
ListUsersResponse is the data structure returned from calling the ListUsers API endpoint.
ListVendorOptions is the data structure used when calling the ListVendors API endpoint.
ListVendorResponse is the data structure returned from calling the ListVendors API endpoint.
LogEntry is a list of all of the events that happened to an incident.
MaintenanceWindow is used to temporarily disable one or more services for a set period of time.
ManageIncidentsOptions is the structure used when PUTing updates to incidents to the ManageIncidents func.
Member is a team member.
MergeIncidentsOptions is the structure used when merging incidents with MergeIncidents func.
Notification is a message containing the details of the incident.
NotificationRule is a rule for notifying the user.
NullAPIErrorObject is a wrapper around the APIErrorObject type.
OnCall represents a contiguous unit of time for which a user will be on call for a given escalation policy and escalation rule.
Overrides are any schedule layers from the override layer.
PendingAction is the data structure for any pending actions on an incident.
PreviewScheduleOptions is the data structure used when calling the PreviewSchedule API endpoint.
No description provided by the author
Priority is the data structure describing the priority of an incident.
PriorityProperty is a single priorty object returned from the Priorities endpoint.
RenderedScheduleEntry represents the computed set of schedule layer entries that put users on call for a schedule, and cannot be modified directly.
Resolve reason is the data structure describing the reason an incident was resolved.
ResponderRequest contains the API structure for an incident responder request.
ResponderRequestOptions defines the input options for the Create Responder function.
ResponderRequestResponse.
ResponderRequestTarget specifies an individual target for the responder request.
ResponderRequestTargets is a wrapper for a ResponderRequestTarget.
Restriction limits on-call responsibility for a layer to certain times of the day or week.
RuleActionExtraction represents a rule extraction action object.
RuleActionParameter represents a generic parameter object on a rule action.
RuleActions represents a rule action.
RuleActionSuppress represents a rule suppress action object.
RuleActionSuspend represents a rule suspend action object.
RuleConditions represents the conditions field for a Ruleset.
Ruleset represents a ruleset.
RulesetObject represents a generic object that is common within a ruleset object.
RulesetPayload represents payload with a ruleset object.
RulesetRule represents a Ruleset rule.
RulesetRulePayload represents a payload for ruleset rules.
RuleSubcondition represents a subcondition of a ruleset condition.
RuleTimeFrame represents a time_frame object on the rule object.
Schedule determines the time periods that users are on call.
ScheduledAction contains scheduled actions for the service.
ScheduledWeekly represents a time_frame object for scheduling rules weekly.
ScheduleLayer is an entry that puts users on call for a schedule.
Service represents something you monitor (like a web service, email service, or database service).
ServiceDependency represents a relationship between a business and technical service.
ServiceObj represents a service object in service relationship.
ServiceRule represents a Service rule.
ServiceRuleActions represents a rule action.
SupportHours are the support hours for the service.
Tag is a way to label user, team and escalation policies in PagerDuty.
TagAssignment is the structure for assigning tags to an entity.
TagAssignments can be applied teams, users and escalation policies.
Team is a collection of users and escalation policies that represent a group of people within an organization.
UpdateScheduleOptions is the data structure used when calling the UpdateSchedule API endpoint.
User is a member of a PagerDuty account that has the ability to interact with incidents and other data on the account.
UserReference is a reference to an authorized PagerDuty user.
V2Event includes the incident/alert details.
V2EventResponse is the json response body for an event.
V2Payload represents the individual event details for an event.
Vendor represents a specific type of integration.
WebhookPayload represents the V2 webhook payload.
WebhookPayloadMessages is the wrapper around the Webhook payloads.

# Interfaces

HTTPClient is an interface which declares the functionality we need from an HTTP client.

# Type aliases

Agent is the actor who carried out the action.
ClientOptions allows for options to be passed into the Client for customization.