diff --git a/notify.pl b/notify.pl index 6a9b9b3..248577c 100755 --- a/notify.pl +++ b/notify.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# Copyright (c) 2019-2021 Mischa Peters +# Copyright (c) 2019-2022 Mischa Peters # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,7 @@ # vmm(4)/vmd(8) VM notify script for OpenBSD Amsterdam # 2020/05/17 initial release # 2021/05/09 complete restructure and KISS +# 2022/11/13 added price structure for notifications # use 5.024; use strict; @@ -30,6 +31,11 @@ use File::Basename; my $function = $ARGV[0] || "empty"; my $function_variable = $ARGV[1] || "empty"; +# define the prices for the different components of the VM +my $base_price = '60'; +my %memory_prices = ('2G' => '10', '4G' => '30', '8G' => '70'); +my %hdd_prices = ('50G' => '50', '100G' => '100', '150G' => '150', '200G' => '200'); + # fuction to parse _deploy.conf and vm*.txt files # all variables are stripped and added to either %vms or %conf sub get_variables { @@ -97,6 +103,12 @@ sub mailout { my $_email = $vms{$vm_name}{'email'}; my $_hostname = $vms{$vm_name}{'hostname'}; my $_username = $vms{$vm_name}{'username'}; + my $_memory = $vms{$vm_name}{'memory'} || ''; + my $_disk2 = $vms{$vm_name}{'disk2'} || ''; + + my $memory_price = $memory_prices{$_memory} || '0'; + my $hdd_price = $hdd_prices{$_disk2} || '0'; + my $price = $base_price + $memory_price + $hdd_price; (my $_firstname, my $_lastname) = split(/ /, $_name, 2); (my $_year, my $_month, my $_day) = split(/\//, $_date, 3); @@ -125,6 +137,7 @@ sub mailout { $row =~ s/TOTAL_VMS/$total_vms/g; $row =~ s/TOTAL_HOSTS/$total_hosts/g; $row =~ s/PAYMENT/$_payment/g; + $row =~ s/PRICE/$price/g; if ($row =~ /TIME\((.*)\)/) { my @TIMES = split(/,/, $1); @@ -133,7 +146,7 @@ sub mailout { print $fh_email "$row\n"; } close $fh_email; - print "$function: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n"; + print "$function: $_date, $_payment ($price), $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n"; } }