elstat/lib/adapters/ping.ex

21 lines
405 B
Elixir
Raw Normal View History

2018-06-11 07:24:16 +00:00
defmodule Elstat.Adapter.Ping do
@behaviour Elstat.Adapter
def adapter_spec do
%{
db_columns: [:timestamp, :status]
}
2018-06-11 07:24:16 +00:00
end
2018-06-11 07:24:16 +00:00
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
def transform_val({:bool, alive?}) do
[alive?]
end
2018-06-11 07:24:16 +00:00
end