Skip to content

primelib/pagerduty4j

Repository files navigation

PagerDuty4J

A java client for the PagerDuty APIs.

Module: REST

Maven Central javadoc

Installation

implementation("io.github.primelib:pagerduty4j-rest:<latestVersion>")

Click to view instructions for other build tools.

Usage

Consumer Specification Approach

PagerDutyRESTConsumerApi client = PagerDutyRESTFactory.create(spec -> {
    spec.api(PagerDutyRESTConsumerApi.class);
    spec.baseUrl("https://api.pagerduty.com");
    spec.apiKeyAuth(authSpec -> authSpec.apiKey("<token>"));
    // optional: http proxy
    spec.httpProxy(proxySpec -> {
        proxySpec.host("localhost");
        proxySpec.port(8080);
    });
});

client.listIncidentAlerts(spec -> {
    spec.id("15");
    spec.limit(100);
});

Parameter Approach

PagerDutyRESTApi client = PagerDutyRESTFactory.create(spec -> {
    spec.api(PagerDutyRESTApi.class);
    spec.baseUrl("https://api.pagerduty.com");
    spec.apiKeyAuth(authSpec -> authSpec.apiKey("<token>"));
    // optional: http proxy
    spec.httpProxy(proxySpec -> {
        proxySpec.host("localhost");
        proxySpec.port(8080);
    });
});

client.listIncidentAlerts("15", 100, null, null, null, null, null, null);

NOTE: The Parameter Approach can break if the API changes. The Consumer Specification Approach is more resilient to API changes.

Module: Events-V2

Maven Central javadoc

Installation

implementation("io.github.primelib:pagerduty4j-events-v2:<latestVersion>")

Click to view instructions for other build tools.

Usage

Consumer Specification Approach

PagerDutyEventsV2ConsumerApi client = PagerDutyEventsV2Factory.create(spec -> {
    spec.api(PagerDutyEventsV2ConsumerApi.class);
    spec.baseUrl("https://events.pagerduty.com/v2");
    // optional: http proxy
    spec.httpProxy(proxySpec -> {
        proxySpec.host("localhost");
        proxySpec.port(8080);
    });
});

client.createChangeEvent(spec -> {
    spec.createChangeEventRequest(CreateChangeEventRequest.of(requestSpec -> {
        requestSpec.routingKey("<routingKey>");
        requestSpec.payload(ChangeEventPayload.of(payloadSpec -> {
            payloadSpec.summary("<summary>");
            payloadSpec.source("<source>");
        }));
    }));
});

Parameter Approach

PagerDutyEventsV2Api client = PagerDutyEventsV2Factory.create(spec -> {
    spec.api(PagerDutyEventsV2Api.class);
    spec.baseUrl("https://events.pagerduty.com/v2");
    // optional: http proxy
    spec.httpProxy(proxySpec -> {
        proxySpec.host("localhost");
        proxySpec.port(8080);
    });
});

client.createChangeEvent(new CreateChangeEventRequest(new ChangeEventPayload("<summary>", null, "<source>", null), "<routingKey>", null, null));

NOTE: The Parameter Approach can break if the API changes. The Consumer Specification Approach is more resilient to API changes.

Links

License

Released under the MIT License.