summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormischa <mischa@rx.high5.nl>2021-04-13 21:24:44 +0200
committermischa <mischa@rx.high5.nl>2021-04-13 21:24:44 +0200
commit031c139096de86b720d8d085b86816432bedea48 (patch)
treec8a71f90a38a11e2ba42a8d850c6b0eb65c90f4b
parent64e24d553a9ff4c090166d48e196ede630f5f9b1 (diff)
added msg function for indiviual notification
-rwxr-xr-xnotify.pl77
-rw-r--r--templates/email-msg.txt17
2 files changed, 79 insertions, 15 deletions
diff --git a/notify.pl b/notify.pl
index c5f4efd..9304079 100755
--- a/notify.pl
+++ b/notify.pl
@@ -140,7 +140,7 @@ sub stopped {
}
if (grep(/$vm_name/, @stopped_vms)) {
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
- my $ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n');
+ my $ip4address = 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";
@@ -148,13 +148,13 @@ sub stopped {
while (my $row = <$fh>) {
chomp $row;
$row =~ s/NAME/$_firstname/g;
- $row =~ s/IP$/$ipaddress/g;
+ $row =~ s/IPV4/$ip4address/g;
$row =~ s/VMID/$vm_name/g;
$row =~ s/SERVER/$_server/g;
print $fh_email "$row\n";
}
close $fh_email;
- print "STOPPED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
+ print "STOPPED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
}
}
}
@@ -200,7 +200,7 @@ sub renewal {
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');
+ my $ip4address = 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";
@@ -208,7 +208,7 @@ sub renewal {
while (my $row = <$fh>) {
chomp $row;
$row =~ s/NAME/$_firstname/g;
- $row =~ s/IP$/$ipaddress/g;
+ $row =~ s/IPV4/$ip4address/g;
$row =~ s/VMID/$vm_name/g;
$row =~ s/SERVER/$_server/g;
@@ -221,7 +221,7 @@ sub renewal {
print $fh_email "$row\n";
}
close $fh_email;
- print "RENEWAL: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
+ print "RENEWAL: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
}
}
}
@@ -267,7 +267,7 @@ sub subscription {
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');
+ my $ip4address = 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";
@@ -275,7 +275,7 @@ sub subscription {
while (my $row = <$fh>) {
chomp $row;
$row =~ s/NAME/$_firstname/g;
- $row =~ s/IP$/$ipaddress/g;
+ $row =~ s/IPV4/$ip4address/g;
$row =~ s/VMID/$vm_name/g;
$row =~ s/SERVER/$_server/g;
@@ -288,7 +288,7 @@ sub subscription {
print $fh_email "$row\n";
}
close $fh_email;
- print "SUBSCRIPTION: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
+ print "SUBSCRIPTION: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
}
}
}
@@ -317,7 +317,7 @@ sub notify {
if (-e "$template") {
#if ($_boot =~ /yes/) {
(my $_firstname, my $_lastname) = split(/ /, $_name, 2);
- my $ipaddress = qx(grep -A2 $vm_name $_etc/dhcpd.conf | awk '/fixed-address/{print \$2}' | tr -d ';\n');
+ my $ip4address = 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";
@@ -325,7 +325,7 @@ sub notify {
while (my $row = <$fh>) {
chomp $row;
$row =~ s/NAME/$_firstname/g;
- $row =~ s/IP$/$ipaddress/g;
+ $row =~ s/IPV4/$ip4address/g;
$row =~ s/VMID/$vm_name/g;
$row =~ s/SERVER/$_server/g;
if ($row =~ /TIME\((.*)\)/) {
@@ -335,7 +335,53 @@ sub notify {
print $fh_email "$row\n";
}
close $fh_email;
- print "NOTIFIED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ipaddress\n";
+ print "NOTIFIED: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
+ }
+ }
+}
+
+sub msg {
+ 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-msg.txt";
+ my $server_number = $1 if $_server =~ /([0-9]+)/;
+ my $oddeven = $server_number % 2;
+
+ 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 ($function_variable =~ /empty/) { print "No VMID provided\n"; last; }
+ if ($function_variable =~ /$vm_name/) {
+ (my $_firstname, my $_lastname) = split(/ /, $_name, 2);
+ my $ip4address = 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/IPV4/$ip4address/g;
+ $row =~ s/VMID/$vm_name/g;
+ $row =~ s/SERVER/$_server/g;
+ if ($row =~ /TIME\((.*)\)/) {
+ my @TIMES = split(/,/, $1);
+ $row =~ s/TIME\(.*\)/$TIMES[$oddeven]/g;
+ }
+ print $fh_email "$row\n";
+ }
+ close $fh_email;
+ print "XXX: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
}
}
}
@@ -371,7 +417,7 @@ sub deprovision {
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');
+ my $ip4address = 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";
@@ -379,13 +425,13 @@ sub deprovision {
while (my $row = <$fh>) {
chomp $row;
$row =~ s/NAME/$_firstname/g;
- $row =~ s/IP$/$ipaddress/g;
+ $row =~ s/IPV4/$ip4address/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";
+ print "DEPROVISION: $_date, $_payment, $_name, $_email, $_hostname, $_server ($vm_name), $ip4address\n";
}
}
}
@@ -443,5 +489,6 @@ elsif ($function =~ /stopped/) { stopped(\%conf, \%vms); }
elsif ($function =~ /renewal/) { renewal(\%conf, \%vms); }
elsif ($function =~ /subscription/) { subscription(\%conf, \%vms); }
elsif ($function =~ /notify/) { notify(\%conf, \%vms); }
+elsif ($function =~ /msg/) { msg(\%conf, \%vms); }
elsif ($function =~ /deprovision/) { deprovision(\%conf, \%vms); }
else { print "Specify function: deployed, stopped, renewal, notify, deprovision\n"; }
diff --git a/templates/email-msg.txt b/templates/email-msg.txt
new file mode 100644
index 0000000..e5aa4fa
--- /dev/null
+++ b/templates/email-msg.txt
@@ -0,0 +1,17 @@
+From: admin
+Bcc: mischa@high5.nl
+Subject: OpenBSD Amsterdam - maintenance
+Content-Type: text/plain; charset=utf-8
+
+Hi NAME,
+
+You have a VM (VMID) running on SERVER.
+We will sysupgrade SERVER from OpenBSD 6.8 to OpenBSD 6.9.
+
+This will happen on 2021-xx-xx @ TIME(11:30,16:00) UTC.
+
+Mischa
+
+--
+OpenBSD Amsterdam
+https://obsda.ms