diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index b20248c9..6c57f7f0 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1086,6 +1086,8 @@ sub _set_paths 'postgresql.conf' => "/var/lib/pgsql/data/postgresql.conf", pxe_default => "/var/lib/tftpboot/pxelinux.cfg/default", pxe_uefi => "/var/lib/tftpboot/pxelinux.cfg/uefi", + postfix_main => "/etc/postfix/main.cf", + postfix_relay_password => "/etc/postfix/relay_password", ssh_config => "/etc/ssh/ssh_config", 'type.striker' => "/etc/anvil/type.striker", 'type.dr' => "/etc/anvil/type.dr", @@ -1105,6 +1107,7 @@ sub _set_paths fences_unified_metadata => "/var/www/html/fences_unified_metadata.xml", }, directories => { + alert_emails => "/var/spool/anvil", anvil => "/etc/anvil", backups => "/root/anvil-backups", 'cgi-bin' => "/var/www/cgi-bin", @@ -1204,6 +1207,7 @@ sub _set_paths ps => "/usr/bin/ps", psql => "/usr/bin/psql", 'postgresql-setup' => "/usr/bin/postgresql-setup", + postmap => "/usr/sbin/postmap", pwd => "/usr/bin/pwd", pvs => "/usr/sbin/pvs", pvscan => "/usr/sbin/pvscan", diff --git a/Anvil/Tools/DRBD.pm b/Anvil/Tools/DRBD.pm index fe1afc93..63ccac4f 100755 --- a/Anvil/Tools/DRBD.pm +++ b/Anvil/Tools/DRBD.pm @@ -1045,7 +1045,10 @@ sub update_global_common # Read in the existing config. my $new_global_common = ""; - my $old_global_common = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'global-common.conf'}}); + my $old_global_common = $anvil->Storage->read_file({ + debug => $debug, + file => $anvil->data->{path}{configs}{'global-common.conf'}, + }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_global_common => $old_global_common }}); foreach my $line (split/\n/, $old_global_common) { diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index e5e711d7..fa62ebb9 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -558,7 +558,7 @@ sub configure_pgsql my $created_pgpass = 0; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { 'path::secure::postgres_pgpass' => $anvil->data->{path}{secure}{postgres_pgpass}, - "database::${uuid}::password" => $anvil->data->{database}{$uuid}{password}, + "database::${uuid}::password" => $anvil->Log->is_secure($anvil->data->{database}{$uuid}{password}), }}); if ((not -e $anvil->data->{path}{secure}{postgres_pgpass}) && ($anvil->data->{database}{$uuid}{password})) { @@ -1441,8 +1441,8 @@ sub get_recipients my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_recipients()" }}); - ### TODO: Read in 'notifications' - my $query = " + + my $query = " SELECT recipient_uuid, recipient_name, @@ -2662,6 +2662,11 @@ sub get_mail_servers my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->initialize()" }}); + if (exists $anvil->data->{mail_servers}) + { + delete $anvil->data->{mail_servers}; + } + my $query = " SELECT mail_server_uuid, @@ -2698,7 +2703,7 @@ FROM mail_server_address => $mail_server_address, mail_server_port => $mail_server_port, mail_server_username => $mail_server_username, - mail_server_password => $mail_server_password, + mail_server_password => $anvil->Log->is_secure($mail_server_password), mail_server_security => $mail_server_security, mail_server_authentication => $mail_server_authentication, mail_server_helo_domain => $mail_server_helo_domain, @@ -2716,7 +2721,7 @@ FROM "mail_servers::mail_server::${mail_server_uuid}}::mail_server_address" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_address}, "mail_servers::mail_server::${mail_server_uuid}}::mail_server_port" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_port}, "mail_servers::mail_server::${mail_server_uuid}}::mail_server_username" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_username}, - "mail_servers::mail_server::${mail_server_uuid}}::mail_server_password" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password}, + "mail_servers::mail_server::${mail_server_uuid}}::mail_server_password" => $anvil->Log->is_secure($anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password}), "mail_servers::mail_server::${mail_server_uuid}}::mail_server_security" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_security}, "mail_servers::mail_server::${mail_server_uuid}}::mail_server_authentication" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_authentication}, "mail_servers::mail_server::${mail_server_uuid}}::mail_server_helo_domain" => $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_helo_domain}, @@ -2727,39 +2732,40 @@ FROM $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "mail_servers::address_to_uuid::${mail_server_address}" => $anvil->data->{mail_servers}{address_to_uuid}{$mail_server_address}, }}); - - ### TODO; - # Look up variables for this server. -=cut - my $query = " + } + + # Look up variables for this server. + $query = " SELECT variable_name, variable_value FROM variables WHERE - variable_source_uuid = ".$anvil->Database->quote($host_uuid)." + variable_name LIKE 'mail_server::last_used::%' +AND + variable_source_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)." AND variable_source_table = 'hosts' ;"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); - - my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); - my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); + + my $local_host = $anvil->_short_host_name; + $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + results => $results, + count => $count, + local_host => $local_host, + }}); + foreach my $row (@{$results}) + { + my $variable_name = $row->[0]; + my $variable_value = $row->[1]; + $anvil->data->{mail_servers}{use_order}{$local_host}{variables}{$variable_name} = $variable_value; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - results => $results, - count => $count, + "mail_servers::use_order::${local_host}::variables::${variable_name}" => $anvil->data->{mail_servers}{use_order}{$local_host}{variables}{$variable_name}, }}); - foreach my $row (@{$results}) - { - my $variable_name = $row->[0]; - my $variable_value = $row->[1]; - $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{$variable_name} = $variable_value; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "machine::host_uuid::${host_uuid}::hosts::variables::${variable_name}" => $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{$variable_name}, - }}); - } -=cut } return(0); @@ -2889,6 +2895,8 @@ WHERE =head2 get_notifications +By default, any machine generating an alert will go to recipients at their default level. Entries in this table allow for "overrides", either by Striker host or by Anvil! node / dr host set. + This gets the list of configured mail servers. =cut @@ -3346,7 +3354,7 @@ sub insert_or_update_anvils anvil_uuid => $anvil_uuid, anvil_description => $anvil_description, anvil_name => $anvil_name, - anvil_password => $anvil_password, + anvil_password => $anvil->Log->is_secure($anvil_password), anvil_node1_host_uuid => $anvil_node1_host_uuid, anvil_node2_host_uuid => $anvil_node2_host_uuid, anvil_dr1_host_uuid => $anvil_dr1_host_uuid, @@ -3501,7 +3509,7 @@ INSERT INTO ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ); "; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { query => $query }}); $anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__}); } else @@ -3545,7 +3553,7 @@ WHERE $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_anvil_name => $old_anvil_name, old_anvil_description => $old_anvil_description, - old_anvil_password => $old_anvil_password, + old_anvil_password => $anvil->Log->is_secure($old_anvil_password), old_anvil_node1_host_uuid => $old_anvil_node1_host_uuid, old_anvil_node2_host_uuid => $old_anvil_node2_host_uuid, old_anvil_dr1_host_uuid => $old_anvil_dr1_host_uuid, @@ -3574,7 +3582,7 @@ SET WHERE anvil_uuid = ".$anvil->Database->quote($anvil_uuid)." "; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { query => $query }}); $anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__}); } } @@ -6295,7 +6303,7 @@ If needed to authenticate, this is the password portion passed along with the C< =head3 mail_server_port (optional, default depends on 'mail_server_security') -If set, this is the TCP port used when connecting to th mail server. If not set, the port is detemined based on the C<< mail_server_security >>. If it is C<< none >> or C<< starttls >>, the port is C<< 143 >>. if is it C<< ssl_tls >>, the port is C<< 993 >>. +If set, this is the TCP port used when connecting to th mail server. If not set, the port is detemined based on the C<< mail_server_security >>. If it is C<< none >> or C<< starttls >>, the port is C<< 587 >>. if is it C<< ssl_tls >>, the port is C<< 993 >>. =head3 mail_server_security (optional) @@ -6303,9 +6311,9 @@ This is the connection security used when establishing a connection to the mail This can be set to anything you wish, but the expected values are; -* C<< none >> (default port 143) -* C<< starttls >> (default port 143) -* C<< ssl_tls >> (default port 993) +* C<< none >> (default port 587) +* C<< starttls >> (default port 587) +* C<< ssl_tls >> (default port 465) B<< NOTE >> - If any other string is passed and C<< mail_server_port >> is not set, port C<< 143 >> will be used. @@ -6346,7 +6354,7 @@ sub insert_or_update_mail_servers mail_server_address => $mail_server_address, mail_server_authentication => $mail_server_authentication, mail_server_helo_domain => $mail_server_helo_domain, - mail_server_password => $mail_server_password, + mail_server_password => $anvil->Log->is_secure($mail_server_password), mail_server_port => $mail_server_port, mail_server_security => $mail_server_security, mail_server_username => $mail_server_username, @@ -6445,10 +6453,10 @@ WHERE } if (not $mail_server_port) { - $mail_server_port = 143; + $mail_server_port = 587; if ($mail_server_security eq "ssl_tls") { - $mail_server_port = 993; + $mail_server_port = 465; } } @@ -6485,7 +6493,7 @@ INSERT INTO ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ); "; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { query => $query }}); $anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__}); } else @@ -6532,7 +6540,7 @@ WHERE old_mail_server_address => $old_mail_server_address, old_mail_server_authentication => $old_mail_server_authentication, old_mail_server_helo_domain => $old_mail_server_helo_domain, - old_mail_server_password => $old_mail_server_password, + old_mail_server_password => $anvil->Log->is_secure($old_mail_server_password), old_mail_server_port => $old_mail_server_port, old_mail_server_security => $old_mail_server_security, old_mail_server_username => $old_mail_server_username, diff --git a/Anvil/Tools/Email.pm b/Anvil/Tools/Email.pm index 9e082616..39dd16cd 100755 --- a/Anvil/Tools/Email.pm +++ b/Anvil/Tools/Email.pm @@ -4,17 +4,23 @@ package Anvil::Tools::Email; # mailx. # +### TODO: By default, a recipient receives all alerts at their default level. Later, we'll add an +### override table to allow a user to ignore a given striker or Anvil! node / dr host set. So +### creating this list is no longer needed. + use strict; use warnings; -use Scalar::Util qw(weaken isweak); use Data::Dumper; +use Scalar::Util qw(weaken isweak); +use Text::Diff; our $VERSION = "3.0.0"; my $THIS_FILE = "Email.pm"; ### Methods; -# check_alert_recipients -# check_postfix +# check_queue +# check_config +# =pod @@ -76,103 +82,103 @@ sub parent ############################################################################################################# -=head2 check_alert_recipients +=head2 check_config -This loops through all known hosts and all known C<< recipients >> and any C<< hosts >> that don't have a corresponding entry in C<< notifications >>. When found, an entry is created using the recipient's new level. +This method checks the current postfix server configuration to see if it needs to be updated, then checks to see if the local C<< postfix >> daemin is enabled and started. + +If any problem is encountered, C<< 1 >> is returned. Otherwise, if all is well, C<< 0 >> is returned. + +This method takes no parameters. =cut -sub check_alert_recipients +sub check_config { my $self = shift; my $parameter = shift; my $anvil = $self->parent; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Email->check_config()" }}); - # Get a list of all recipients. - $anvil->Database->get_recipients({debug => 2}); + my $problem = 0; - # Get a list of hosts. - $anvil->Database->get_hosts({debug => 2}); + # We check to see if there are any emails in the queue. If we see queued emails for more than five + # minutes, and a second mail server is configured, we'll automatically reconfigure for the next + # known server. + my ($oldest_message) = $anvil->Email->check_queue({debug => $debug}); + if ($oldest_message > 600) + { + $anvil->Email->swap_server({debug => $debug}); + } - # Get the notification list - $anvil->Database->get_notifications({debug => 2}); + # If not configured look in variables for 'mail_server::last_used::'. The first one + # that doesn't have an existing variable will be used. If all known mail servers have variables, the + # oldest is used. + # + # In any case where the mail server is configured, the server that is used has their + # 'mail_server::last_used::' variable set to the current time stamp. - # Now loop! - foreach my $host_uuid (keys %{$anvil->data->{hosts}{host_uuid}}) + # Is the postfix daemon running? + my $reconfigure = 1; + if ($reconfigure) { - my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name}; + # Get the list of mail servers. + $anvil->Database->get_mail_servers({debug => $debug}); - # Loop through recipients. - foreach my $recipient_uuid (keys %{$anvil->data->{recipients}{recipient_uuid}}) + ### TODO: This just bootstraps the initial config + my $used_mail_server_count = exists $anvil->data->{mail_servers}{use_order} ? keys %{$anvil->data->{mail_servers}{use_order}} : 0; + if (not $used_mail_server_count) { - my $recipient_new_level = $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{recipient_new_level}; - - # Now see if there's already an entry in notifications. - my $exists = 0; - foreach my $notification_uuid (keys %{$anvil->data->{notifications}{notification_uuid}}) + # Just pick the first one. + foreach my $mail_server_uuid (keys %{$anvil->data->{mail_servers}{mail_server}}) { - my $notification_recipient_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_recipient_uuid}; - my $notification_host_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid}; - if (($host_uuid eq $notification_host_uuid) && ($recipient_uuid eq $notification_recipient_uuid)) - { - $exists = 1; - last; - } - } - - # Did we find an entry? - if (not $exists) - { - # Nope, save it. - my ($notification_uuid) = $anvil->Database->insert_or_update_notifications({ - debug => 2, - notification_recipient_uuid => $recipient_uuid, - notification_host_uuid => $host_uuid, - notification_alert_level => $recipient_new_level, + $anvil->Email->_configure_for_server({ + debug => $debug, + mail_server_uuid => $mail_server_uuid, }); + + last; } } } - return(0); + return($problem); } -=head2 check_postfix - -This method checks the current postfix server configuration to see if it needs to be updated, then checks to see if the local C<< postfix >> daemin is enabled and started. - -If any problem is encountered, C<< 1 >> is returned. Otherwise, if all is well, C<< 0 >> is returned. - -Parameters; - -=head3 config (optional, default '1') - -If set to C<< 0 >>, the configuration is not checked or updated. +=head2 check_queue -=head3 daemon (optional, default '1') +This method looks to see how many email messages are in the send queue and how long they've been there. The age of the older queued message is returned (in seconds). -If set to C<< 0 >>, the C<< postfix >> daemon is not checked or started. +This method takes no parameters. =cut -sub check_postfix +sub check_queue { my $self = shift; my $parameter = shift; my $anvil = $self->parent; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Email->check_queue()" }}); - my $problem = 0; - my $config = defined $parameter->{config} ? $parameter->{config} : 1; - my $daemon = defined $parameter->{daemon} ? $parameter->{daemon} : 1; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - config => $config, - daemon => $daemon, - }}); + my $oldest_message = 0; + ### TODO + # If configured/running, the number of messages in queue is checked. If '0', + # 'mail_server::queue_empty' is updated with the current time. If 1 or more, the time since the queue + # was last 0 is checked. If > 300, the mail server is reconfigured to use the mail server with the + # oldest 'mail_server::last_used::' time. - return($problem); + return($oldest_message); +} + +=head2 swap_server + + +=cut +sub swap_server +{ + } # =head3 @@ -184,3 +190,557 @@ sub check_postfix ############################################################################################################# # Private functions # ############################################################################################################# + +# This does the actual work of configuring postfix for a give mail server. Returns '1' if reconfigured, +# returns '0' if not. +sub _configure_for_server +{ + my $self = shift; + my $parameter = shift; + my $anvil = $self->parent; + my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Email->_configure_for_server()" }}); + + my $reload = 0; + my $mail_server_uuid = defined $parameter->{mail_server_uuid} ? $parameter->{mail_server_uuid} : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + mail_server_uuid => $mail_server_uuid, + }}); + + if (not $mail_server_uuid) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Email->register()", parameter => "_configure_for_server" }}); + return($reload); + } + + if (not exists $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}) + { + # Try loading the mail server data. + $anvil->Database->get_mail_servers({debug => $debug}); + + if (not exists $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}) + { + # Invalid UUID / mail server + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0141", variables => { uuid => $mail_server_uuid }}); + return($reload); + } + } + + ### Check / update / create relay_password + my $mail_server_address = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_address}; + my $mail_server_port = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_port}; + my $mail_server_username = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_username}; + my $mail_server_password = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_password}; + my $mail_server_security = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_security}; + my $mail_server_authentication = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_authentication}; + my $mail_server_helo_domain = $anvil->data->{mail_servers}{mail_server}{$mail_server_uuid}{mail_server_helo_domain}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + mail_server_address => $mail_server_address, + mail_server_port => $mail_server_port, + mail_server_username => $mail_server_username, + mail_server_password => $mail_server_password, + mail_server_security => $mail_server_security, + mail_server_authentication => $mail_server_authentication, + mail_server_helo_domain => $mail_server_helo_domain, + }}); + + my $old_postfix_relay_file = ""; + if (-e $anvil->data->{path}{configs}{postfix_relay_password}) + { + $old_postfix_relay_file = $anvil->Storage->read_file({ + debug => $debug, + file => $anvil->data->{path}{configs}{postfix_relay_password}, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { + old_postfix_relay_file => $old_postfix_relay_file, + }}); + } + + my $new_postfix_relay_file = "[".$mail_server_address."]:".$mail_server_port." ".$mail_server_username.":".$mail_server_password."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { + new_postfix_relay_file => $new_postfix_relay_file, + }}); + + if ($new_postfix_relay_file ne $old_postfix_relay_file) + { + # Create the new relay file. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0530"}); + $reload = 1; + my $error = $anvil->Storage->write_file({ + backup => 0, + debug => $debug, + body => $new_postfix_relay_file, + file => $anvil->data->{path}{configs}{postfix_relay_password}, + mode => "0644", + user => "root", + group => "root", + overwrite => 1, + secure => 1, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + reload => $reload, + error => $error, + }}); + + # Generate the binary version. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0531"}); + my ($output, $return_code) = $anvil->System->call({ debug => $debug, shell_call => $anvil->data->{path}{exe}{postmap}." ".$anvil->data->{path}{configs}{postfix_relay_password} }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + output => $output, + return_code => $return_code, + }}); + } + + ### Check / update main.cf + my $new_postfix_main = ""; + my $old_postfix_main = $anvil->Storage->read_file({ + debug => $debug, + file => $anvil->data->{path}{configs}{postfix_main}, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + old_postfix_relay_file => $old_postfix_relay_file, + }}); + + my $last_line = ""; + my $relayhost_seen = 0; + my $relayhost_line = "relayhost = [".$mail_server_address."]:".$mail_server_port; + my $smtp_helo_name_seen = 0; + my $smtp_helo_name_line = "smtp_helo_name = ".$anvil->_domain_name(); + my $smtp_use_tls_seen = 0; + my $smtp_use_tls_line = "smtp_use_tls = yes"; + my $smtp_sasl_auth_enable_seen = 0; + my $smtp_sasl_auth_enable_line = "smtp_sasl_auth_enable = yes"; + my $smtp_sasl_password_maps_seen = 0; + my $smtp_sasl_password_maps_line = "smtp_sasl_password_maps = hash:".$anvil->data->{path}{configs}{postfix_relay_password}; + my $smtp_sasl_security_options_seen = 0; + my $smtp_sasl_security_options_line = "smtp_sasl_security_options ="; + my $smtp_tls_CAfile_seen = 0; + my $smtp_tls_CAfile_line = "smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + relayhost_line => $relayhost_line, + smtp_helo_name_line => $smtp_helo_name_line, + smtp_use_tls_line => $smtp_use_tls_line, + smtp_sasl_auth_enable_line => $smtp_sasl_auth_enable_line, + smtp_sasl_password_maps_line => $smtp_sasl_password_maps_line, + smtp_sasl_security_options_line => $smtp_sasl_security_options_line, + smtp_tls_CAfile_line => $smtp_tls_CAfile_line, + }}); + + # Before we start, we'll see if our variables have been seen. If not, we'll inject the below the + # 'relay_host' section. + foreach my $line (split/\n/, $old_postfix_main) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); + if ($line =~ /^relayhost = /) + { + $relayhost_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { relayhost_seen => $relayhost_seen }}); + } + if ($line =~ /^smtp_helo_name =/) + { + $smtp_helo_name_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_helo_name_seen => $smtp_helo_name_seen }}); + } + if ($line =~ /^smtp_use_tls =/) + { + $smtp_use_tls_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_use_tls_seen => $smtp_use_tls_seen }}); + } + if ($line =~ /^smtp_sasl_auth_enable =/) + { + $smtp_sasl_auth_enable_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_sasl_auth_enable_seen => $smtp_sasl_auth_enable_seen }}); + } + if ($line =~ /^smtp_sasl_password_maps =/) + { + $smtp_sasl_password_maps_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_sasl_password_maps_seen => $smtp_sasl_password_maps_seen }}); + } + if ($line =~ /^smtp_sasl_security_options =/) + { + $smtp_sasl_security_options_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_sasl_security_options_seen => $smtp_sasl_security_options_seen }}); + } + if ($line =~ /^smtp_tls_CAfile =/) + { + $smtp_tls_CAfile_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { smtp_tls_CAfile_seen => $smtp_tls_CAfile_seen }}); + } + } + + foreach my $line (split/\n/, $old_postfix_main) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); + if ($line =~ /^relayhost = /) + { + $relayhost_seen = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { relayhost_seen => $relayhost_seen }}); + + if ($line ne $relayhost_line) + { + # Rewrite the line. + $line = $relayhost_line; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:reload' => $reload, + }}); + } + } + if (($last_line eq "#relayhost = [an.ip.add.ress]") && ($line eq "") && (not $relayhost_seen)) + { + # Never configured before, inject our line. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0532"}); + $new_postfix_main .= $relayhost_line."\n"; + $relayhost_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:relayhost_line' => $relayhost_line, + 's2:relayhost_seen' => $relayhost_seen, + 's3:reload' => $reload, + }}); + + # Inject any other variables we've not seen yet. + if (not $smtp_helo_name_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_helo_name_line }}); + $reload = 1; + $smtp_helo_name_seen = 1; + $new_postfix_main .= $smtp_helo_name_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_helo_name_line' => $smtp_helo_name_line, + 's2:smtp_helo_name_seen' => $smtp_helo_name_seen, + 's3:reload' => $reload, + }}); + } + if (not $smtp_use_tls_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_use_tls_line }}); + $reload = 1; + $smtp_use_tls_seen = 1; + $new_postfix_main .= $smtp_use_tls_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_use_tls_line' => $smtp_use_tls_line, + 's2:smtp_use_tls_seen' => $smtp_use_tls_seen, + 's3:reload' => $reload, + }}); + } + if (not $smtp_sasl_auth_enable_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_auth_enable_line }}); + $reload = 1; + $smtp_sasl_auth_enable_seen = 1; + $new_postfix_main .= $smtp_sasl_auth_enable_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_auth_enable_line' => $smtp_sasl_auth_enable_line, + 's2:smtp_sasl_auth_enable_seen' => $smtp_sasl_auth_enable_seen, + 's3:reload' => $reload, + }}); + } + if (not $smtp_sasl_password_maps_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_password_maps_line }}); + $reload = 1; + $smtp_sasl_password_maps_seen = 1; + $new_postfix_main .= $smtp_sasl_password_maps_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_password_maps_line' => $smtp_sasl_password_maps_line, + 's2:smtp_sasl_password_maps_seen' => $smtp_sasl_password_maps_seen, + 's3:reload' => $reload, + }}); + } + if (not $smtp_sasl_security_options_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_security_options_line }}); + $reload = 1; + $smtp_sasl_security_options_seen = 1; + $new_postfix_main .= $smtp_sasl_security_options_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_security_options_line' => $smtp_sasl_security_options_line, + 's2:smtp_sasl_security_options_seen' => $smtp_sasl_security_options_seen, + 's3:reload' => $reload, + }}); + } + if (not $smtp_tls_CAfile_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_tls_CAfile_line }}); + $reload = 1; + $smtp_tls_CAfile_seen = 1; + $new_postfix_main .= $smtp_tls_CAfile_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_tls_CAfile_line' => $smtp_tls_CAfile_line, + 's2:smtp_tls_CAfile_seen' => $smtp_tls_CAfile_seen, + 's3:reload' => $reload, + }}); + } + } + + # Any other existing config lines + if ($line =~ /^smtp_helo_name =/) + { + if ($line ne $smtp_helo_name_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_tls_CAfile_line, + }}); + $line = $smtp_helo_name_line; + $smtp_helo_name_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_helo_name_seen' => $smtp_helo_name_seen, + 's2:reload' => $reload, + }}); + } + } + if ($line =~ /^smtp_use_tls =/) + { + if ($line ne $smtp_use_tls_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_use_tls_line, + }}); + $line = $smtp_use_tls_line; + $smtp_use_tls_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_use_tls_seen' => $smtp_use_tls_seen, + 's2:reload' => $reload, + }}); + } + } + if ($line =~ /^smtp_sasl_auth_enable =/) + { + if ($line ne $smtp_sasl_auth_enable_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_sasl_auth_enable_line, + }}); + $line = $smtp_sasl_auth_enable_line; + $smtp_sasl_auth_enable_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_sasl_auth_enable_seen' => $smtp_sasl_auth_enable_seen, + 's2:reload' => $reload, + }}); + } + } + if ($line =~ /^smtp_sasl_password_maps =/) + { + if ($line ne $smtp_sasl_password_maps_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_sasl_password_maps_line, + }}); + $line = $smtp_sasl_password_maps_line; + $smtp_sasl_password_maps_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_sasl_password_maps_seen' => $smtp_sasl_password_maps_seen, + 's2:reload' => $reload, + }}); + } + } + if ($line =~ /^smtp_sasl_security_options =/) + { + if ($line ne $smtp_sasl_security_options_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_sasl_security_options_line, + }}); + $line = $smtp_sasl_security_options_line; + $smtp_sasl_security_options_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_sasl_security_options_seen' => $smtp_sasl_security_options_seen, + 's2:reload' => $reload, + }}); + } + } + if ($line =~ /^smtp_tls_CAfile =/) + { + if ($line ne $smtp_tls_CAfile_line) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0534", variables => { + old_line => $line, + new_line => $smtp_tls_CAfile_line, + }}); + $line = $smtp_tls_CAfile_line; + $smtp_tls_CAfile_seen = 1; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:line' => $line, + 's2:smtp_tls_CAfile_seen' => $smtp_tls_CAfile_seen, + 's2:reload' => $reload, + }}); + } + } + + $new_postfix_main .= $line."\n"; + $last_line = $line; + } + if (not $relayhost_seen) + { + # We apparently missed our injection point, append it to the end of the file. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $relayhost_line }}); + $new_postfix_main .= $relayhost_line."\n"; + $reload = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:relayhost_line' => $relayhost_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_helo_name_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_helo_name_line }}); + $reload = 1; + $new_postfix_main .= $smtp_helo_name_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_helo_name_line' => $smtp_helo_name_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_use_tls_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_use_tls_line }}); + $reload = 1; + $new_postfix_main .= $smtp_use_tls_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_use_tls_line' => $smtp_use_tls_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_sasl_auth_enable_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_auth_enable_line }}); + $reload = 1; + $new_postfix_main .= $smtp_sasl_auth_enable_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_auth_enable_line' => $smtp_sasl_auth_enable_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_sasl_password_maps_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_password_maps_line }}); + $reload = 1; + $new_postfix_main .= $smtp_sasl_password_maps_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_password_maps_line' => $smtp_sasl_password_maps_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_sasl_security_options_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_sasl_security_options_line }}); + $reload = 1; + $new_postfix_main .= $smtp_sasl_security_options_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_sasl_security_options_line' => $smtp_sasl_security_options_line, + 's2:reload' => $reload, + }}); + } + if (not $smtp_tls_CAfile_seen) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0533", variables => { line => $smtp_tls_CAfile_line }}); + $reload = 1; + $new_postfix_main .= $smtp_tls_CAfile_line."\n"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:smtp_tls_CAfile_line' => $smtp_tls_CAfile_line, + 's2:reload' => $reload, + }}); + } + + # Write out the file, if needed. + if ($old_postfix_main ne $new_postfix_main) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0517", variables => { + file => $anvil->data->{path}{configs}{postfix_main}, + diff => diff \$old_postfix_main, \$new_postfix_main, { STYLE => 'Unified' }, + }}); + # Create the new relay file. + $reload = 1; + my $error = $anvil->Storage->write_file({ + debug => $debug, + backup => 1, + body => $new_postfix_main, + file => $anvil->data->{path}{configs}{postfix_main}, + mode => "0644", + user => "root", + group => "root", + overwrite => 1, + secure => 1, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + reload => $reload, + error => $error, + }}); + } + + # Make sure the postfix daemon is running and enabled. + my $postfix_started = 0; + + # Is the postfix daemon running? + my $postfix_running = $anvil->System->check_daemon({daemon => "postfix.service"}); + if (not $postfix_running) + { + # Start it. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0535", variables => { daemon => "postfix.service" }}); + my $start_return_code = $anvil->System->start_daemon({daemon => "postfix.service"}); + my $enable_return_code = $anvil->System->enable_daemon({daemon => "postfix.service"}); + $postfix_started = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + start_return_code => $start_return_code, + enable_return_code => $enable_return_code, + postfix_started => $postfix_started, + }}); + } + + if ($reload) + { + # Record that we've switched to this mail server. + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "mail_server::last_used::${mail_server_uuid}", + variable_value => time, + variable_source_table => "hosts", + variable_source_uuid => $anvil->Get->host_uuid, + variable_section => "email::servers", + variable_description => "striker_0276", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }}); + + # Start the daemon + if (not $postfix_started) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0091", variables => { daemon => "postfix.service" }}); + my $restart_return_code = $anvil->System->restart_daemon({daemon => "postfix.service"}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { restart_return_code => $restart_return_code }}); + } + } + + # Lastly, make sure the alert email directory exists. + if (not -d $anvil->data->{path}{directories}{alert_emails}) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0536"}); + my $failed = $anvil->Storage->make_directory({ + debug => $debug, + directory => $anvil->data->{path}{directories}{alert_emails}, + mode => "0775", + user => "root", + group => "root", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { failed => $failed }}); + } + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { reload => $reload }}); + return($reload); +} diff --git a/Anvil/Tools/Server.pm b/Anvil/Tools/Server.pm index 82b9e1e5..0f4c3738 100755 --- a/Anvil/Tools/Server.pm +++ b/Anvil/Tools/Server.pm @@ -636,9 +636,6 @@ sub migrate return($success); } - ### TODO: Left off here, this is not allowing two primaries. I think the problem is 'source' is being - ### mixed up in hashed between 'local' and the local machine's short host name. Switch - ### everything away from 'local' to the short host name throughout the program. if (not $anvil->data->{server}{$source}{$server}) { # The 'target' below is where I'm reading the server's definition from, which is the diff --git a/cgi-bin/striker b/cgi-bin/striker index 13b47cf3..ad837e27 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -755,7 +755,7 @@ WHERE }); # Show the menu. - $anvil->data->{form}{back_link} = "?"; + $anvil->data->{form}{back_link} = "?email=true"; $anvil->data->{form}{refresh_link} = "?email=true&task=email_recipient"; $anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "recipient-menu", variables => { recipients => $recipients_form, @@ -913,11 +913,11 @@ WHERE } elsif (not $port) { - # Port wasn't passed. Use '143' unless $connection_security is 'ssl_tls' + # Port wasn't passed. Use '587' unless $connection_security is 'ssl_tls' $port = 143; if ($connection_security eq "ssl_tls") { - $port = 993; + $port = 465; } $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { port => $port }}); } @@ -1144,7 +1144,7 @@ WHERE }); # Show the menu. - $anvil->data->{form}{back_link} = "?"; + $anvil->data->{form}{back_link} = "?email=true"; $anvil->data->{form}{refresh_link} = "?email=true&task=email_server"; $anvil->data->{form}{body} = $anvil->Template->get({file => "email.html", name => "mail-server-menu", variables => { mail_servers => $mail_servers_form, diff --git a/html/skins/alteeve/email.html b/html/skins/alteeve/email.html index 7c5cdfe1..65c4cbd0 100644 --- a/html/skins/alteeve/email.html +++ b/html/skins/alteeve/email.html @@ -54,7 +54,7 @@ - #!variable!name!# + #!variable!name!#   #!string!striker_0068!#   @@ -477,7 +477,7 @@ - #!variable!name!# + #!variable!name!#   #!string!striker_0068!#   diff --git a/notes b/notes index 639bf244..9b9664cb 100644 --- a/notes +++ b/notes @@ -287,15 +287,9 @@ pcs property set stonith-max-attempts=INFINITY pcs property set stonith-enabled=true -### No longer used. -pcs resource create hypervisor systemd:libvirtd op monitor interval=60 -pcs resource clone hypervisor clone-max=2 notify="false" -pcs resource create drbd systemd:drbd op monitor interval=60 -pcs resource clone drbd clone-max=2 notify="false" - # Create a new server resource, stopped, create the location constraint (higher == preferred), then start. -pcs resource create srv07-el6 ocf:alteeve:server name="srv07-el6" meta allow-migrate="true" migrate_to="INFINITY" target-role="stopped" start= stop="INFINITY" op monitor interval="60" on-fail="block" +pcs resource create srv07-el6 ocf:alteeve:server name="srv07-el6" meta allow-migrate="true" target-role="stopped" op monitor interval="60" on-fail="block" stop timeout="INFINITY" migrate_to timeout="INFINITY" pcs constraint location srv07-el6 prefers mk-a02n01=200 mk-a02n02=100 pcs resource enable srv07-el6 - or - @@ -411,12 +405,6 @@ Set to 90% of BCN bandwidth # Provision servers mkdir /mnt/anvil/{provision,files,archive,definitions} -pcs resource create srv01-c7 ocf:alteeve:server hypervisor="qemu:///system" config="/mnt/anvil/definitions/srv01-c7.xml" meta allow-migrate="true" op monitor interval="10" op stop timeout="60" on-fail="block" meta allow-migrate="true" failure-timeout="75" -pcs resource create srv01-c7 ocf:alteeve:server hypervisor="qemu:///system" config="/mnt/anvil/definitions/srv01-c7.xml" meta allow-migrate="true" op monitor interval="10" op on-fail="block" meta allow-migrate="true" failure-timeout="75" -pcs resource create srv01-c7 ocf:alteeve:server name="srv01-c7" meta allow-migrate="true" op monitor interval="10" op stop on-fail="block" meta allow-migrate="true" failure-timeout="75" - -pcs resource create srv01-c7 ocf:alteeve:server name="srv01-c7" meta allow-migrate="true" op monitor interval="60" op stop on-fail="block" op migrate_to on-fail="block" op migrate_from on-fail="block" meta allow-migrate="true" failure-timeout="75" - == Resource Agent; https://github.com/ClusterLabs/resource-agents/blob/master/doc/dev-guides/ra-dev-guide.asc @@ -458,11 +446,6 @@ reset location to prefer current host -> unmanage resource -> cleanup resource - (running on node 2, so re-add location constraint - basically, make sure location constraint favours current host) -pcs resource unmanage srv01-c7 -pcs constraint remove location-srv01-c7-m3-a02n02.alteeve.com-50 -crm_resource --reprobe -pcs resource manage srv01-c7 - https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#chapter-1-introduction @@ -916,10 +899,6 @@ virt-install --connect qemu:///system \ # Migration; -pcs resource move srv07-el6 mk-a02n02 -# (then remove the constraint); -pcs constraint show --full -pcs constraint remove cli-ban-srv07-el6-on-mk-a02n01 pcs constraint remove $(pcs constraint show --full | grep ban-srv07-el6 | perl -pe 's/^.*?id:(.*?)\)/$1/') diff --git a/share/words.xml b/share/words.xml index 5b58e9c4..c61ef407 100644 --- a/share/words.xml +++ b/share/words.xml @@ -209,6 +209,7 @@ The error was: #!variable!error!# =========================================================== + There appears to be no mail server in the database with the UUID: [#!variable!uuid!#]. Current Network Interfaces and States @@ -1007,6 +1008,13 @@ The file: [#!variable!file!#] needs to be updated. The difference is: The server is running (state is: [#!variable!state!#]). We've been asked to migrating the server: [#!variable!server!#] to: [#!variable!target_host!#]. Checking server state after: [#!variable!server!#] was migrated to this host. + Updating the postfix relay password file: [#!data!path::configs::postfix_relay_password!#]. + Generating the binary hash of the postfix relay password file: [#!data!path::configs::postfix_relay_password!#]. + It looks like the initial configuration of the postfix main configuration file, injecting the relay password file. + Injecting the configuration line: [#!variable!line!#]. + Updating the configuration line from: [#!variable!old_line!#] to: [#!variable!new_line!#]. + Starting and enabling the daemon: [#!variable!daemon!#]. + Creating the Anvil! alert email spool directory: [#!data!path::directories::alert_emails!#]. The host name: [#!variable!target!#] does not resolve to an IP address. @@ -1580,6 +1588,7 @@ If you are comfortable that the target has changed for a known reason, you can s Adding a disaster recovery (DR) host is optional. You can add one later if you don't have one now. If there are no servers on either node (as it a new #!string!brand_0006!# build), the OSes will be updated. Otherwise, they won't be updated. If the kernel is updated, or the network reconfigured, the node will be rebooted. Free-form description of this system. + This tracks the last time a given mail server was configured for use. It allows for a round-robin switching of mail servers when one mail server stops working and two or more mail servers have been configured. #!variable!number!#/sec diff --git a/tools/scancore b/tools/scancore index 01e3ca1a..b0c33b18 100755 --- a/tools/scancore +++ b/tools/scancore @@ -46,6 +46,9 @@ wait_for_database($anvil); wait_until_configured($anvil); # Send a startup +$anvil->Mail->check_config; +$anvil->Alert->register +exit; # Disconnect. We'll reconnect inside the loop $anvil->Database->disconnect(); @@ -234,37 +237,8 @@ sub prepare_for_run $anvil->Database->connect(); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0132"}); - # TODO: Check/configure the mail server. - check_email($anvil); - - return(0); -} - -sub check_email -{ - my ($anvil) = @_; - - # We check to see if there are any emails in the queue. If we see queued emails for more than five - # minutes, and a second mail server is configured, we'll automatically reconfigure for the next - # known server. - - # Before we do anything, we want to make sure all recipients have been registered against all hosts. - $anvil->Email->check_alert_recipients(); - - ### TODO: - # If not configured look in variables for 'mail_server::last_used::'. The first one - # that doesn't have an existing variable will be used. If all known mail servers have variables, the - # oldest is used. - # - # If configured/running, the number of messages in queue is checked. If '0', - # 'mail_server::queue_empty' is updated with the current time. If 1 or more, the time since the queue - # was last 0 is checked. If > 300, the mail server is reconfigured to use the mail server with the - # oldest 'mail_server::last_used::' time. - # - # In any case where the mail server is configured, the server that is used has their - # 'mail_server::last_used::' variable set to the current time stamp. - - # Is the postfix daemon running? + # See if the mail server needs to be updated. + $anvil->Email->check_config; return(0); } diff --git a/tools/test.pl b/tools/test.pl index dd5a2496..9d055015 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -29,7 +29,5 @@ $anvil->Database->connect(); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0132"}); $anvil->Get->switches; -my $cib = ''; - -$anvil->Cluster->parse_cib({cib => $cib, debug => 2}); +$anvil->Email->check_config({debug => 3});