Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

niklas2810/healthchecksio-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

healthchecksio-java

Maven Central GitHub Build Javadoc Link

healthchecksio-java is a Java Library for the REST API of healthchecks.io (it supports private instances as well). For now, only client features (Pinging API) are supported. However, the Management API is on my ToDo-List!

You can find more information on how to set up and use this library down below.


Table of Contents:

Installation

healthchecksio-java is available on Maven Central. You can find alternative importing methods (as well as direct download options) there.

The Javadocs of this project are available here.

Maven:

<dependency>
  <groupId>com.niklasarndt</groupId>
    <artifactId>healthchecksio-java</artifactId>
    <version>1.0.2</version>
</dependency>

Gradle:

implementation 'com.niklasarndt:healthchecksio-java:1.0.2'

Quick Start

Creating a Healthchecks client is quite straightforward.

//Creates a new healthchecks.io pinging client for the specified UUID
HealthchecksClient client = Healthchecks.forUuid("<uuid>"); 

Use these commands to send events to healthchecks.io:

client.start(); //The job has just begun
client.success(); //The job was completed successfully
client.fail(); //The job failed unexpectedly
client.exitCode(5); //The job exited with a specific exit code. Non-Zero exit codes will trigger alerts.

Every method also supports an attached message:

client.fail("Could not execute the job: " + reason); //Sends this string to healthchecks.io, which will be visible on the dashboard

The same applies to the Manager:

HealthchecksManager manager = Healthchecks.manager("<api-key>");

Read more about the Management API in the wiki for further instructions, here's a quick example:

Check[] filteredChecks = manager.getExistingChecks("cron debian").get(); //Retrieve all checks with tags "cron" and "debian"

To find out more about using the API, visit the wiki!

This library has a slf4-api(https://mvnrepository.com/artifact/org.slf4j/slf4j-api) implementation which produces debug logging output. To prevent this from happening, add this line to your logback.xml:

<logger name="com.niklasarndt.healthchecksio" level="WARN"/>

From now on, only warnings will be added to your logs.

Advanced Usage

You can also use this library with your self-hosted instance. To do this, simply use a different constructor function!

HealthchecksClient client = Healthchecks.forUuid("https://healthchecks.example.com", "<uuid>"); 

The same scheme applies to the manager (wiki).

Contributing

If you have any questions regarding the project or spotted a bug, feel free to open an issue!

Pull requests are always very much appreciated, but I hope you'll forgive me if I'm slow to respond sometimes.

Dependencies

Unit Testing:

License

© Niklas Arndt 2020, MIT License

I do not own or claim any copyright of healthchecks.io. healthchecks.io is being created by Pēteris Caune and other contributors under the BSD 3-Clause Revised License.