From 886dfc2b0da4ad415f0c1dced014dff47aaebd65 Mon Sep 17 00:00:00 2001 From: ageissler Date: Mon, 3 Mar 2025 08:23:09 +0100 Subject: [PATCH] =?UTF-8?q?pve-reporting/get=5Fvminfo=5Fclu2.pl=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pve-reporting/get_vminfo_clu2.pl | 119 +++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 pve-reporting/get_vminfo_clu2.pl diff --git a/pve-reporting/get_vminfo_clu2.pl b/pve-reporting/get_vminfo_clu2.pl new file mode 100644 index 0000000..c0ef7aa --- /dev/null +++ b/pve-reporting/get_vminfo_clu2.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +#use Data::Dumper; + +if ($ARGV[0] eq "") { + printf "no mail address given to send report to. exit\n"; + exit 1; +} + +@servers = qw/pveadmin4.conadm.de/; + +print "-- get general info from every host\n"; +for $server (@servers) { + print "--- server $server\n"; + @serverinfo = `ssh -q -l root $server qm list | sed "s/\$/$server/" | grep -v VMID 2> /dev/null`; + foreach (@serverinfo) { + ($vmid, + $vms{$1}{'name'}, + $vms{$1}{'status'}, + $vms{$1}{'memory'}, + $vms{$1}{'bootdisk'}, + $vms{$1}{'pid'}, + $vms{$1}{'host'} + ) = $_ =~ / *([0-9]{3,4}) *([^ ]*) *([a-z]*) *([0-9]*) *([0-9.]*) *([0-9]*) *($server)/gm; + } + $vmlist=""; + foreach $vmid (keys %vms) { + $vmlist = $vmlist . "$vmid " if ($vms{$vmid}{'host'} eq $server); + } + chomp $vmlist; + + print "---- get more details from vms $vmlist\n"; + @more = `ssh -q -l root $server bash /opt/pve-reporting/get_vmid_info.sh $vmlist 2> /dev/null`; + foreach (@more) { + chomp; + ( $vmid, + $vms{$1}{'os'}, + $vms{$1}{'disksizes'}, + $vms{$1}{'diskusages'}, + $vms{$1}{'sockets'}, + $vms{$1}{'cores'}, + $vms{$1}{'description'}, + $vms{$1}{'tags'}, + $vms{$1}{'cdrom'} + ) = $_ =~ /([^|]*).([^|]*).([^|]*).([^|]*).([^|]*).([^|]*).([^|]*).([^|]*).([^|]*)$/gm; + print "----- ID $vmid\n"; + } + print "\n"; +} + +#print Dumper(%vms); + +open HTML, ">output2.html"; +printf HTML "\n\n"; +open OUTPUT, ">output2.txt"; +print "-- print vm information to console and in file output2.txt\n"; +$str = sprintf "VMID|NAME|OS|DISKSIZE(S)|DISKUSAGE(S)|SOCKETS|CORES|MEMORY(MB)|BOOTDISK(GB)|DESCRIPTION|TAGS|STATUS|HOST|PID|CDROM\n"; +printf $str; +printf OUTPUT $str; + +$str = sprintf "\n\n"; +printf HTML $str; +foreach $vm (sort keys %vms) { + $str = sprintf ("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n", + $vm, + $vms{$vm}{'name'}, + $vms{$vm}{'os'}, + $vms{$vm}{'disksizes'}, + $vms{$vm}{'diskusages'}, + $vms{$vm}{'sockets'}, + $vms{$vm}{'cores'}, + $vms{$vm}{'memory'}, + $vms{$vm}{'bootdisk'}, + $vms{$vm}{'description'}, + $vms{$vm}{'tags'}, + $vms{$vm}{'status'}, + $vms{$vm}{'host'}, + $vms{$vm}{'pid'}, + $vms{$vm}{'cdrom'} + ); + printf $str; + printf OUTPUT $str; + + $vms{$vm}{'disksizes'} =~ s/,/
/g; + $vms{$vm}{'diskusages'} =~ s/,/
/g; + $vms{$vm}{'tags'} =~ s/;/
/g; + $str = sprintf ("\n", + $vm, + $vms{$vm}{'name'}, + $vms{$vm}{'os'}, + $vms{$vm}{'disksizes'}, + $vms{$vm}{'diskusages'}, + $vms{$vm}{'sockets'}, + $vms{$vm}{'cores'}, + $vms{$vm}{'memory'}, + $vms{$vm}{'bootdisk'}, + $vms{$vm}{'description'}, + $vms{$vm}{'tags'}, + $vms{$vm}{'status'}, + $vms{$vm}{'host'}, + $vms{$vm}{'pid'}, + $vms{$vm}{'cdrom'} + ); + printf HTML $str; +} +close OUTPUT; +printf HTML "\n
VMIDNAMEOSDISKSIZE(S)DISKUSAGE(S)SOCKETSCORESMEMORY(MB)BOOTDISK(GB)DESCRIPTIONTAGSSTATUSHOSTPIDCDROM
%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s
\n"; +close HTML; + + +print "-- send output2.txt as attachement via email\n"; + +open MAIL, ">mail2.tmp"; +printf MAIL "TO: $ARGV[0]\n"; +printf MAIL "FROM: CONET Services Monitoring Reporter