ha-sys-mon-agent/systemd-tests.py
2024-05-01 13:25:07 +03:00

21 lines
482 B
Python

import asyncio
from google.protobuf.json_format import MessageToJson
import systemd
async def main() -> None:
services = ["docker.service", "sshd.service"]
monitor = systemd.Monitor(services)
await monitor.initialize()
resp = await monitor.poll()
for unit in resp:
json = MessageToJson(unit, including_default_value_fields=True)
print(json)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())