README.adoc

:icons: font
:encoding: utf-8

= NodePing Elixir

An Elixir package for managing checks, schedules, contacts, etc. on your NodePing account.

== Installation

The package can be installed by adding `nodeping` to your list of dependencies in `mix.exs`:

[source,elixir]
----
def deps do
  [
    {:nodeping, "~> 1.2"}
  ]
end
----

NOTE: If you want to use this package with Elixir version 1.9, instead set your dep to `{:nodeping, "~> 1.1"}`

And run `mix deps.get`.

== Usage

You will need to create an account at https://nodeping.com[NodePing] and fetch your API token under Account `Settings -> API`.
This will be your API `token` that you provide to authenticate with the service and manage things such as checks.
If you want to manage `SubAccounts`, you can get the ID for that subaccount under `Account Settings -> SubAccounts`,
and the ID is next to the name.

This document does not contain all the capabilities provided by this package.

=== Verify API Token

Verify if your API token is valid. Returns `true` or `false`.

[source,elixir]
----
token = System.fetch_env!("TOKEN")
NodePing.token_valid?(token)
----

== Checks

=== Get Checks

Get checks on your NodePing account via the `NodePing.Checks.get_checks` module.

[source,elixir]
----
token = System.fetch_env!("TOKEN")
{:ok, result} = NodePing.Checks.get_checks(token)
----

You can also get checks that meet certain conditions such as:

* passing - `NodePing.Checks.get_passing_checks`
* failing - `NodePing.Checks.get_failing_checks`
* disabled - `NodePing.Checks.get_disabled_checks`
* last result - `NodePing.Checks.get_last_result`

==== Get By ID

Get a single check by providing its ID

[source,elixir]
----
token = System.fetch_env!("TOKEN")
id = "201205050153W2Q4C-0J2HSIRF"
{:ok, result} = NodePing.Checks.get_by_id(token, id)
----

=== Find Checks

There are functions in the `NodePing.Checks` module called `find_by_id` and `find_by_state` which
accepts a result from `NodePing.Checks.get_checks` and lets you search by ID in the result or for
passing/failing checks. Each time you use these functions, they do not make a call to the API.


=== Create a Check

Create checks on your NodePing account via `NodePing.Checks.create_check`.

In this example a PING check is created and pointed at 8.8.8.8

[source,elixir]
----
token = System.fetch_env!("TOKEN")
checktype = NodePing.Checktypes.Ping
target = "8.8.8.8"
args = %{label: "my label", target: target, interval: 1, enabled: true}
{:ok, result} = NodePing.Checks.create_check(token, checktype, args)
----