Documentation
¶
Overview ¶
Package pagerduty provides a notifier implementation that sends notifications via PagerDuty. It uses the PagerDuty API to create incidents based on the provided configuration.
Usage: To use this package, you need to create a new instance of PagerDuty with your API token. You can then configure it with the necessary details like the sender's address and receivers. Finally, you can send notifications which will create incidents in PagerDuty.
Example:
package main
import (
"context"
"log"
"github.com/atwallets/notify"
"github.com/atwallets/notify/service/pagerduty"
)
func main() {
// Create a new PagerDuty service. Replace 'your_pagerduty_api_token' with your actual PagerDuty API token.
pagerDutyService, err := pagerduty.New("your_pagerduty_api_token")
if err != nil {
log.Fatalf("failed to create pagerduty service: %s", err)
}
// Set the sender address and add receivers.
pagerDutyService.SetFromAddress("sender@example.com")
pagerDutyService.AddReceivers("ServiceDirectory1", "ServiceDirectory2")
// Create a notifier instance and register the PagerDuty service to it.
notifier := notify.New()
notifier.UseServices(pagerDutyService)
// Send a notification.
err = notifier.Send(context.Background(), "Test Alert", "This is a test alert from PagerDuty service.")
if err != nil {
log.Fatalf("failed to send notification: %s", err)
}
log.Println("Notification sent successfully")
}
This package requires a valid PagerDuty API token to authenticate requests.
Index ¶
- Constants
- type Client
- type Config
- func (c *Config) AddReceivers(receivers ...string)
- func (c *Config) OK() error
- func (c *Config) PriorityReference() *pagerduty.APIReference
- func (c *Config) SetFromAddress(fromAddress string)
- func (c *Config) SetNotificationType(notificationType string)
- func (c *Config) SetPriorityID(priorityID string)
- func (c *Config) SetUrgency(urgency string)
- type PagerDuty
Constants ¶
const ( APIReferenceType = "service_reference" APIPriorityReference = "priority_reference" DefaultNotificationType = "incident" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
FromAddress string
Receivers []string
NotificationType string
Urgency string
PriorityID string
}
Config contains the configuration for the PagerDuty service.
func (*Config) AddReceivers ¶
AddReceivers appends the receivers to the configuration.
func (*Config) OK ¶
OK checks if the configuration is valid. It returns an error if the configuration is invalid.
func (*Config) PriorityReference ¶
func (c *Config) PriorityReference() *pagerduty.APIReference
PriorityReference returns the PriorityID reference if it is set, otherwise it returns nil.
func (*Config) SetFromAddress ¶
SetFromAddress sets the from address in the configuration.
func (*Config) SetNotificationType ¶
SetNotificationType sets the notification type in the configuration. If the notification type is empty, it will be set to the default value "incident".
func (*Config) SetPriorityID ¶
SetPriorityID sets the PriorityID in the configuration.
func (*Config) SetUrgency ¶
SetUrgency sets the urgency in the configuration.
type PagerDuty ¶
func (*PagerDuty) IncidentOptions ¶
func (s *PagerDuty) IncidentOptions(subject, message string) *pagerduty.CreateIncidentOptions