23 lines
502 B
Elixir
23 lines
502 B
Elixir
|
defmodule Elstat.Adapter.Ping do
|
||
|
@behaviour Elstat.Adapter
|
||
|
|
||
|
use GenServer
|
||
|
require Logger
|
||
|
|
||
|
def start_link(service_opts) do
|
||
|
GenServer.start_link(__MODULE__, service_opts, [])
|
||
|
end
|
||
|
|
||
|
def init(service_opts) do
|
||
|
Logger.info("Ping started with #{inspect service_opts}")
|
||
|
{:ok, %{}}
|
||
|
end
|
||
|
|
||
|
def check(args) do
|
||
|
{cmd_output, _} = System.cmd("ping", ["-c", "1", args.address])
|
||
|
alive? = not Regex.match?(~r/100(\.0)?% packet loss/, cmd_output)
|
||
|
{:ok, {:bool, alive?}}
|
||
|
end
|
||
|
|
||
|
end
|