Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ping/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG - Ping

## 1.0.3 / 2026-07-23

***Fixed***:

* Fix the Ping check on non-English Windows. It no longer crashes on localized output (``'utf-8' codec can't decode byte 0x81``) and no longer reports reachable hosts as down. The check now uses the UTF-8 code page and, when the localized "time" label isn't found, falls back to matching ping's untranslated ``ms`` unit ([#3075](https://github.com/DataDog/integrations-extras/pull/3075)).

## 1.0.2 / 2021-09-30

***Fixed***:
Expand Down
7 changes: 5 additions & 2 deletions ping/datadog_checks/ping/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _exec_ping(self, timeout, target_host):
cmd = "ping"

if platform.system() == "Windows": # pragma: nocover
precmd = ["cmd", "/c", "chcp 437 &"] # Set code page to English for non-US Windows
precmd = ["cmd", "/c", "chcp 65001 &"]
countOption = "-n"
timeoutOption = "-w"
# The timeout option is in ms on Windows
Expand Down Expand Up @@ -90,7 +90,10 @@ def check(self, instance):
if result:
length = result[0][0]
else:
raise CheckException("No time= found ({})".format(lines))
result = re.findall(r"[<=]\s*([\d.]+)\s*ms", lines)
if not result:
raise CheckException("No response time found ({})".format(lines))
length = result[0]

except CheckException as e:
self.log.info("%s is DOWN (%s)", host, e)
Expand Down
19 changes: 19 additions & 0 deletions ping/tests/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ def mock_exec_ping():
round-trip min/avg/max/stddev = 0.093/0.093/0.093/0.000 ms"""


def mock_exec_ping_german():
return (
"Antwort von 127.0.0.1: Bytes=32 Zeit=3ms TTL=117\n"
"Ping-Statistik für 127.0.0.1:\n"
" Minimum = 3ms, Maximum = 3ms, Mittelwert = 3ms"
)


def test_empty_check(empty_instance):
check = PingCheck("ping", {}, {})

Expand Down Expand Up @@ -49,6 +57,17 @@ def test_valid_check_ipv6(aggregator, instance_ipv6):
aggregator.assert_all_metrics_covered()


def test_localized_output(aggregator, instance_response_time):
check = PingCheck("ping", {}, {})

with mock.patch.object(check, "_exec_ping", return_value=mock_exec_ping_german()):
check.check(instance_response_time)
aggregator.assert_service_check("network.ping.can_connect", AgentCheck.OK)
aggregator.assert_metric("network.ping.can_connect", value=1)
aggregator.assert_metric("network.ping.response_time", value=3)
aggregator.assert_all_metrics_covered()


@pytest.mark.usefixtures("dd_environment")
def test_integration(aggregator, instance):
check = PingCheck("ping", {}, {})
Expand Down
Loading