mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-27 02:56:31 +00:00
Get host dmesg as host logs (#1606)
* Get host dmesg as host logs * fix lint
This commit is contained in:
parent
2b082b362d
commit
2de1d35dd1
4
API.md
4
API.md
@ -252,6 +252,10 @@ return:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- GET `/host/logs`
|
||||||
|
|
||||||
|
Return host dmesg
|
||||||
|
|
||||||
- POST `/host/options`
|
- POST `/host/options`
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
@ -74,6 +74,7 @@ class RestAPI(CoreSysAttributes):
|
|||||||
self.webapp.add_routes(
|
self.webapp.add_routes(
|
||||||
[
|
[
|
||||||
web.get("/host/info", api_host.info),
|
web.get("/host/info", api_host.info),
|
||||||
|
web.get("/host/logs", api_host.logs),
|
||||||
web.post("/host/reboot", api_host.reboot),
|
web.post("/host/reboot", api_host.reboot),
|
||||||
web.post("/host/shutdown", api_host.shutdown),
|
web.post("/host/shutdown", api_host.shutdown),
|
||||||
web.post("/host/reload", api_host.reload),
|
web.post("/host/reload", api_host.reload),
|
||||||
|
@ -1,24 +1,27 @@
|
|||||||
"""Init file for Supervisor host RESTful API."""
|
"""Init file for Supervisor host RESTful API."""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Awaitable
|
||||||
|
|
||||||
|
from aiohttp import web
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from .utils import api_process, api_validate
|
|
||||||
from ..const import (
|
from ..const import (
|
||||||
ATTR_HOSTNAME,
|
|
||||||
ATTR_FEATURES,
|
|
||||||
ATTR_KERNEL,
|
|
||||||
ATTR_OPERATING_SYSTEM,
|
|
||||||
ATTR_CHASSIS,
|
ATTR_CHASSIS,
|
||||||
ATTR_DEPLOYMENT,
|
|
||||||
ATTR_STATE,
|
|
||||||
ATTR_NAME,
|
|
||||||
ATTR_DESCRIPTON,
|
|
||||||
ATTR_SERVICES,
|
|
||||||
ATTR_CPE,
|
ATTR_CPE,
|
||||||
|
ATTR_DEPLOYMENT,
|
||||||
|
ATTR_DESCRIPTON,
|
||||||
|
ATTR_FEATURES,
|
||||||
|
ATTR_HOSTNAME,
|
||||||
|
ATTR_KERNEL,
|
||||||
|
ATTR_NAME,
|
||||||
|
ATTR_OPERATING_SYSTEM,
|
||||||
|
ATTR_SERVICES,
|
||||||
|
ATTR_STATE,
|
||||||
|
CONTENT_TYPE_BINARY,
|
||||||
)
|
)
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
|
from .utils import api_process, api_process_raw, api_validate
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -107,3 +110,8 @@ class APIHost(CoreSysAttributes):
|
|||||||
"""Restart a service."""
|
"""Restart a service."""
|
||||||
unit = request.match_info.get(SERVICE)
|
unit = request.match_info.get(SERVICE)
|
||||||
return asyncio.shield(self.sys_host.services.restart(unit))
|
return asyncio.shield(self.sys_host.services.restart(unit))
|
||||||
|
|
||||||
|
@api_process_raw(CONTENT_TYPE_BINARY)
|
||||||
|
def logs(self, request: web.Request) -> Awaitable[bytes]:
|
||||||
|
"""Return host kernel logs."""
|
||||||
|
return self.sys_host.info.get_dmesg()
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
"""Info control for host."""
|
"""Info control for host."""
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from ..exceptions import HostNotSupportedError, DBusNotConnectedError, DBusError
|
from ..exceptions import (
|
||||||
|
HostNotSupportedError,
|
||||||
|
HostError,
|
||||||
|
DBusNotConnectedError,
|
||||||
|
DBusError,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -45,6 +51,21 @@ class InfoCenter(CoreSysAttributes):
|
|||||||
"""Return local CPE."""
|
"""Return local CPE."""
|
||||||
return self.sys_dbus.hostname.cpe
|
return self.sys_dbus.hostname.cpe
|
||||||
|
|
||||||
|
async def get_dmesg(self) -> bytes:
|
||||||
|
"""Return host dmesg output."""
|
||||||
|
proc = await asyncio.create_subprocess_shell(
|
||||||
|
"dmesg", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get kernel log
|
||||||
|
try:
|
||||||
|
stdout, _ = await proc.communicate()
|
||||||
|
except OSError as err:
|
||||||
|
_LOGGER.error("Can't read kernel log: %s", err)
|
||||||
|
raise HostError()
|
||||||
|
|
||||||
|
return stdout
|
||||||
|
|
||||||
async def update(self):
|
async def update(self):
|
||||||
"""Update properties over dbus."""
|
"""Update properties over dbus."""
|
||||||
_LOGGER.info("Update local host information")
|
_LOGGER.info("Update local host information")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user