From 698441f44f13a0c030444c9e4937457b72ed4e15 Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Wed, 23 Oct 2024 20:17:57 +0200 Subject: [PATCH] KVM: Monitor VM IP address using qemu-guest-agent --- src/im_mad/remotes/kvm-probes.d/guestagent.conf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/im_mad/remotes/kvm-probes.d/guestagent.conf b/src/im_mad/remotes/kvm-probes.d/guestagent.conf index 95c6dcbbec..0f1a0db012 100644 --- a/src/im_mad/remotes/kvm-probes.d/guestagent.conf +++ b/src/im_mad/remotes/kvm-probes.d/guestagent.conf @@ -4,9 +4,18 @@ # enable or disable monitoring information from the qemu guest agent. :enabled: false # Commands used to gather VM information. -# Each command key will appear on the MONITORING message from the poll probe # The value will be run as a command executed with virsh qemu-agent-command # The $vm_id substring, if existing, will be replaced by the VM ID when the monitoring probes # are looping on each of the VMs on the host. Each command will be run once per VM. +# The expected response for each command is a JSON string with a "return" key. +# The contents of it will appear on the MONITORING message from the poll probe. :commands: :vm_qemu_ping: "one-$vm_id '{\"execute\":\"guest-ping\"}' --timeout 5" + # The first non-loopback address + :vm_ip_address: > + one-$vm_id '{"execute":"guest-network-get-interfaces"}' --timeout 5 | + jq '{"return" : [ .return[]."ip-addresses"[]|select(."ip-address-type"=="ipv4" and (."ip-address"|startswith("127.")|not))."ip-address" ][0]}' + # Array of all IP addresses + :vm_ip_address_list: > + one-$vm_id '{"execute":"guest-network-get-interfaces"}' --timeout 5 | + jq '{"return" : [ .return[]."ip-addresses"[]."ip-address" ]}'