elstat/lib/adapters/ping.ex

23 lines
502 B
Elixir
Raw Normal View History

2018-06-11 07:24:16 +00:00
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