A lightweight and flexible Java client designed to work with the PagerDuty Events V2 API. This allows for the manipulation of incidents within the PagerDuty service, specifically via the trigger, acknowledge, and resolve actions.
The client can be added with your favorite dependency management tool, the latest version can be found here: https://search.maven.org/artifact/io.github.quaide/pagerduty-events-v2-client.
<dependency>
<groupId>io.github.quaide</groupId>
<artifactId>pagerduty-events-v2-client</artifactId>
<version>1.0.1</version>
</dependency>
dependencies {
implementation 'io.github.quaide:pagerduty-events-v2-client:1.0.1'
}
The PagerDutyEventsV2Client
constructor optionally takes an HttpClient
. HttpClient httpClient = HttpClient.newHttpClient();
returns a new HttpClient
with default settings.
To build a request, you must build an instance of EventsRequest
. The following fields are required:
EventsRequest
:
routingKey
eventAction
dedupKey
(required IFF the value ofeventAction
isacknowledge
orresolve
)payload
summary
source
severity
Refer to PagerDuty documentation for more information regarding their API.
After building your EventRequest
, the request can be POSTed via pagerDutyEventsV2Client.post()
.
The following is a complete example:
import pagerdutyevents.EventsRequest;
import pagerdutyevents.EventsResponse;
import pagerdutyevents.PagerDutyEventsV2Client;
import pagerdutyevents.Payload;
import java.net.http.HttpClient;
public class TestPagerDutyClient {
private static final String ROUTING_KEY = "12345678901234567890123456789012";
public static void main(String[] args) {
HttpClient httpClient = HttpClient.newHttpClient();
PagerDutyEventsV2Client pagerDutyEventsV2Client = new PagerDutyEventsV2Client(httpClient);
Payload payload =
Payload.builder()
.summary("testing PagerDuty Events API v2 client")
.severity(Payload.Severity.info)
.source("quaide-test")
.build();
EventsRequest eventsRequest =
EventsRequest.builder()
.routingKey(ROUTING_KEY)
.eventAction(EventsRequest.EventAction.trigger)
.payload(payload)
.build();
EventsResponse eventsResponse = pagerDutyEventsV2Client.post(eventsRequest);
}
}
Licensed under the MIT License.