This commit is contained in:
conetadm
2025-03-10 08:26:47 +01:00
parent 7fe35abee0
commit fba07d666f
2 changed files with 166 additions and 142 deletions

View File

@@ -2,8 +2,8 @@
#use Data::Dumper;
if ($ARGV[0] eq "") {
printf "no mail address given to send report to. exit\n";
exit 1;
printf "no mail address given to send report to. exit\n";
exit 1;
}
@servers = qw/pveadmin4.conadm.de/;
@@ -14,37 +14,37 @@ for $server (@servers) {
@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;
$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;
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";
$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 "\n";
}
open HTML, ">output2.html";
@@ -75,8 +75,8 @@ printf HTML '<meta name=viewport content=width=device-width,initial-scale=1/>
';
printf HTML "<head>\n<body>\n";
open OUTPUT, ">output2.txt";
print "-- print vm information to console and in file output2.txt\n";
open OUTPUT, ">output2.csv";
print "-- print vm information to console and in file output2.csv\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;
@@ -85,45 +85,45 @@ $str = sprintf "<table border='1' id='example' class='display compact' width='10
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'}
);
$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/,/<br>/g;
$vms{$vm}{'diskusages'} =~ s/,/<br>/g;
$vms{$vm}{'tags'} =~ s/;/<br>/g;
$vms{$vm}{'disksizes'} =~ s/,/<br>/g;
$vms{$vm}{'diskusages'} =~ s/,/<br>/g;
$vms{$vm}{'tags'} =~ s/;/<br>/g;
$str = sprintf ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\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'}
);
$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;
@@ -131,7 +131,7 @@ printf HTML "\n</table>\n</body></html>";
close HTML;
print "-- send output2.txt as attachement via email\n";
print "-- send output2.csv as attachement via email\n";
open MAIL, ">mail2.tmp";
printf MAIL "TO: $ARGV[0]\n";
@@ -139,5 +139,6 @@ printf MAIL "FROM: CONET Services Monitoring Reporter <help\@conet.de\n";
printf MAIL "SUBJECT: Proxmox VE Report Cluster Admin\n";
printf MAIL "X-CONET-SRC: conetadm\@conlxobs1:/scripts/conetadm/pve-reporting/get_vminfo_clu2.pl\n";
printf MAIL "\n\n";
`echo "" | mutt -H mail2.tmp -a output2.txt -- $ARGV[0]`;
`echo "" | mutt -H mail2.tmp -a output2.csv -- $ARGV[0]`;
unlink "mail2.tmp";