mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add diagnostics to webmin (#112543)
This commit is contained in:
parent
b026b5d589
commit
0e86f182cc
35
homeassistant/components/webmin/diagnostics.py
Normal file
35
homeassistant/components/webmin/diagnostics.py
Normal file
@ -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
tests/components/webmin/snapshots/test_diagnostics.ambr
Normal file
138
tests/components/webmin/snapshots/test_diagnostics.ambr
Normal file
@ -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
tests/components/webmin/test_diagnostics.py
Normal file
23
tests/components/webmin/test_diagnostics.py
Normal file
@ -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…
x
Reference in New Issue
Block a user