39 lines
900 B
Bash
39 lines
900 B
Bash
#!/bin/bash
|
|
|
|
# Proxmox VE virtual machine listing
|
|
# (c) 2015-2019, Tom Laermans for Observium
|
|
|
|
PVESH=`which pvesh`
|
|
if [ $? -eq 0 ]
|
|
then
|
|
echo "<<<proxmox-qemu>>>"
|
|
|
|
VERSION=$(pveversion | awk -F/ '{print $2}' | sed 's/\..*//')
|
|
if [[ ${VERSION} -ge 5 ]]
|
|
then
|
|
JSON=`pvesh get /nodes/$(hostname)/qemu --output-format=json-pretty 2>/dev/null`
|
|
else
|
|
pvesh get /nodes/$(hostname)/qemu 2>/dev/null
|
|
fi
|
|
fi
|
|
|
|
count=`echo $JSON | jq '. | length' `
|
|
|
|
for ((i=0; i<$count; i++)); do
|
|
name=`echo $JSON | jq -r '.['$i'].name'`
|
|
vmid=`echo $JSON | jq -r '.['$i'].vmid'`
|
|
ostype=`cat /etc/pve/qemu-server/${vmid}.conf | grep ostype | awk '{print $2}'`
|
|
if [ "$i" == "0" ]
|
|
then
|
|
CMD=".[$i] += {\"os\":\"$ostype\"}"
|
|
else
|
|
CMD=$CMD" | .[$i] += {\"os\":\"$ostype\"}"
|
|
fi
|
|
#echo "$name is $vmid"
|
|
done
|
|
|
|
jqcmd=(jq "$CMD")
|
|
|
|
#echo run it now
|
|
echo "$JSON" | "${jqcmd[@]}"
|