added deprovision function to notify.pl
This commit is contained in:
parent
ff9ea80ec5
commit
39fdfd90af
|
@ -0,0 +1,13 @@
|
|||
From: Mischa <mischa@openbsd.amsterdam>
|
||||
Subject: OpenBSD Amsterdam VM will be deprovisioned
|
||||
Content-Type: text/plain; charset=utf-8
|
||||
|
||||
Hi NAME,
|
||||
|
||||
Your VM, VMID on SERVER, will be deprovisioned today.
|
||||
|
||||
Mischa
|
||||
|
||||
--
|
||||
OpenBSD Amsterdam
|
||||
https://obsda.ms
|
57
notify.pl
57
notify.pl
|
@ -108,7 +108,7 @@ sub deployed {
|
|||
print $fh_email "$row\n";
|
||||
}
|
||||
close $fh_email;
|
||||
print "NOTIFIED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
|
||||
print "DEPLOYED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ sub stopped {
|
|||
print $fh_email "$row\n";
|
||||
}
|
||||
close $fh_email;
|
||||
print "NOTIFIED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
|
||||
print "STOPPED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ sub renewal {
|
|||
print $fh_email "$row\n";
|
||||
}
|
||||
close $fh_email;
|
||||
print "NOTIFIED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
|
||||
print "RENEWAL: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -265,6 +265,54 @@ sub notify {
|
|||
}
|
||||
}
|
||||
|
||||
sub deprovision {
|
||||
my %conf = %{$_[0]};
|
||||
my %vms = %{$_[1]};
|
||||
my $_etc = $conf{'conf'}{'ETC'};
|
||||
my $_vms = $conf{'conf'}{'VMS'};
|
||||
my $_tmpl = $conf{'conf'}{'TEMPLATES'};
|
||||
my $_server = $conf{'conf'}{'SERVER'};
|
||||
my $template = "$_tmpl/email-deprovision.txt";
|
||||
|
||||
my $year = strftime("%Y", localtime);
|
||||
my $month = strftime("%m", localtime);
|
||||
|
||||
for my $vm_name (sort keys %vms) {
|
||||
my $_date = $vms{$vm_name}{'date'};
|
||||
my $_payment = $vms{$vm_name}{'payment'};
|
||||
my $_donated = $vms{$vm_name}{'donated'};
|
||||
my $_name = $vms{$vm_name}{'name'};
|
||||
my $_email = $vms{$vm_name}{'email'};
|
||||
my $_hostname = $vms{$vm_name}{'hostname'};
|
||||
my $_boot = $vms{$vm_name}{'boot'} || "yes";
|
||||
|
||||
if ($_donated =~ /done/) { next; }
|
||||
if ($_donated =~ /expire/) { next; }
|
||||
if ($_donated =~ /sponsor/) { next; }
|
||||
if ($_donated =~ /renewal/) { next; }
|
||||
if ($_date =~ /$year\//) { next; }
|
||||
if ($_date =~ /\/$month\//) {
|
||||
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
|
||||
(my $_year, my $_month, my $_day) = split(/\//, $_date, 3);
|
||||
my $ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n');
|
||||
|
||||
open(my $fh, '<', $template);
|
||||
open my $fh_email, "|-", "/usr/sbin/sendmail -t";
|
||||
printf $fh_email "To: %s\n", $_email;
|
||||
while (my $row = <$fh>) {
|
||||
chomp $row;
|
||||
$row =~ s/NAME/$_firstname/g;
|
||||
$row =~ s/IP$/$ipaddress/g;
|
||||
$row =~ s/VMID/$vm_name/g;
|
||||
$row =~ s/SERVER/$_server/g;
|
||||
print $fh_email "$row\n";
|
||||
}
|
||||
close $fh_email;
|
||||
print "DEPROVISION: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# function to print all keys & values for debug purposes
|
||||
sub debug_parse {
|
||||
my %conf = %{$_[0]};
|
||||
|
@ -317,4 +365,5 @@ if ($function =~ /deployed/) { deployed(\%conf, \%vms); }
|
|||
elsif ($function =~ /stopped/) { stopped(\%conf, \%vms); }
|
||||
elsif ($function =~ /renewal/) { renewal(\%conf, \%vms); }
|
||||
elsif ($function =~ /notify/) { notify(\%conf, \%vms); }
|
||||
else { print "Specify function: deployed, stopped, renewal, notify\n"; }
|
||||
elsif ($function =~ /deprovision/) { deprovision(\%conf, \%vms); }
|
||||
else { print "Specify function: deployed, stopped, renewal, notify, deprovision\n"; }
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
SLEEP=240
|
||||
CPU=$(sysctl -n hw.ncpuonline)
|
||||
CPU=$((${CPU}-2))
|
||||
CPU=$(($(sysctl -n hw.ncpuonline)-2))
|
||||
|
||||
COUNTER=0
|
||||
for i in $(vmctl show | sort | awk '/ - / {print $9}' | xargs); do
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
SLEEP=30
|
||||
CPU=$(sysctl -n hw.ncpuonline)
|
||||
CPU=$((${CPU}-2))
|
||||
CPU=$(($(sysctl -n hw.ncpuonline)-2))
|
||||
|
||||
COUNTER=0
|
||||
for i in $(vmctl show | sort | awk '/ running / {print $9}' | xargs); do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mac="fe:e1:ab:dd:73:a4"
|
||||
ip="192.168.1.1"
|
||||
owner="testuser1"
|
||||
date="2018/09/02"
|
||||
date="2018/11/02"
|
||||
payment="70"
|
||||
donated=""
|
||||
name="Test1 User"
|
||||
|
|
Loading…
Reference in New Issue