Closed quiknick closed 2 years ago
pvesh get nodes/pve4/qemu/105/agent/network-get-interfaces
│ result │ [{"hardware-address":"00:00:00:00:00:00","ip-addresses":[{"ip-address":"127.0.0.1","ip-address-type":"ipv4","prefix":8},{"ip-address":"::1","ip-address-type":"ipv6","prefix":128}],"name":"lo","statistics":{"rx-bytes":1010657032,"rx-dropped":0,"rx-errs":0,"rx-packets":5714439,"tx-bytes":1010657032,"tx-dropped":0,"tx-errs":0,"tx-packets":5714439}},{"hardware-address":"0a:25:f9:fb:69:3d","ip-addresses":[{"ip-address":"192.168.128.105","ip-address-type":"ipv4","prefix":24},{"ip-address":"fe80::825:f9ff:feeb:697d","ip-address-type":"ipv6","prefix":64}],"name":"ens18","statistics":{"rx-bytes":5996678058,"rx-dropped":55,"rx-errs":0,"rx-packets":2278196,"tx-bytes":164408943,"tx-dropped":0,"tx-errs":0,"tx-packets":767657}}]
and get hostname
pvesh get nodes/pve4/qemu/105/agent/get-host-name ┌────────┬────────────────────────────┐ │ key │ value │ ╞════════╪════════════════════════════╡ │ result │ {"host-name":"playground"}
of course with any of these commands you have to know what host the vm is on, then use the vmid in concert to get info.
If I understood it correctly, you wish to have IP address information of Virtual Machines and Containers also synced on Netbox? If so, I agree with it and I am going to work on it later on!
As you said, Virtual Machines needs to have Qemu Agent installed on it so that I can get this information and make it available on Netbox. While LXC containers is already ready for API integration through REST API.
Currently only LXC container IPs and interfaces are recorded, but not VM IPs, MACs, interfaces and hostnames, even with QEMU agent installed.
Option 1: use qemu-guest-agent to get info
apt install qemu-guest-agent enabling the Guest agent flag in the VM config (in the GUI -> VM -> 'Options')
Proxmox VM Summary now lists IP and actual interface.
Use pvesh commands in following comment to get interface name, IP address and hostname.
Option 2: Use arp to get basic IP info
Look for the mac address in the configuration of the vm. In my example: vmid = 1176
Code: ~# qm config 1176 | grep net boot: order=scsi0;ide2;net0 net0: virtio=4E:57:9F:01:4E:6F,bridge=vmbr12,firewall=1
Now you can use "arp" to get the current IP address from the MAC:
Code: ~# arp -n | grep -i 4E:57:9F:01:4E:6F 10.12.4.59 ether 4e:57:9f:01:4e:6f C vmbr12