2018-06-11 07:24:16 +00:00
|
|
|
defmodule Elstat.Adapter.Ping do
|
|
|
|
@behaviour Elstat.Adapter
|
|
|
|
|
2018-06-11 22:19:15 +00:00
|
|
|
def adapter_spec do
|
|
|
|
%{
|
|
|
|
db_columns: [:status]
|
|
|
|
}
|
2018-06-11 07:24:16 +00:00
|
|
|
end
|
2018-06-11 22:19:15 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
end
|