summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormischa <mischa@rx.high5.nl>2020-11-25 11:10:29 +0100
committermischa <mischa@rx.high5.nl>2020-11-25 11:10:29 +0100
commit39fdfd90afd997f11138e04a5d5f5703d296c298 (patch)
tree836c0f4b3adc7d01a59b4eeec6acce105979238b
parentff9ea80ec58bb13b10d04850549bff9d0c5fa416 (diff)
added deprovision function to notify.pl
-rw-r--r--email-deprovision.txt13
-rwxr-xr-xnotify.pl57
-rwxr-xr-xstartall.sh3
-rwxr-xr-xstopall.sh3
-rw-r--r--vms/vm01.txt2
5 files changed, 69 insertions, 9 deletions
diff --git a/email-deprovision.txt b/email-deprovision.txt
new file mode 100644
index 0000000..b413ce3
--- /dev/null
+++ b/email-deprovision.txt
@@ -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
diff --git a/notify.pl b/notify.pl
index d1bec3b..026487c 100755
--- a/notify.pl
+++ b/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"; }
diff --git a/startall.sh b/startall.sh
index 4678c75..fc283f7 100755
--- a/startall.sh
+++ b/startall.sh
@@ -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
diff --git a/stopall.sh b/stopall.sh
index 52091a0..b00a904 100755
--- a/stopall.sh
+++ b/stopall.sh
@@ -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
diff --git a/vms/vm01.txt b/vms/vm01.txt
index be49a2b..00fb8e8 100644
--- a/vms/vm01.txt
+++ b/vms/vm01.txt
@@ -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"