Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagnostics to webmin #112543

Merged
merged 1 commit into from
Mar 8, 2024
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
Add diagnostics to webmin
  • Loading branch information
autinerd committed Mar 6, 2024
commit 0c0338a045759cae7097332fb5b636cdfcd86e58
35 changes: 35 additions & 0 deletions homeassistant/components/webmin/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Diagnostics support for Webmin."""
from typing import Any

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .coordinator import WebminUpdateCoordinator

TO_REDACT = {
CONF_HOST,
CONF_UNIQUE_ID,
CONF_USERNAME,
CONF_PASSWORD,
"address",
"address6",
"ether",
"broadcast",
"device",
"dir",
"title",
"entry_id",
}


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: WebminUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
return async_redact_data(
{"entry": entry.as_dict(), "data": coordinator.data}, TO_REDACT
)
138 changes: 138 additions & 0 deletions tests/components/webmin/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# serializer version: 1
# name: test_diagnostics
dict({
'data': dict({
'active_interfaces': list([
dict({
'address': '**REDACTED**',
'address6': '**REDACTED**',
'broadcast': '**REDACTED**',
'edit': 1,
'fullname': 'lo',
'index': 0,
'mtu': 65536,
'name': 'lo',
'netmask': '255.0.0.0',
'netmask6': list([
128,
]),
'scope6': list([
'host',
]),
'up': 1,
}),
dict({
'address6': '**REDACTED**',
'edit': 1,
'ether': '**REDACTED**',
'fullname': 'enp6s0',
'index': 1,
'mtu': 1500,
'name': 'enp6s0',
'netmask6': list([
]),
'scope6': list([
]),
'up': 1,
}),
dict({
'address': '**REDACTED**',
'address6': '**REDACTED**',
'broadcast': '**REDACTED**',
'edit': 1,
'ether': '**REDACTED**',
'fullname': 'eno1',
'index': 2,
'mtu': 1500,
'name': 'eno1',
'netmask': '255.255.255.0',
'netmask6': list([
64,
]),
'scope6': list([
'link',
]),
'up': 1,
}),
]),
'free_space': 8641328926720,
'fs': list([
dict({
'device': '**REDACTED**',
'dir': '**REDACTED**',
'free': 174511820800,
'ifree': 15091734,
'itotal': 15482880,
'iused': 391146,
'iused_percent': 3,
'total': 248431161344,
'type': 'ext4',
'used': 61225123840,
'used_percent': 26,
}),
dict({
'device': '**REDACTED**',
'dir': '**REDACTED**',
'free': 1044483624960,
'ifree': 183131475,
'itotal': 183140352,
'iused': 8877,
'iused_percent': 1,
'total': 5952635744256,
'type': 'ext4',
'used': 4608079593472,
'used_percent': 82,
}),
dict({
'device': '**REDACTED**',
'dir': '**REDACTED**',
'free': 7422333480960,
'ifree': 362787383,
'itotal': 366198784,
'iused': 3411401,
'iused_percent': 1,
'total': 11903838912512,
'type': 'ext4',
'used': 3881508986880,
'used_percent': 35,
}),
]),
'load_15m': 1.0,
'load_1m': 0.98,
'load_5m': 1.02,
'mem_free': 26162544,
'mem_total': 32767008,
'swap_free': 1953088,
'swap_total': 1953088,
'total_space': 18104905818112,
'uptime': dict({
'days': 3,
'minutes': 23,
'seconds': 12,
}),
'used_space': 8550813704192,
}),
'entry': dict({
'data': dict({
}),
'disabled_by': None,
'domain': 'webmin',
'entry_id': '**REDACTED**',
'minor_version': 1,
'options': dict({
'host': '**REDACTED**',
'password': '**REDACTED**',
'port': 10000,
'ssl': True,
'username': '**REDACTED**',
'verify_ssl': False,
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': '**REDACTED**',
'unique_id': None,
'version': 1,
}),
})
# ---
23 changes: 23 additions & 0 deletions tests/components/webmin/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Tests for the diagnostics data provided by the Webmin integration."""
from syrupy.assertion import SnapshotAssertion

from homeassistant.core import HomeAssistant

from .conftest import async_init_integration

from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator


async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
assert (
await get_diagnostics_for_config_entry(
hass, hass_client, await async_init_integration(hass)
)
== snapshot
)
Loading