Skip to content
Open
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.5 / 2026-11-26

***Fixed***:

* Fix the Ping check reporting reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example ``LANG=ja_JP.UTF-8``). ping translated its output, including the ``ms`` unit, so no response time was found. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fix the Ping check reporting reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example ``LANG=ja_JP.UTF-8``). ping translated its output, including the ``ms`` unit, so no response time was found. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).
* Fix the ping check so it reports reachable hosts as down on Linux and macOS when the Agent runs with a non-English locale (for example, ``LANG=ja_JP.UTF-8``). It translated the output, including the ``ms`` unit, so it didn't properly report a response time. The check now runs ping with ``LC_ALL=C`` ([#3306](https://github.com/DataDog/integrations-extras/pull/3306)).


## 1.0.4 / 2026-08-04

***Fixed***:
Expand Down
2 changes: 2 additions & 0 deletions ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This check uses the system ping command, rather than generating the ICMP echo re

**Note for Windows users**: Versions prior to 1.0.4 may not work correctly if the installed Windows language is not set to English.

**Note for Linux and macOS users**: Versions prior to 1.0.5 may not work correctly if the Agent runs with a non-English locale.

## Setup

The ping check is not included in the [Datadog Agent][2] package, so you need to install it.
Expand Down
8 changes: 7 additions & 1 deletion ping/datadog_checks/ping/ping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under Simplified BSD License (see LICENSE)

import os
import platform
import re
import subprocess
Expand Down Expand Up @@ -71,7 +72,12 @@ def _exec_ping(self, timeout, target_host):
if platform.system() == "Windows":
lines, err, retcode = self._exec_ping_windows(command, subprocess_timeout)
else:
lines, err, retcode = get_subprocess_output(command, self.log, raise_on_empty_output=True)
# Force the C locale so ping's output is in English regardless of the Agent's LANG;
# the response-time regexes below only understand the untranslated output.
# The Agent replaces the whole environment when env is given, so copy it first.
env = dict(os.environ)
env["LC_ALL"] = "C"
lines, err, retcode = get_subprocess_output(command, self.log, raise_on_empty_output=True, env=env)

self.log.debug("ping returned %s - %s - %s", retcode, lines, err)
if retcode != 0:
Expand Down
24 changes: 24 additions & 0 deletions ping/tests/test_ping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import platform
import subprocess

Expand All @@ -7,6 +8,7 @@
from datadog_checks.base import AgentCheck
from datadog_checks.base.errors import CheckException
from datadog_checks.ping import PingCheck
from datadog_checks.ping import ping as ping_module

WINDOWS_GERMAN_OUTPUT = (
"Ping wird ausgeführt für 127.0.0.1 mit 32 Bytes Daten:\r\nAntwort von 127.0.0.1: Bytes=32 Zeit=3ms TTL=117\r\n"
Expand Down Expand Up @@ -83,6 +85,28 @@ def test_localized_output(aggregator, instance_response_time):
aggregator.assert_all_metrics_covered()


def test_unix_ping_runs_with_c_locale(monkeypatch):
# ping translates its output (e.g. "time=" -> "時間=" and "ms" -> "ミリ秒" under ja_JP),
# which the response-time regexes can't parse, so the check must force the C locale.
monkeypatch.setenv("LANG", "ja_JP.UTF-8")
monkeypatch.setenv("LC_ALL", "ja_JP.UTF-8")
check = PingCheck("ping", {}, {})
subprocess_mock = mock.Mock(return_value=(mock_exec_ping(), "", 0))
with (
mock.patch.object(platform, "system", return_value="Linux"),
mock.patch.object(ping_module, "get_subprocess_output", subprocess_mock),
):
check._exec_ping(4, "127.0.0.1")

env = subprocess_mock.call_args.kwargs["env"]
assert env["LC_ALL"] == "C"
# The Agent replaces the whole environment when env is given, so the rest must be kept.
assert env["PATH"] == os.environ["PATH"]
assert env["LANG"] == "ja_JP.UTF-8"
# Only the child process gets the C locale; the Agent's own environment is untouched.
assert os.environ["LC_ALL"] == "ja_JP.UTF-8"


def test_windows_oem_decode():
check = PingCheck("ping", {}, {})
check.WINDOWS_OUTPUT_ENCODING = "cp850"
Expand Down
Loading