List Ovirt/RHV VM’s
( curl -s -u admin@internal:secretpassword -k https://ovirt-engine.lab/ovirt-engine/api/vms/ | grep "^ <name>" | cut -f2 -d\> | cut -f1 -d \< | while read; do echo "$REPLY" done ) > list echo "NOT IN BACKUP" cat list | while read ; do ls vmbackup/$REPLY.ova 2>/dev/null >/dev/null || echo $REPLY ;done echo "" ls vmbackup/*ova | while read ; do host=$( echo $REPLY | cut -f2 -d/ | cut -f1 -d.) age=$(stat -c %y $REPLY | cut -f1 -d" ") echo "$age $host" done
Backup: (UPDATE)
While i made my own backup script for Ovirt, i found this ansible based one.
https://github.com/silverorange/ovirt_ansible_backup
Backup Ovirt Engine using ansible
Usage : ansible-playbook -i ovirt-engine.lab, playbook.yml -u root (-k) ## Playbook --- - hosts: all vars: ovirt_backup_mode: 'backup' ovirt_backup_archive: '/tmp/engine-backup.gzip' ovirt_backup_log_file: '/tmp/engine-backup.log' ovirt_backup_scope: 'all' ansible_python_interpreter: /usr/bin/python3 roles: - ovirt-engine-backup ## roles/ovirt-engine-backup/tasks/main.yml --- - name: run engine-backup shell: 'engine-backup --mode={{ ovirt_backup_mode }} --file={{ ovirt_backup_archive }} --log={{ ovirt_backup_log_file }} --scope={{ ovirt_backup_scope }}' tags: - skip_ansible_lint register: ovirt_backup_status - name: download engine backup file fetch: src: "{{ ovirt_backup_archive }}" dest: "{{ ovirt_backup_archive }}" when: ovirt_backup_status is succeeded - name: download log file fetch: src: "{{ ovirt_log_file }}" dest: "{{ ovirt_log_file }}" when: ovirt_backup_status is failed
Gluster overview
#!/bin/bash ansible -i inventory all -m shell -a "/sbin/gluster v info" --become -K > output cat output | grep "^Volume Name" | sort | cut -c14- | sort | uniq cat output | egrep "^Volume Name|^Brick|^Type" | grep -v Bricks
Gluster to grafana using influx
#!/bin/bash export PATH=$PATH:/sbin ( # Get short shotname host=$(echo $HOSTNAME | cut -f1 -d.) echo "-- vg info --" # Get vg info - pool nog doen vgs --units k | egrep "brick|data0" | while read brickinfo ; do name=$(echo $brickinfo | awk '{ print $1}' ) size=$(echo $brickinfo | awk '{ print $6}' | cut -f1 -d.) free=$(echo $brickinfo | awk '{ print $7}' | cut -f1 -d. | sed s/k//g) usage=$(echo $(( $size - $free ))) curl -i -XPOST 'http://grafanaserver:8086/write?db=gluster' --data-binary "$host-$name size=$size,free=$free,usage=$usage" done echo "-- vg info done --" echo "-- lv info --" # Get lv info - these are mountpoints (not bricks) #lvs --units k | egrep "brick|data0" | grep -v pool | while read volinfo ; do df | egrep "brick|data0" | while read volinfo ; do name=$(echo $volinfo | awk '{ print $1}' | rev | cut -f1 -d/ | rev ) size=$(df | grep -v svg |grep "$name" | awk '{ print $2}') usage=$(df | grep -v svg |grep "$name" | awk '{ print $3}') free=$(df | grep -v svg |grep "$name" | awk '{ print $4}') curl -i -XPOST 'http://grafanaserver:8086/write?db=gluster' --data-binary "$host-$name size=$size,free=$free,usage=$usage" done echo "-- lv info done --" # Get gluster volumes without gluster command, due to issues running multiple instances # One volume on one mountpoint ? Then df == volume metrics : > /tmp/vollist find /var/lib/glusterd/| grep $HOSTNAME | grep vol$ | while read brickpath ; do grep brick-path $brickpath | awk '{print $3 }' >> /tmp/vollist done mount | egrep "brick|data0" | awk '{print $3 }' | while read mountpoint ; do count=$(grep $mountpoint /tmp/vollist | wc -l) if [ $count -lt 2 ] ; then echo "lv = brick .. df info" #brick=$(echo $mountpoint) #volume=$(echo $mountpoint |rev | cut -f1 -d/ | rev) #size=$(df $mountpoint | grep -v Filesystem | awk '{ print $2 }') #free=$(df $mountpoint | grep -v Filesystem | awk '{ print $4 }') #usage=$(df $mountpoint | grep -v Filesystem | awk '{ print $5 }' | sed s/%//g ) dfinfo=$(df $mountpoint | grep -v ^Filesystem) name=$(echo $dfinfo | awk '{print $1}' | rev | cut -f1 -d/ | rev) size=$(echo $dfinfo | awk '{print $2}') usage=$(echo $dfinfo | awk '{print $3}') free=$(echo $dfinfo | awk '{print $4}') perc=$(echo $dfinfo | awk '{print $5}' | sed s/%//g) curl -i -XPOST 'http://grafanaserver:8086/write?db=gluster' --data-binary "$host-$name size=$size,free=$free,usage=$usage" #curl -i -XPOST 'http://grafanaserver:8086/write?db=gluster' --data-binary "$host-$brick-$volume size=$size,free=$free,usage=$usage" else echo "du script draaien voor $mountpoint" fi done echo "-- data% --" lvs --units k -a -oname,vg_name,size,vgfree,data_percent,pool_lv | grep -v \\[ | egrep "brick|data" | grep -v sysdata | grep -v "^ thin" | while read ; do vg=$(echo $REPLY | awk '{print $2}') name=$(echo $REPLY | awk '{print $6"-"$1}') size=$(echo $REPLY | awk '{ print $3 }' | cut -f1 -d.) free=$(echo $REPLY | awk '{ print $4 }' | cut -f1 -d. | sed s/k//g) dataperc=$(echo $REPLY | awk '{ print $5 }' | cut -f1 -d. ) if [ "w$dataperc" == "w" ] ; then dataperc=0 ;fi curl -i -XPOST 'http://grafanaserver:8086/write?db=gluster' --data-binary "$host-$name-$vg size=$size,free=$free,dataperc=$dataperc" done ) 2> /dev/null >/dev/null
Running Ovirt and want a overview of glustermounts in VMs?
run makeinventory.sh (this creats an list of linux hosts which are UP in RHV/Ovirt) #!/bin/bash #ik haal een lijst op van virtual machines die aanstaan en linux draaien #set -x mkdir -p tmp rm -f tmp/linuxup read -p "Username: " x2 read -s -p "Password: " x1 echo " " curl -s -X GET -H "Accept: application/xml" --insecure -u $x2@radlan:$x1 https://ovirtserver/ovirt-engine/api/vms | grep "vm href=" | cut -c37-72 > tmp/vms cat tmp/vms | while read vm ; do echo -n "." curl -s -X GET -H "Accept: application/xml" --insecure -u $x2@radlan:$x1 https://ovirtserver/ovirt-engine/api/vms/$vm > tmp/$vm done echo " " : > tmp/linuxup find tmp -type f -mtime 0 | egrep -v "vms$|linuxup" | while read ; do name=$(cat $REPLY | grep -i "^ <name>"| cut -f2 -d\> | cut -f1 -d \<) os=$(cat $REPLY | egrep "^ <family>" | egrep -v "svw|SVNT|debian|ubuntu|server|spice|vnc|windows_|native" | cut -f2 -d\> | cut -f1 -d \<) up=$(cat $REPLY | grep -A1 start_time | tail -1| cut -f2 -d\> | cut -f1 -d \<) echo $name,$os,$up | grep -v ",," | grep ",up" >> tmp/linuxup cat tmp/linuxup echo "" echo "staat in tmp/linuxup" done echo "[all]" > inventory cat tmp/linuxup | grep "."| grep -i linux | cut -f1 -d, >> inventory Run get.sh * ansible on all hosts (inventory) and fetches gluster mounts * reorders this info * generates a dot file (graphviz) * running dot fot a svg/png output for every gluster host #!/bin/bash echo "draai eerst makeinventory.sh voor een nieuwe host lijst" read d echo "Kijk ook of ansible alle servers kan bereiken" read d ansible -i inventory all -m shell -a cat /etc/mtab | grep gluster | while read; do source=$(echo $REPLY | cut -f1 -d" ");dest=$(echo $REPLY | cut -f2 -d" ") ; echo " " ;echo "$source $HOSTNAME:$dest" ;done > gluster cat gluster | grep ^s | grep : > gluster.grep cat gluster.grep | cut -f1 -d: | sort | uniq | while read gluster ; do cat header > $gluster.dot cat gluster.grep | grep $gluster | cut -f1 -d" "| sort | uniq | while read ; do echo " \"$REPLY\";" ;done >> $gluster.dot cat middel >> $gluster.dot cat gluster.grep | grep $gluster| sed s/^/\"/ | sed s/\ /\"\ \-\>\ \"/ | sed s/$/\"\;/ >> $gluster.dot cat footer >> $gluster.dot dot $gluster.dot -Tsvg >$gluster.svg dot -Gsize=9,15\! -Gdpi=100 $gluster.dot -Tpng >$gluster.png done A php select page to few them <form method="post"> <select name="volume"> <?PHP foreach (glob("*.svg") as $filename) { echo "<option value=" . $filename .">" . $filename . "</option>"; } ?> </select> <input type="submit" value="Submit"> </form> <?PHP if (isset($_POST['volume'])){ $image=$_POST['volume']; echo "<img src=\"$image\">"; } ?> example below:
Get a list of RHV snapshots and descriptions
#!/bin/bash : > outlist read -p "Username: " user read -s -p "Password: " pass curl -X GET -H "Accept: application/xml" -u $user@internal:$pass -k https://ovirt-engine:443/ovirt-engine/api/vms | egrep "<name>|snapshots" | grep -v " " | sed '$!N;s/\n/ /' > templist cat templist | cut -f2,3 -d\> | cut -f1,3 -d\< | sed 's/<link href=\"/ /g' | cut -f1 -d\" > templist2 cat templist2 | while read ; do host=$(echo $REPLY | awk '{ print $1 }') link=$(echo $REPLY | awk '{ print $2 }') echo $host >> outlist curl -X GET -H "Accept: application/xml" -u $user@radlan:$pass -k https://ovirt-engine:443/$link | egrep "description|date" | grep -v ' <' >> outlist ; echo "----" >> outlist done cat outlist | awk '/Active VM/ {getline; next} { print }' > /tmp/outlist grep -B3 date /tmp/outlist |sed -e 's/<[^>]*>//g' > /tmp/snapshots cat /tmp/snapshots | awk '/----/ {printf "\n%s\n",$0;next} {printf "%s ",$0}' | sed 's/ --*//g' | grep -v '\-\-\-\-' | grep " " > snapshots Output: svr04.lab Backup 2019-06-28T07:55:28.909+02:00 svr05.lab upgrade 2019-06-18T14:18:49.745+02:00 svr33.lab pre_ansible 2019-06-18T14:04:43.569+02:00 Somewhere i've got a snapshot age warn script. This information was posted in Mattermost when sending the "/snapshots" command
Ansible Playbook to add virtual nics
--- - name: adnic hosts: localhost gather_facts: false become: no vars_prompt: - name: "username" prompt: "IPA username" private: no - name: "password" prompt: "IPA password" private: yes - name: "server" prompt: "server" private: no - name: "interface" prompt: "interface" private: no default: 'eth1' - name: "nicprofile" prompt: "dmz or other" private: no default: 'dmz' tasks: - name: Obtain SSO token with using username/password credentials ovirt_auth: url: https://ovirt-engine.lab/ovirt-engine/api username: "{{ username }}@internal" insecure: yes password: "{{ password }}" - ovirt_nics: auth: "{{ ovirt_auth }}" vm: "{{ server }}" state: "present" name: "{{ interface }}" network: "{{ nicprofile }}" profile: "{{ nicprofile }}"
Ansible playbook to create snapshots
- name: makesnap hosts: localhost gather_facts: false vars_prompt: - name: "username" prompt: "IPA username" private: no - name: "password" prompt: "IPA password" private: yes - name: "hostname" prompt: "hostname" private: no - name: "snapshotname" prompt: "snapshotname" private: no tasks: - name: Make snapshot ovirt_snapshots: auth: username: "{{ username }}@internal" password: "{{ password }}" insecure: True url: https://ovirt-engine.lab/ovirt-engine/api description: "{{ snapshotname }}" use_memory: true state: present timeout: 600 vm_name: "{{ hostname }}"