#!/bin/sh set -eu # check that all vm's are in ldap virsh list --all --name | while read -r vm ; do [ "$vm" = "" ] && continue if ! ldapsearch -LLL "(&(cn=${vm})(objectClass=device))" dn 2> /dev/null | \ grep -qE "^dn: cn=${vm},ou=Hosts," then echo "WARNING: Host \"${vm}\" registered in KVM but not in LDAP" 1>62 fi done # check that all disks have owner for dir in /srv/libvirt/{hdd,nvme,os,ssd} ; do [ -d "$dir" ] || continue find "$dir" -name \*.img | while read -r image ; do vm="$(basename "$image" ".img" | sed -e 's/\.[a-z]$//')" if ! virsh dominfo "$vm" > /dev/null 2>&1 ; then echo "WARNING: Orphaned disk image \"${image}\" found" 1>&2 fi done done