* Renamed the 'notifications' table to 'alert-override', better reflecting what it does.

* Got anvil-manage-alerts managing alert overrides.
* Created, but for now commented out, the new 'audit' table.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 2 years ago
parent 753ea7518f
commit 622fb84652
  1. 589
      Anvil/Tools/Database.pm
  2. 25
      man/anvil-manage-alerts.8
  3. 2
      notes
  4. 111
      share/anvil.sql
  5. 40
      share/words.xml
  6. 145
      tools/anvil-daemon
  7. 517
      tools/anvil-manage-alerts

@ -25,6 +25,7 @@ my $THIS_FILE = "Database.pm";
# connect # connect
# disconnect # disconnect
# find_host_uuid_columns # find_host_uuid_columns
# get_alert_overrides
# get_alerts # get_alerts
# get_anvils # get_anvils
# get_bridges # get_bridges
@ -40,7 +41,6 @@ my $THIS_FILE = "Database.pm";
# get_local_uuid # get_local_uuid
# get_mail_servers # get_mail_servers
# get_manifests # get_manifests
# get_notifications
# get_recipients # get_recipients
# get_servers # get_servers
# get_storage_group_data # get_storage_group_data
@ -49,6 +49,7 @@ my $THIS_FILE = "Database.pm";
# get_power # get_power
# get_upses # get_upses
# initialize # initialize
# insert_or_update_alert_overrides
# insert_or_update_anvils # insert_or_update_anvils
# insert_or_update_bridges # insert_or_update_bridges
# insert_or_update_bonds # insert_or_update_bonds
@ -62,7 +63,6 @@ my $THIS_FILE = "Database.pm";
# insert_or_update_mail_servers # insert_or_update_mail_servers
# insert_or_update_manifests # insert_or_update_manifests
# insert_or_update_network_interfaces # insert_or_update_network_interfaces
# insert_or_update_notifications
# insert_or_update_mac_to_ip # insert_or_update_mac_to_ip
# insert_or_update_oui # insert_or_update_oui
# insert_or_update_power # insert_or_update_power
@ -2519,6 +2519,80 @@ WHERE
} }
=head2 get_alert_overrides
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, or by Anvil! node / dr host set.
Parameters;
=head3 include_deleted (Optional, default 0)
If set to C<< 1 >>, deleted overrides are included when loading the data. When C<< 0 >> is set, the default, any manifest last_ran with C<< manifest_note >> set to C<< DELETED >> is ignored.
=cut
sub get_alert_overrides
{
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 => "Database->get_alert_overrides()" }});
my $include_deleted = defined $parameter->{include_deleted} ? $parameter->{include_deleted} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
include_deleted => $include_deleted,
}});
my $query = "
SELECT
alert_override_uuid,
alert_override_recipient_uuid,
alert_override_host_uuid,
alert_override_alert_level
FROM
alert_overrides
;";
$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 => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $alert_override_uuid = $row->[0];
my $alert_override_recipient_uuid = $row->[1];
my $alert_override_host_uuid = $row->[2];
my $alert_override_alert_level = $row->[3];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
alert_override_uuid => $alert_override_uuid,
alert_override_recipient_uuid => $alert_override_recipient_uuid,
alert_override_host_uuid => $alert_override_host_uuid,
alert_override_alert_level => $alert_override_alert_level,
}});
if (($alert_override_alert_level == -1) && (not $include_deleted))
{
next;
}
# Store the data
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid} = $alert_override_recipient_uuid;
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid} = $alert_override_host_uuid;
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level} = $alert_override_alert_level;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"alert_overrides::alert_override_uuid::${alert_override_uuid}::alert_override_recipient_uuid" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid},
"alert_overrides::alert_override_uuid::${alert_override_uuid}::alert_override_host_uuid" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid},
"alert_overrides::alert_override_uuid::${alert_override_uuid}::alert_override_alert_level" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level},
}});
}
return(0);
}
=head2 get_anvils =head2 get_anvils
This loads information about all known Anvil! systems as recorded in the C<< anvils >> table. This loads information about all known Anvil! systems as recorded in the C<< anvils >> table.
@ -4484,66 +4558,6 @@ 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
sub get_notifications
{
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 => "Database->get_notifications()" }});
my $query = "
SELECT
notification_uuid,
notification_recipient_uuid,
notification_host_uuid,
notification_alert_level
FROM
notifications
;";
$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 => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $notification_uuid = $row->[0];
my $notification_recipient_uuid = $row->[1];
my $notification_host_uuid = $row->[2];
my $notification_alert_level = $row->[3];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
notification_uuid => $notification_uuid,
notification_recipient_uuid => $notification_recipient_uuid,
notification_host_uuid => $notification_host_uuid,
notification_alert_level => $notification_alert_level,
}});
# Store the data
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_recipient_uuid} = $notification_recipient_uuid;
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid} = $notification_host_uuid;
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_alert_level} = $notification_alert_level;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"notifications::notification_uuid::${notification_uuid}::notification_recipient_uuid" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_recipient_uuid},
"notifications::notification_uuid::${notification_uuid}::notification_host_uuid" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid},
"notifications::notification_uuid::${notification_uuid}::notification_alert_level" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_alert_level},
}});
}
return(0);
}
=head2 get_recipients =head2 get_recipients
This returns a list of users listening to alerts for a given host, along with their alert level. This returns a list of users listening to alerts for a given host, along with their alert level.
@ -4569,10 +4583,10 @@ sub get_recipients
}}); }});
# We're going to include the alert levels for this host based on overrides that might exist in the # We're going to include the alert levels for this host based on overrides that might exist in the
# 'notifications' table. If the data hasn't already been loaded, we'll load it now. # 'alert_overrides' table. If the data hasn't already been loaded, we'll load it now.
if (not $anvil->data->{notifications}{notification_uuid}) if (not $anvil->data->{alert_overrides}{alert_override_uuid})
{ {
$anvil->Database->get_notifications({debug => $debug}); $anvil->Database->get_alert_overrides({debug => $debug});
} }
my $host_uuid = $anvil->Get->host_uuid(); my $host_uuid = $anvil->Get->host_uuid();
@ -4639,19 +4653,19 @@ WHERE
}}); }});
# If there is an override for a given recipient on this host, mark it as such. # If there is an override for a given recipient on this host, mark it as such.
foreach my $notification_uuid (keys %{$anvil->data->{notifications}{notification_uuid}}) foreach my $alert_override_uuid (keys %{$anvil->data->{alert_overrides}{alert_override_uuid}})
{ {
my $notification_recipient_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_recipient_uuid}; my $alert_override_recipient_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid};
my $notification_host_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid}; my $alert_override_host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid};
my $notification_alert_level = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_alert_level}; my $alert_override_alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
notification_recipient_uuid => $notification_recipient_uuid, alert_override_recipient_uuid => $alert_override_recipient_uuid,
notification_host_uuid => $notification_host_uuid, alert_override_host_uuid => $alert_override_host_uuid,
notification_alert_level => $notification_alert_level, alert_override_alert_level => $alert_override_alert_level,
}}); }});
if (($notification_host_uuid eq $host_uuid) && ($notification_recipient_uuid eq $recipient_uuid)) if (($alert_override_host_uuid eq $host_uuid) && ($alert_override_recipient_uuid eq $recipient_uuid))
{ {
$anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{level_on_host} = $notification_alert_level; $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{level_on_host} = $alert_override_alert_level;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"recipients::recipient_uuid::${recipient_uuid}::level_on_host" => $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{level_on_host}, "recipients::recipient_uuid::${recipient_uuid}::level_on_host" => $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid}{level_on_host},
}}); }});
@ -5867,6 +5881,231 @@ sub initialize
}; };
=head2 insert_or_update_alert_overrides
This updates (or inserts) a record in the C<< alert_overrides >> table used for configuring what recipients get what alerts for a given host.
If there is an error, an empty string is returned.
B<< NOTE >>: The information is this table IS NOT AUTHORITATIVE! It's generally updated daily, so the information here could be stale.
Parameters;
=head3 delete (optional, default '0')
If set to C<< 1 >>, the associated alert_override override will be deleted. Specifically, the C<< alert_override_alert_level >> is set to C<< -1 >>.
When this is set, either C<< recipient_uuid >> or C<< recipient_email >> is required.
=head3 alert_override_uuid (optional)
If set, this is the specific entry that will be updated.
=head3 alert_override_recipient_uuid (required)
This is the C<< recipients >> -> C<< recipient_uuid >> of the alert recipient.
=head3 alert_override_host_uuid (required)
This is the C<< hosts >> -> C<< host_uuid >> of the machine generating alerts.
=head3 alert_override_alert_level (required)
This is the alert level that the recipient is interested in. Any alert of equal or higher level will be sent to the associated recipient.
Valid values;
=head4 0 (ignore)
No alerts from the associated system will be sent to this recipient.
=head4 1 (critical)
Critical alerts. These are alerts that almost certainly indicate an issue with the system that has are likely will cause a service interruption. (ie: node was fenced, emergency shut down, etc)
=head4 2 (warning)
Warning alerts. These are alerts that likely require the attention of an administrator, but have not caused a service interruption. (ie: power loss/load shed, over/under voltage, fan failure, network link failure, etc)
=head4 3 (notice)
Notice alerts. These are generally low priority alerts that do not need attention, but might be indicators of developing problems. (ie: UPSes transfering to batteries, server migration/shut down/boot up, etc)
=head4 4 (info)
Info alerts. These are generally for debugging, and will generating a staggering number of alerts. Not recommended for most cases.
=cut
sub insert_or_update_alert_overrides
{
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 => "Database->insert_or_update_alert_overrides()" }});
my $delete = defined $parameter->{'delete'} ? $parameter->{'delete'} : 0;
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $alert_override_uuid = defined $parameter->{alert_override_uuid} ? $parameter->{alert_override_uuid} : "";
my $alert_override_recipient_uuid = defined $parameter->{alert_override_recipient_uuid} ? $parameter->{alert_override_recipient_uuid} : "";
my $alert_override_host_uuid = defined $parameter->{alert_override_host_uuid} ? $parameter->{alert_override_host_uuid} : "";
my $alert_override_alert_level = defined $parameter->{alert_override_alert_level} ? $parameter->{alert_override_alert_level} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
'delete' => $delete,
alert_override_uuid => $alert_override_uuid,
alert_override_recipient_uuid => $alert_override_recipient_uuid,
alert_override_host_uuid => $alert_override_host_uuid,
alert_override_alert_level => $alert_override_alert_level,
}});
if (not $delete)
{
if (not $alert_override_recipient_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_alert_overrides()", parameter => "alert_override_recipient_uuid" }});
return("");
}
if (not $alert_override_host_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_alert_overrides()", parameter => "alert_override_host_uuid" }});
return("");
}
if ($alert_override_alert_level eq "")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_alert_overrides()", parameter => "alert_override_alert_level" }});
return("");
}
elsif (($alert_override_alert_level =~ /\D/) or ($alert_override_alert_level < 0) or ($alert_override_alert_level > 4))
{
# Not an integer
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0109", variables => { alert_override_alert_level => $alert_override_alert_level }});
return("");
}
}
# If we're deleting, we need a alert_override_uuid
if (($parameter->{'delete'}) && (not $alert_override_uuid))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0389"});
return("");
}
# If deleting, set the alert_override level to '-1'
if ($parameter->{'delete'})
{
$alert_override_alert_level = -1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { alert_override_alert_level => $alert_override_alert_level }});
}
# If we don't have the alert_override_uuid, see if we can look it up.
if (not $alert_override_uuid)
{
my $query = "
SELECT
alert_override_uuid
FROM
alert_overrides
WHERE
alert_override_recipient_uuid = ".$anvil->Database->quote($alert_override_recipient_uuid)."
AND
alert_override_host_uuid = ".$anvil->Database->quote($alert_override_host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$alert_override_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { alert_override_uuid => $alert_override_uuid }});
}
}
# Do we have an existing entry?
if ($alert_override_uuid)
{
# Yes, look up the previous alert_override_alert_level.
my $query = "
SELECT
alert_override_alert_level
FROM
alert_overrides
WHERE
alert_override_uuid = ".$anvil->Database->quote($alert_override_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
# If this doesn't return anything, the passed in UUID was invalid.
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if (not $count)
{
# Error out.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0110", variables => { alert_override_uuid => $alert_override_uuid }});
return("");
}
my $old_alert_override_alert_level = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_alert_override_alert_level => $old_alert_override_alert_level }});
# Did the level change?
if ($alert_override_alert_level ne $old_alert_override_alert_level)
{
# UPDATE
my $query = "
UPDATE
alert_overrides
SET
alert_override_alert_level = ".$anvil->Database->quote($alert_override_alert_level).",
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
alert_override_uuid = ".$anvil->Database->quote($alert_override_uuid)."
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
}
else
{
# Nope, INSERT
$alert_override_uuid = $anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { alert_override_uuid => $alert_override_uuid }});
my $query = "
INSERT INTO
alert_overrides
(
alert_override_uuid,
alert_override_recipient_uuid,
alert_override_host_uuid,
alert_override_alert_level,
modified_date
) VALUES (
".$anvil->Database->quote($alert_override_uuid).",
".$anvil->Database->quote($alert_override_recipient_uuid).",
".$anvil->Database->quote($alert_override_host_uuid).",
".$anvil->Database->quote($alert_override_alert_level).",
".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
);
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
return($alert_override_uuid)
}
=head2 insert_or_update_anvils =head2 insert_or_update_anvils
This updates (or inserts) a record in the C<< anvils >> table. The C<< anvil_uuid >> referencing the database row will be returned. This updates (or inserts) a record in the C<< anvils >> table. The C<< anvil_uuid >> referencing the database row will be returned.
@ -10100,202 +10339,6 @@ INSERT INTO
} }
=head2 insert_or_update_notifications
This updates (or inserts) a record in the C<< notifications >> table used for configuring what recipients get what alerts for a given host.
If there is an error, an empty string is returned.
B<< NOTE >>: The information is this table IS NOT AUTHORITATIVE! It's generally updated daily, so the information here could be stale.
Parameters;
=head3 notification_uuid (optional)
If set, this is the specific entry that will be updated.
=head3 notification_recipient_uuid (required)
This is the C<< recipients >> -> C<< recipient_uuid >> of the alert recipient.
=head3 notification_host_uuid (required)
This is the C<< hosts >> -> C<< host_uuid >> of the machine generating alerts.
=head3 notification_alert_level (required)
This is the alert level that the recipient is interested in. Any alert of equal or higher level will be sent to the associated recipient.
Valid values;
=head4 0 (ignore)
No alerts from the associated system will be sent to this recipient.
=head4 1 (critical)
Critical alerts. These are alerts that almost certainly indicate an issue with the system that has are likely will cause a service interruption. (ie: node was fenced, emergency shut down, etc)
=head4 2 (warning)
Warning alerts. These are alerts that likely require the attention of an administrator, but have not caused a service interruption. (ie: power loss/load shed, over/under voltage, fan failure, network link failure, etc)
=head4 3 (notice)
Notice alerts. These are generally low priority alerts that do not need attention, but might be indicators of developing problems. (ie: UPSes transfering to batteries, server migration/shut down/boot up, etc)
=cut
sub insert_or_update_notifications
{
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 => "Database->insert_or_update_notifications()" }});
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $notification_uuid = defined $parameter->{notification_uuid} ? $parameter->{notification_uuid} : "";
my $notification_recipient_uuid = defined $parameter->{notification_recipient_uuid} ? $parameter->{notification_recipient_uuid} : "";
my $notification_host_uuid = defined $parameter->{notification_host_uuid} ? $parameter->{notification_host_uuid} : "";
my $notification_alert_level = defined $parameter->{notification_alert_level} ? $parameter->{notification_alert_level} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
notification_uuid => $notification_uuid,
notification_recipient_uuid => $notification_recipient_uuid,
notification_host_uuid => $notification_host_uuid,
notification_alert_level => $notification_alert_level,
}});
if (not $notification_recipient_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_notifications()", parameter => "notification_recipient_uuid" }});
return("");
}
if (not $notification_host_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_notifications()", parameter => "notification_host_uuid" }});
return("");
}
if ($notification_alert_level eq "")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_notifications()", parameter => "notification_alert_level" }});
return("");
}
elsif (($notification_alert_level =~ /\D/) or ($notification_alert_level < 0) or ($notification_alert_level > 3))
{
# Not an integer
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0109", variables => { notification_alert_level => $notification_alert_level }});
return("");
}
# If we don't have the notification_uuid, see if we can look it up.
if (not $notification_uuid)
{
my $query = "
SELECT
notification_uuid
FROM
notifications
WHERE
notification_recipient_uuid = ".$anvil->Database->quote($notification_recipient_uuid)."
AND
notification_host_uuid = ".$anvil->Database->quote($notification_host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
$notification_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { notification_uuid => $notification_uuid }});
}
}
# Do we have an existing entry?
if ($notification_uuid)
{
# Yes, look up the previous notification_alert_level.
my $query = "
SELECT
notification_alert_level
FROM
notifications
WHERE
notification_uuid = ".$anvil->Database->quote($notification_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
# If this doesn't return anything, the passed in UUID was invalid.
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if (not $count)
{
# Error out.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0110", variables => { notification_uuid => $notification_uuid }});
return("");
}
my $old_notification_alert_level = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_notification_alert_level => $old_notification_alert_level }});
# Did the level change?
if ($notification_alert_level ne $old_notification_alert_level)
{
# UPDATE
my $query = "
UPDATE
notifications
SET
notification_alert_level = ".$anvil->Database->quote($notification_alert_level).",
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
notification_uuid = ".$anvil->Database->quote($notification_uuid)."
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
}
else
{
# Nope, INSERT
$notification_uuid = $anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { notification_uuid => $notification_uuid }});
my $query = "
INSERT INTO
notifications
(
notification_uuid,
notification_recipient_uuid,
notification_host_uuid,
notification_alert_level,
modified_date
) VALUES (
".$anvil->Database->quote($notification_uuid).",
".$anvil->Database->quote($notification_recipient_uuid).",
".$anvil->Database->quote($notification_host_uuid).",
".$anvil->Database->quote($notification_alert_level).",
".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
);
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
return($notification_uuid)
}
=head2 insert_or_update_mac_to_ip =head2 insert_or_update_mac_to_ip
This updates (or inserts) a record in the C<< mac_to_ip >> table used for tracking what MAC addresses have what IP addresses. This updates (or inserts) a record in the C<< mac_to_ip >> table used for tracking what MAC addresses have what IP addresses.
@ -10964,6 +11007,10 @@ Warning alerts. These are alerts that likely require the attention of an adminis
Notice alerts. These are generally low priority alerts that do not need attention, but might be indicators of developing problems. (ie: UPSes transfering to batteries, server migration/shut down/boot up, etc) Notice alerts. These are generally low priority alerts that do not need attention, but might be indicators of developing problems. (ie: UPSes transfering to batteries, server migration/shut down/boot up, etc)
=head4 4 (info)
Info alerts. These are generally for debugging, and will generating a staggering number of alerts. Not recommended for most cases.
=head3 recipient_uuid (optional) =head3 recipient_uuid (optional)
If set, this is the UUID that will be used to update a record in the database. If not set, it will be searched for by looking for a matching C<< recipient_email >>. If set, this is the UUID that will be used to update a record in the database. If not set, it will be searched for by looking for a matching C<< recipient_email >>.
@ -11006,7 +11053,7 @@ sub insert_or_update_recipients
} }
# Make sure the recipient_level is 0, 1, 2 or 3 # Make sure the recipient_level is 0, 1, 2 or 3
if (($recipient_level ne "0") && ($recipient_level ne "1") && ($recipient_level ne "2") && ($recipient_level ne "3")) if (($recipient_level =~ /\D/) or ($recipient_level < 0) or ($recipient_level > 4))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0108", variables => { recipient_level => $recipient_level }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0108", variables => { recipient_level => $recipient_level }});
return(""); return("");

@ -2,15 +2,15 @@
.\" Contact mkelly@alteeve.com to report issues, concerns or suggestions. .\" Contact mkelly@alteeve.com to report issues, concerns or suggestions.
.TH anvil-manage-alerts "8" "October 26 2022" "Anvil! Intelligent Availability™ Platform" .TH anvil-manage-alerts "8" "October 26 2022" "Anvil! Intelligent Availability™ Platform"
.SH NAME .SH NAME
anvil-manage-alerts \- This program manages alerts; Email servers, recipients, notification overrides, and generating test alerts. anvil-manage-alerts \- This program manages alerts; Email servers, recipients, alert-override overrides, and generating test alerts.
.SH SYNOPSIS .SH SYNOPSIS
.B anvil-manage-alerts .B anvil-manage-alerts
\fI\,<command> \/\fR \fI\,<command> \/\fR
.SH DESCRIPTION .SH DESCRIPTION
The program allows you to add, edit and delete email servers, alert recipients, and notification overrides. You can also use it to generate a test alert. The program allows you to add, edit and delete email servers, alert recipients, and alert-override overrides. You can also use it to generate a test alert.
If run without any switches, the list of mail servers and recipients are returned. If run without any switches, the list of mail servers and recipients are returned.
When called without any switches, the list of currect mail servers, alert recipients and notification overrides are shown, along with all known hosts. When called without any switches, the list of currect mail servers, alert recipients and alert-override overrides are shown, along with all known hosts.
.TP .TP
.SH OPTIONS .SH OPTIONS
.TP .TP
@ -76,19 +76,19 @@ Example: example.com
See: https://www.ibm.com/docs/en/zos/2.2.0?topic=sc-helo-command-identify-domain-name-sending-host-smtp See: https://www.ibm.com/docs/en/zos/2.2.0?topic=sc-helo-command-identify-domain-name-sending-host-smtp
.TP .TP
\fB\-\-notifications\fR \fB\-\-alert-overrides\fR
This is where an alert recipient can have notification overrides. Typically this is used so that a given user can ignore alerts from a specific Anvil! node pair. This is where an alert recipient can have alert-override overrides. Typically this is used so that a given user can ignore alerts from a specific Anvil! node pair.
.TP .TP
\fB\-\-notification-uuid\fR <uuid> \fB\-\-alert-override-uuid\fR <uuid>
This is required for \fB\-\-edit\fR and \fB\-\-delete\fR. It is the existing notification override being worked on. This is required for \fB\-\-edit\fR and \fB\-\-delete\fR. It is the existing alert-override override being worked on.
.TP .TP
\fB\-\-notification-recipient-uuid\fR <uuid> \fB\-\-alert-override-recipient-uuid\fR <uuid>
This is the recipients -> recipient_uuid who we are creating the override for. This is the recipients -> recipient_uuid who we are creating the override for.
.TP .TP
\fB\-\-notification-host-uuid\fR \fB\-\-alert-override-host-uuid\fR
This is the hosts -> host_uuid of the machine that you are creating the alert This is the hosts -> host_uuid of the machine that you are creating the alert
.TP .TP
\fB\-\-notification-alert-level\fR <1, 2, 3 or 4> \fB\-\-alert-override-alert-level\fR <1, 2, 3 or 4>
This is the desired override alert level. This is the desired override alert level.
Valid values are: Valid values are:
@ -121,7 +121,7 @@ Example: notaspy@example.com
In the future, languages will be added and this can be used to indicate what language the user will receive their alerts in. At the time of writing this man page, only 'en_CA' is supported. In the future, languages will be added and this can be used to indicate what language the user will receive their alerts in. At the time of writing this man page, only 'en_CA' is supported.
.TP .TP
\fB\-\-recipient-level\fR <1, 2, 3 or 4> \fB\-\-recipient-level\fR <1, 2, 3 or 4>
This is the default alert level this recipient is interested in. It can be adjusted on a per-host basis via the 'notifications' over-rides. This is the default alert level this recipient is interested in. It can be adjusted on a per-host basis via the 'alert-overrides' over-rides.
Valid values are: Valid values are:
@ -137,6 +137,3 @@ Valid values are:
Written by Madison Kelly, Alteeve staff and the Anvil! project contributors. Written by Madison Kelly, Alteeve staff and the Anvil! project contributors.
.SH "REPORTING BUGS" .SH "REPORTING BUGS"
Report bugs to users@clusterlabs.org Report bugs to users@clusterlabs.org
", "download", "everywhere", "file", "is-script", "job-uuid", "rename", "to

@ -6,8 +6,6 @@ dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release
dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-node --allowerasing dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-node --allowerasing
dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-dr --allowerasing dnf -y update && dnf -y install https://www.alteeve.com/an-repo/m3/anvil-release-latest.noarch.rpm && alteeve-repo-setup -y && dnf -y install anvil-dr --allowerasing
### Get OUI out of the fucking database.
### Currently set default zone; ### Currently set default zone;

@ -484,7 +484,7 @@ CREATE TABLE recipients (
recipient_name text not null, -- This is the recipient's name recipient_name text not null, -- This is the recipient's name
recipient_email text not null, -- This is the recipient's email address or the file name, depending. recipient_email text not null, -- This is the recipient's email address or the file name, depending.
recipient_language text not null, -- If set, this is the language the user wants to receive alerts in. If not set, the default language is used. recipient_language text not null, -- If set, this is the language the user wants to receive alerts in. If not set, the default language is used.
recipient_level integer not null, -- This is the default alert level this recipient is interested in. It can be adjusted on a per-host basis via the 'notifications' table. recipient_level integer not null, -- This is the default alert level this recipient is interested in. It can be adjusted on a per-host basis via the 'alert_overrides' table.
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE recipients OWNER TO admin; ALTER TABLE recipients OWNER TO admin;
@ -533,55 +533,55 @@ CREATE TRIGGER trigger_recipients
-- This table is used when a user wants to set a custom alert level for a given machine. Typically this is -- This table is used when a user wants to set a custom alert level for a given machine. Typically this is
-- used to ignore test Anvil! systems. -- used to ignore test Anvil! systems.
CREATE TABLE notifications ( CREATE TABLE alert_overrides (
notification_uuid uuid not null primary key, alert_override_uuid uuid not null primary key,
notification_recipient_uuid uuid not null, -- The recipient we're linking. alert_override_recipient_uuid uuid not null, -- The recipient we're linking.
notification_host_uuid uuid not null, -- This host_uuid of the referenced machine alert_override_host_uuid uuid not null, -- This host_uuid of the referenced machine
notification_alert_level integer not null, -- This is the alert level (at or above) that this user wants alerts from. alert_override_alert_level integer not null, -- This is the alert level (at or above) that this user wants alerts from. If set to '-1', the record is deleted.
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
FOREIGN KEY(notification_host_uuid) REFERENCES anvils(anvil_uuid), FOREIGN KEY(alert_override_host_uuid) REFERENCES hosts(host_uuid),
FOREIGN KEY(notification_recipient_uuid) REFERENCES recipients(recipient_uuid) FOREIGN KEY(alert_override_recipient_uuid) REFERENCES recipients(recipient_uuid)
); );
ALTER TABLE notifications OWNER TO admin; ALTER TABLE alert_overrides OWNER TO admin;
CREATE TABLE history.notifications ( CREATE TABLE history.alert_overrides (
history_id bigserial, history_id bigserial,
notification_uuid uuid, alert_override_uuid uuid,
notification_recipient_uuid uuid, alert_override_recipient_uuid uuid,
notification_host_uuid uuid, alert_override_host_uuid uuid,
notification_alert_level integer, alert_override_alert_level integer,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.notifications OWNER TO admin; ALTER TABLE history.alert_overrides OWNER TO admin;
CREATE FUNCTION history_notifications() RETURNS trigger CREATE FUNCTION history_alert_overrides() RETURNS trigger
AS $$ AS $$
DECLARE DECLARE
history_notifications RECORD; history_alert_overrides RECORD;
BEGIN BEGIN
SELECT INTO history_notifications * FROM notifications WHERE notification_uuid = new.notification_uuid; SELECT INTO history_alert_overrides * FROM alert_overrides WHERE alert_override_uuid = new.alert_override_uuid;
INSERT INTO history.notifications INSERT INTO history.alert_overrides
(notification_uuid, (alert_override_uuid,
notification_recipient_uuid, alert_override_recipient_uuid,
notification_host_uuid, alert_override_host_uuid,
notification_alert_level, alert_override_alert_level,
modified_date) modified_date)
VALUES VALUES
(history_notifications.notification_uuid, (history_alert_overrides.alert_override_uuid,
history_notifications.notification_recipient_uuid, history_alert_overrides.alert_override_recipient_uuid,
history_notifications.notification_host_uuid, history_alert_overrides.alert_override_host_uuid,
history_notifications.notification_alert_level, history_alert_overrides.alert_override_alert_level,
history_notifications.modified_date); history_alert_overrides.modified_date);
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql;
ALTER FUNCTION history_notifications() OWNER TO admin; ALTER FUNCTION history_alert_overrides() OWNER TO admin;
CREATE TRIGGER trigger_notifications CREATE TRIGGER trigger_alert_overrides
AFTER INSERT OR UPDATE ON notifications AFTER INSERT OR UPDATE ON alert_overrides
FOR EACH ROW EXECUTE PROCEDURE history_notifications(); FOR EACH ROW EXECUTE PROCEDURE history_alert_overrides();
-- This creates a list of mail servers that are available for use by hosts. This information is used to -- This creates a list of mail servers that are available for use by hosts. This information is used to
@ -1922,6 +1922,53 @@ CREATE TRIGGER trigger_temperature
AFTER INSERT OR UPDATE ON temperature AFTER INSERT OR UPDATE ON temperature
FOR EACH ROW EXECUTE PROCEDURE history_temperature(); FOR EACH ROW EXECUTE PROCEDURE history_temperature();
-- -- Enable after Yan's review
-- This is used to audit major events by user.
--CREATE TABLE audits (
--audit_uuid uuid primary key,
--audit_user_uuid uuid not null, -- This is the users -> user_uuid the audit is tracking
--audit_details text not null, -- This is the information explaining the action being audited.
--modified_date timestamp with time zone not null,
--FOREIGN KEY(audit_user_uuid) REFERENCES users(user_uuid)
--);
--ALTER TABLE audits OWNER TO admin;
--CREATE TABLE history.audits (
--history_id bigserial,
--audit_uuid uuid,
--audit_user_uuid uuid,
--audit_details text,
--modified_date timestamp with time zone not null
--);
--ALTER TABLE history.audits OWNER TO admin;
--CREATE FUNCTION history_audits() RETURNS trigger
--AS $$
--DECLARE
--history_audits RECORD;
--BEGIN
--SELECT INTO history_audits * FROM audits WHERE audit_uuid = new.audit_uuid;
--INSERT INTO history.audits
--(audit_uuid,
--audit_user_uuid,
--audit_details,
--modified_date)
--VALUES
--(history_audit.audit_uuid,
--history_audit.audit_user_uuid,
--history_audit.audit_details,
--history_audit.modified_date);
--RETURN NULL;
--END;
--$$
--LANGUAGE plpgsql;
--ALTER FUNCTION history_audits() OWNER TO admin;
--CREATE TRIGGER trigger_audits
--AFTER INSERT OR UPDATE ON audits
--FOR EACH ROW EXECUTE PROCEDURE history_audits();
-- ------------------------------------------------------------------------------------------------------- -- -- ------------------------------------------------------------------------------------------------------- --
-- These are special tables with no history or tracking UUIDs that simply record transient information. -- -- These are special tables with no history or tracking UUIDs that simply record transient information. --

@ -165,8 +165,8 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp
<key name="error_0105">The file: [#!variable!file!#] was not found.</key> <key name="error_0105">The file: [#!variable!file!#] was not found.</key>
<key name="error_0106"><![CDATA[The method Network->find_matches() was given the hash key: [#!variable!key!#], but it does not reference a hash. Are any IPs associated with this target? The caller was: [#!variable!source!#:#!variable!line!#].]]></key> <key name="error_0106"><![CDATA[The method Network->find_matches() was given the hash key: [#!variable!key!#], but it does not reference a hash. Are any IPs associated with this target? The caller was: [#!variable!source!#:#!variable!line!#].]]></key>
<key name="error_0107">Failed to reconnect after reconfiguring the network. Will reboot in hopes of coming up cleanly.</key> <key name="error_0107">Failed to reconnect after reconfiguring the network. Will reboot in hopes of coming up cleanly.</key>
<key name="error_0108">The 'recipient_level': [#!variable!recipient_level!#] is invalid. It should be '0', '1', '2', or '3'.</key> <key name="error_0108">The 'recipient_level': [#!variable!recipient_level!#] is invalid. It should be '0', '1', '2', '3', or '4'.</key>
<key name="error_0109">The 'notification_alert_level': [#!variable!notification_alert_level!#] is invalid. It should be '0', '1', '2', or '3'.</key> <key name="error_0109">The 'notification_alert_level': [#!variable!notification_alert_level!#] is invalid. It should be '0', '1', '2', '3', or '4'.</key>
<key name="error_0110">The 'notification_uuid': [#!variable!notification_uuid!#] was not found in the database.</key> <key name="error_0110">The 'notification_uuid': [#!variable!notification_uuid!#] was not found in the database.</key>
<key name="error_0111"> <key name="error_0111">
[ Error ] - The was a problem parsing the unified metadata: [ Error ] - The was a problem parsing the unified metadata:
@ -553,6 +553,9 @@ The definition data passed in was:
<key name="error_0386">[ Error ] - The email address: [#!variable!email!#] appears to be invalid.</key> <key name="error_0386">[ Error ] - The email address: [#!variable!email!#] appears to be invalid.</key>
<key name="error_0387">[ Error ] - The switch: [--#!variable!switch!#] is required, but not provided.</key> <key name="error_0387">[ Error ] - The switch: [--#!variable!switch!#] is required, but not provided.</key>
<key name="error_0388">[ Error ] - The mail server UUID: [#!variable!uuid!#] was not found.</key> <key name="error_0388">[ Error ] - The mail server UUID: [#!variable!uuid!#] was not found.</key>
<key name="error_0389">[ Error ] - I was asked to delete a notification over-ride, but no 'notification_uuid' was provides.</key>
<key name="error_0390">[ Error ] - The alert recipient UUID: [#!variable!uuid!#] wasn't found in the database.</key>
<key name="error_0391">[ Error ] - The host UUID: [#!variable!uuid!#] wasn't found in the database.</key>
<!-- Files templates --> <!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable --> <!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -2704,8 +2707,7 @@ Available options;
* Authentication: [#!variable!new_authentication!#] * Authentication: [#!variable!new_authentication!#]
* Security: ..... [#!variable!new_security!#] * Security: ..... [#!variable!new_security!#]
* HELO domain: .. [#!variable!new_helo_domain!#] * HELO domain: .. [#!variable!new_helo_domain!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key>
<key name="message_0295">Are you sure you want to change the mail server thusly: <key name="message_0295">Are you sure you want to change the mail server thusly:
* Address: ...... [#!variable!old_address!#] -> [#!variable!new_address!#] * Address: ...... [#!variable!old_address!#] -> [#!variable!new_address!#]
* TCP port: ..... [#!variable!old_port!#] -> [#!variable!new_port!#] * TCP port: ..... [#!variable!old_port!#] -> [#!variable!new_port!#]
@ -2714,8 +2716,7 @@ Proceed? [y/N]
* Authentication: [#!variable!old_authentication!#] -> [#!variable!new_authentication!#] * Authentication: [#!variable!old_authentication!#] -> [#!variable!new_authentication!#]
* Security: ..... [#!variable!old_security!#] -> [#!variable!new_security!#] * Security: ..... [#!variable!old_security!#] -> [#!variable!new_security!#]
* HELO domain: .. [#!variable!old_helo_domain!#] -> [#!variable!new_helo_domain!#] * HELO domain: .. [#!variable!old_helo_domain!#] -> [#!variable!new_helo_domain!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key>
<key name="message_0296">Are you sure you want to delete the mail server: <key name="message_0296">Are you sure you want to delete the mail server:
* Address: ...... [#!variable!old_address!#] * Address: ...... [#!variable!old_address!#]
* TCP port: ..... [#!variable!old_port!#] * TCP port: ..... [#!variable!old_port!#]
@ -2724,8 +2725,7 @@ Proceed? [y/N]
* Authentication: [#!variable!old_authentication!#] * Authentication: [#!variable!old_authentication!#]
* Security: ..... [#!variable!old_security!#] * Security: ..... [#!variable!old_security!#]
* HELO domain: .. [#!variable!old_helo_domain!#] * HELO domain: .. [#!variable!old_helo_domain!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key>
<key name="message_0297">The new mail server was created with the UUID: [#!variable!uuid!#].</key> <key name="message_0297">The new mail server was created with the UUID: [#!variable!uuid!#].</key>
<key name="message_0298">The mail server has been updated.</key> <key name="message_0298">The mail server has been updated.</key>
<key name="message_0299">The mail server has been deleted.</key> <key name="message_0299">The mail server has been deleted.</key>
@ -2734,22 +2734,34 @@ Proceed? [y/N]
* E-Mail: . [#!variable!new_email!#] * E-Mail: . [#!variable!new_email!#]
* Language: [#!variable!new_language!#] * Language: [#!variable!new_language!#]
* Level: .. [#!variable!new_level!#] * Level: .. [#!variable!new_level!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key>
<key name="message_0301">Are you sure you want to change the alert recipient thusly: <key name="message_0301">Are you sure you want to change the alert recipient thusly:
* Name: ... [#!variable!old_name!#] -> [#!variable!new_name!#] * Name: ... [#!variable!old_name!#] -> [#!variable!new_name!#]
* E-Mail: . [#!variable!old_email!#] -> [#!variable!new_email!#] * E-Mail: . [#!variable!old_email!#] -> [#!variable!new_email!#]
* Language: [#!variable!old_language!#] -> [#!variable!new_language!#] * Language: [#!variable!old_language!#] -> [#!variable!new_language!#]
* Level: .. [#!variable!old_level!#] -> [#!variable!new_level!#] * Level: .. [#!variable!old_level!#] -> [#!variable!new_level!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key>
<key name="message_0302">Are you sure you want to delete the alert recipient: <key name="message_0302">Are you sure you want to delete the alert recipient:
* Name: ... [#!variable!old_name!#] * Name: ... [#!variable!old_name!#]
* E-Mail: . [#!variable!old_email!#] * E-Mail: . [#!variable!old_email!#]
* Language: [#!variable!old_language!#] * Language: [#!variable!old_language!#]
* Level: .. [#!variable!old_level!#] * Level: .. [#!variable!old_level!#]
Proceed? [y/N] Proceed? [y/N]</key>
</key> <key name="message_0303">Are you sure you want to create the alert override for the recipient and system:
* Recipient: . [#!variable!new_recipient!#]
* Host: ...... [#!variable!new_host!#]
* Alert Level: [#!variable!new_level!#]
Proceed? [y/N]</key>
<key name="message_0304">Are you sure you want to change the alert override for the recipient and system:
* Recipient: . [#!variable!old_recipient!#] -> [#!variable!new_recipient!#]
* Host: ...... [#!variable!old_host!#] -> [#!variable!new_host!#]
* Alert Level: [#!variable!old_level!#] -> [#!variable!new_level!#]
Proceed? [y/N]</key>
<key name="message_0305">Are you sure you want to delete the alert override for the recipient and system:
* Recipient: . [#!variable!old_recipient!#]
* Host: ...... [#!variable!old_host!#]
* Alert Level: [#!variable!old_level!#]
Proceed? [y/N]</key>
<!-- Translate names (protocols, etc) --> <!-- Translate names (protocols, etc) -->
<key name="name_0001">Normal Password</key> <!-- none in mail-server --> <key name="name_0001">Normal Password</key> <!-- none in mail-server -->

@ -1321,6 +1321,151 @@ sub handle_special_cases
$anvil->DRBD->_initialize_kmod({debug => 2}); $anvil->DRBD->_initialize_kmod({debug => 2});
} }
if ($host_type eq "striker")
{
# This converts the old/broken 'notifications' tables with the more appropriately named 'alert-override'
if (1)
{
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
my $query = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_catalog = 'anvil' AND table_name = 'notifications';";
$anvil->Log->variables({source => $THIS_FILE, uuid => $uuid, line => __LINE__, level => 2, list => { query => $query }});
my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if ($count)
{
my $queries = [];
push @{$queries}, "DROP FUNCTION history_notifications() CASCADE;";
push @{$queries}, "DROP TABLE history.notifications;";
push @{$queries}, "DROP TABLE public.notifications;";
push @{$queries}, q|CREATE TABLE alert_overrides (
alert_override_uuid uuid not null primary key,
alert_override_recipient_uuid uuid not null, -- The recipient we're linking.
alert_override_host_uuid uuid not null, -- This host_uuid of the referenced machine
alert_override_alert_level integer not null, -- This is the alert level (at or above) that this user wants alerts from. If set to '-1', the record is deleted.
modified_date timestamp with time zone not null,
FOREIGN KEY(alert_override_host_uuid) REFERENCES hosts(host_uuid),
FOREIGN KEY(alert_override_recipient_uuid) REFERENCES recipients(recipient_uuid)
);
ALTER TABLE alert_overrides OWNER TO admin;
CREATE TABLE history.alert_overrides (
history_id bigserial,
alert_override_uuid uuid,
alert_override_recipient_uuid uuid,
alert_override_host_uuid uuid,
alert_override_alert_level integer,
modified_date timestamp with time zone not null
);
ALTER TABLE history.alert_overrides OWNER TO admin;
CREATE FUNCTION history_alert_overrides() RETURNS trigger
AS $$
DECLARE
history_alert_overrides RECORD;
BEGIN
SELECT INTO history_alert_overrides * FROM alert_overrides WHERE alert_override_uuid = new.alert_override_uuid;
INSERT INTO history.alert_overrides
(alert_override_uuid,
alert_override_recipient_uuid,
alert_override_host_uuid,
alert_override_alert_level,
modified_date)
VALUES
(history_alert_overrides.alert_override_uuid,
history_alert_overrides.alert_override_recipient_uuid,
history_alert_overrides.alert_override_host_uuid,
history_alert_overrides.alert_override_alert_level,
history_alert_overrides.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_alert_overrides() OWNER TO admin;
CREATE TRIGGER trigger_alert_overrides
AFTER INSERT OR UPDATE ON alert_overrides
FOR EACH ROW EXECUTE PROCEDURE history_alert_overrides();
|;
foreach my $query (@{$queries})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
}
$anvil->Database->write({debug => 2, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__});
}
}
}
# This checks to make sure that the 'audits' table exists (added late into M3.0 pre-release)
if (0)
{
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
my $query = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_catalog = 'anvil' AND table_name = 'audits';";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $count = $anvil->Database->query({query => $query, uuid => $uuid, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if (not $count)
{
# Add the table.
my $query = q|
CREATE TABLE audits (
audit_uuid uuid primary key,
audit_user_uuid uuid not null, -- This is the users -> user_uuid the audit is tracking
audit_details text not null, -- This is the information explaining the action being audited.
modified_date timestamp with time zone not null,
FOREIGN KEY(audit_user_uuid) REFERENCES users(user_uuid)
);
ALTER TABLE audits OWNER TO admin;
CREATE TABLE history.audits (
history_id bigserial,
audit_uuid uuid,
audit_user_uuid uuid,
audit_details text,
modified_date timestamp with time zone not null
);
ALTER TABLE history.audits OWNER TO admin;
CREATE FUNCTION history_audits() RETURNS trigger
AS $$
DECLARE
history_audits RECORD;
BEGIN
SELECT INTO history_audits * FROM audits WHERE audit_uuid = new.audit_uuid;
INSERT INTO history.audits
(audit_uuid,
audit_user_uuid,
audit_details,
modified_date)
VALUES
(history_audit.audit_uuid,
history_audit.audit_user_uuid,
history_audit.audit_details,
history_audit.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_audits() OWNER TO admin;
CREATE TRIGGER trigger_audits
AFTER INSERT OR UPDATE ON audits
FOR EACH ROW EXECUTE PROCEDURE history_audits();
|;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
$anvil->Database->write({debug => 2, uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__});
}
}
}
}
### TODO: Remove these later. This is here to clean up how we used to handle db_in_use and lock_request flags. ### TODO: Remove these later. This is here to clean up how we used to handle db_in_use and lock_request flags.
if (1) if (1)
{ {

@ -31,11 +31,11 @@ $anvil->Get->switches({list => [
"mail-server-security", "mail-server-security",
"mail-server-authentication", "mail-server-authentication",
"mail-server-helo-domain", "mail-server-helo-domain",
"notifications", "alert-overrides",
"notification-uuid", "alert-override-uuid",
"notification-recipient-uuid", "alert-override-recipient-uuid",
"notification-host-uuid", "alert-override-host-uuid",
"notification-alert-level", "alert-override-alert-level",
"recipients", "recipients",
"recipient-uuid", "recipient-uuid",
"recipient-name", "recipient-name",
@ -70,25 +70,25 @@ elsif ($anvil->data->{switches}{"recipients"})
}}); }});
handle_recipients($anvil); handle_recipients($anvil);
} }
elsif ($anvil->data->{switches}{"notifications"}) elsif ($anvil->data->{switches}{"alert-overrides"})
{ {
$anvil->data->{sys}{show}{notifications} = 1; $anvil->data->{sys}{show}{alert_overrides} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::notifications' => $anvil->data->{sys}{show}{notifications}, 'sys::show::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides},
}}); }});
handle_notifications($anvil); handle_alert_overrides($anvil);
} }
else else
{ {
$anvil->data->{sys}{show}{mail_servers} = 1; $anvil->data->{sys}{show}{mail_servers} = 1;
$anvil->data->{sys}{show}{recipients} = 1; $anvil->data->{sys}{show}{recipients} = 1;
$anvil->data->{sys}{show}{notifications} = 1; $anvil->data->{sys}{show}{alert_overrides} = 1;
$anvil->data->{sys}{show}{systems} = 1; $anvil->data->{sys}{show}{systems} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::mail_servers' => $anvil->data->{sys}{show}{mail_servers}, 'sys::show::mail_servers' => $anvil->data->{sys}{show}{mail_servers},
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients}, 'sys::show::recipients' => $anvil->data->{sys}{show}{recipients},
'sys::show::notifications' => $anvil->data->{sys}{show}{notifications}, 'sys::show::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides},
'sys::show::systems' => $anvil->data->{sys}{show}{systems}, 'sys::show::systems' => $anvil->data->{sys}{show}{systems},
}}); }});
show_existing($anvil); show_existing($anvil);
} }
@ -100,6 +100,290 @@ $anvil->nice_exit({exit_code => 0});
# Functions # # Functions #
############################################################################################################# #############################################################################################################
sub handle_alert_overrides
{
my ($anvil) = @_;
### Are we adding, editing or deleting?
# If we're adding or editing, all fields are required.
my $confirm_needed = 0;
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
# Did the user confirm yet?
if ((not $anvil->data->{switches}{'y'}) and (not $anvil->data->{switches}{'yes'}))
{
$confirm_needed = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { confirm_needed => $confirm_needed }});
}
}
if (($anvil->data->{switches}{add}) or ($anvil->data->{switches}{edit}))
{
# Do we have what we need?
my $problem = 0;
foreach my $switch ("alert-override-recipient-uuid", "alert-override-host-uuid", "alert-override-alert-level")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
switch => $switch,
"switches::$switch" => $anvil->data->{switches}{$switch},
}});
if (($anvil->data->{switches}{$switch} eq "") or ($anvil->data->{switches}{$switch} eq "#!SET!#"))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => $switch }});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
if ($problem)
{
$anvil->nice_exit({exit_code => 1});
}
}
# These will be filled out if we need the user to confirm.
$anvil->data->{sys}{say_old_alert_override_level} = "";
$anvil->data->{sys}{say_old_alert_override_recipient} = "";
$anvil->data->{sys}{say_old_alert_override_host} = "";
$anvil->data->{sys}{say_new_alert_override_level} = "";
$anvil->data->{sys}{say_new_alert_override_recipient} = "";
$anvil->data->{sys}{say_new_alert_override_host} = "";
# Populate the new 'say' strings, if needed.
my $alert_override_uuid = $anvil->data->{switches}{"alert-override-uuid"};
my $new_alert_override_alert_level = $anvil->data->{switches}{"alert-override-alert-level"};
my $new_alert_override_recipient_uuid = $anvil->data->{switches}{"alert-override-recipient-uuid"};
my $new_alert_override_host_uuid = $anvil->data->{switches}{"alert-override-host-uuid"};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
alert_override_uuid => $alert_override_uuid,
new_alert_override_alert_level => $new_alert_override_alert_level,
new_alert_override_recipient_uuid => $new_alert_override_recipient_uuid,
new_alert_override_host_uuid => $new_alert_override_host_uuid,
}});
if ($new_alert_override_recipient_uuid)
{
$anvil->data->{sys}{say_new_alert_override_recipient} = $anvil->data->{recipients}{recipient_uuid}{$new_alert_override_recipient_uuid}{recipient_name}." (".$anvil->data->{recipients}{recipient_uuid}{$new_alert_override_recipient_uuid}{recipient_email}.")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_recipient' => $anvil->data->{sys}{say_new_alert_override_recipient},
}});
}
if ($new_alert_override_host_uuid)
{
$anvil->data->{sys}{say_new_alert_override_host} = $anvil->data->{hosts}{host_uuid}{$new_alert_override_host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_host' => $anvil->data->{sys}{say_new_alert_override_host},
}});
}
if ($new_alert_override_alert_level =~ /\d/)
{
if ($new_alert_override_alert_level == 0)
{
# Ignore
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0023"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level},
}});
}
elsif ($new_alert_override_alert_level == 1)
{
# Critical
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0024"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level},
}});
}
elsif ($new_alert_override_alert_level == 2)
{
# Warning
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0025"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level},
}});
}
elsif ($new_alert_override_alert_level == 3)
{
# Notice
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0026"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level},
}});
}
elsif ($new_alert_override_alert_level == 4)
{
# Info
$anvil->data->{sys}{say_new_alert_override_level} = $anvil->Words->string({key => "unit_0027"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_new_alert_override_level' => $anvil->data->{sys}{say_new_alert_override_level},
}});
}
}
# If we're editing or deleting, make sure we have a valid UUID.
my $old_alert_override_level = "";
my $old_alert_override_recipient_uuid = "";
my $old_alert_override_host_uuid = "";
if (($anvil->data->{switches}{edit}) or ($anvil->data->{switches}{'delete'}))
{
if (not $alert_override_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0387", variables => { switch => "alert-override-uuid" }});
$anvil->nice_exit({exit_code => 1});
}
if (not exists $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0388", variables => { uuid => $alert_override_uuid }});
$anvil->nice_exit({exit_code => 1});
}
$old_alert_override_recipient_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid};
$old_alert_override_host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid};
$old_alert_override_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
old_alert_override_recipient_uuid => $old_alert_override_recipient_uuid,
old_alert_override_host_uuid => $old_alert_override_host_uuid,
old_alert_override_level => $old_alert_override_level,
}});
# Get the translated log level name.
if ($old_alert_override_level == 0)
{
# Ignore
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0023"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level},
}});
}
elsif ($old_alert_override_level == 1)
{
# Critical
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0024"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level},
}});
}
elsif ($old_alert_override_level == 2)
{
# Warning
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0025"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level},
}});
}
elsif ($old_alert_override_level == 3)
{
# Notice
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0026"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level},
}});
}
elsif ($old_alert_override_level == 4)
{
# Info
$anvil->data->{sys}{say_old_alert_override_level} = $anvil->Words->string({key => "unit_0027"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_level' => $anvil->data->{sys}{say_old_alert_override_level},
}});
}
# Get the name / email of the recipient and the host
$anvil->data->{sys}{say_old_alert_override_recipient} = $anvil->data->{recipients}{recipient_uuid}{$old_alert_override_recipient_uuid}{recipient_name}." (".$anvil->data->{recipients}{recipient_uuid}{$old_alert_override_recipient_uuid}{recipient_email}.")";
$anvil->data->{sys}{say_old_alert_override_host} = $anvil->data->{hosts}{host_uuid}{$old_alert_override_host_uuid}{host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::say_old_alert_override_recipient' => $anvil->data->{sys}{say_old_alert_override_recipient},
'sys::say_old_alert_override_host' => $anvil->data->{sys}{say_old_alert_override_host},
}});
}
if ($confirm_needed)
{
my $key = "";
if ($anvil->data->{switches}{add})
{
$key = "message_0303";
}
elsif ($anvil->data->{switches}{edit})
{
$key = "message_0304";
}
elsif ($anvil->data->{switches}{'delete'})
{
$key = "message_0305";
}
print $anvil->Words->string({key => $key, variables => {
new_level => $anvil->data->{sys}{say_new_alert_override_level},
new_recipient => $anvil->data->{sys}{say_new_alert_override_recipient},
new_host => $anvil->data->{sys}{say_new_alert_override_host},
old_level => $anvil->data->{sys}{say_old_alert_override_level},
old_recipient => $anvil->data->{sys}{say_old_alert_override_recipient},
old_host => $anvil->data->{sys}{say_old_alert_override_host},
}})."\n";
my $answer = <STDIN>;
chomp $answer;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { answer => $answer }});
if (lc($answer) !~ /^y/)
{
print $anvil->Words->string({key => "message_0022"})."\n";
$anvil->nice_exit({exit_code => 0});
}
}
# Still alive?
if ($anvil->data->{switches}{add})
{
# Create the new entry.
my ($mail_server_uuid) = $anvil->Database->insert_or_update_alert_overrides({
debug => 2,
alert_override_recipient_uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"},
alert_override_host_uuid => $anvil->data->{switches}{"alert-override-host-uuid"},
alert_override_alert_level => $anvil->data->{switches}{"alert-override-alert-level"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0297", variables => { uuid => $mail_server_uuid }})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{edit})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_alert_overrides({
debug => 2,
alert_override_uuid => $anvil->data->{switches}{"alert-override-uuid"},
alert_override_recipient_uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"},
alert_override_host_uuid => $anvil->data->{switches}{"alert-override-host-uuid"},
alert_override_alert_level => $anvil->data->{switches}{"alert-override-alert-level"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0298"})."\n";
$anvil->nice_exit({exit_code => 0});
}
elsif ($anvil->data->{switches}{'delete'})
{
my ($mail_server_uuid) = $anvil->Database->insert_or_update_alert_overrides({
debug => 2,
'delete' => 1,
alert_override_uuid => $anvil->data->{switches}{"alert-override-uuid"},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_server_uuid => $mail_server_uuid }});
print $anvil->Words->string({key => "message_0299"})."\n";
$anvil->nice_exit({exit_code => 0});
}
else
{
$anvil->data->{sys}{show}{alert_overrides} = 1;
$anvil->data->{sys}{show}{recipients} = 1;
$anvil->data->{sys}{show}{systems} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'sys::show::alert_overrides' => $anvil->data->{sys}{show}{alert_overrides},
'sys::show::recipients' => $anvil->data->{sys}{show}{recipients},
'sys::show::systems' => $anvil->data->{sys}{show}{systems},
}});
show_existing($anvil);
}
return(0);
}
sub handle_recipients sub handle_recipients
{ {
my ($anvil) = @_; my ($anvil) = @_;
@ -454,36 +738,27 @@ sub handle_mail_servers
return(0); return(0);
} }
sub handle_notifications
{
my ($anvil) = @_;
return(0);
}
# Show existing mail servers. # Show existing mail servers.
sub show_existing sub show_existing
{ {
my ($anvil) = @_; my ($anvil) = @_;
# Show mail servers # Show mail servers
$anvil->data->{longest}{mail_server_address} = 0; $anvil->data->{longest}{mail_server_address} = 0;
$anvil->data->{longest}{mail_server_port} = 0; $anvil->data->{longest}{mail_server_port} = 0;
$anvil->data->{longest}{mail_server_username} = 0; $anvil->data->{longest}{mail_server_username} = 0;
$anvil->data->{longest}{mail_server_password} = 0; $anvil->data->{longest}{mail_server_password} = 0;
$anvil->data->{longest}{mail_server_security} = 0; $anvil->data->{longest}{mail_server_security} = 0;
$anvil->data->{longest}{mail_server_authentication} = 0; $anvil->data->{longest}{mail_server_authentication} = 0;
$anvil->data->{longest}{mail_server_helo_domain} = 0; $anvil->data->{longest}{mail_server_helo_domain} = 0;
$anvil->data->{longest}{notification_recipient_name} = 0; $anvil->data->{longest}{alert_override_recipient_name} = 0;
$anvil->data->{longest}{notification_host_name} = 0; $anvil->data->{longest}{alert_override_host_name} = 0;
$anvil->data->{longest}{notification_anvil_name} = 0; $anvil->data->{longest}{alert_override_anvil_name} = 0;
$anvil->data->{longest}{notification_alert_level} = 0; $anvil->data->{longest}{alert_override_alert_level} = 0;
$anvil->data->{longest}{recipient_name} = 0; $anvil->data->{longest}{recipient_name} = 0;
$anvil->data->{longest}{recipient_email} = 0; $anvil->data->{longest}{recipient_email} = 0;
$anvil->data->{longest}{recipient_language} = 0; $anvil->data->{longest}{recipient_language} = 0;
$anvil->data->{longest}{recipient_alert_level} = 0; $anvil->data->{longest}{recipient_alert_level} = 0;
$anvil->data->{say_alert}{1} = "1 (".$anvil->Words->string({key => "unit_0024"}).")"; $anvil->data->{say_alert}{1} = "1 (".$anvil->Words->string({key => "unit_0024"}).")";
$anvil->data->{say_alert}{2} = "2 (".$anvil->Words->string({key => "unit_0025"}).")"; $anvil->data->{say_alert}{2} = "2 (".$anvil->Words->string({key => "unit_0025"}).")";
@ -577,70 +852,70 @@ sub show_existing
} }
} }
foreach my $notification_uuid (sort {$a cmp $b} keys %{$anvil->data->{notifications}{notification_uuid}}) foreach my $alert_override_uuid (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{alert_override_uuid}})
{ {
my $notification_recipient_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_recipient_uuid}; my $alert_override_recipient_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_recipient_uuid};
my $notification_recipient_name = $anvil->data->{recipients}{recipient_uuid}{$notification_recipient_uuid}{recipient_name}; my $alert_override_recipient_name = $anvil->data->{recipients}{recipient_uuid}{$alert_override_recipient_uuid}{recipient_name};
my $notification_recipient_email = $anvil->data->{recipients}{recipient_uuid}{$notification_recipient_uuid}{recipient_email}; my $alert_override_recipient_email = $anvil->data->{recipients}{recipient_uuid}{$alert_override_recipient_uuid}{recipient_email};
my $say_recipient = $notification_recipient_name." <".$notification_recipient_email.">"; my $say_recipient = $alert_override_recipient_name." <".$alert_override_recipient_email.">";
my $notification_host_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid}; my $alert_override_host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid};
my $notification_short_host_name = $anvil->data->{hosts}{host_uuid}{$notification_host_uuid}{short_host_name}; my $alert_override_short_host_name = $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{short_host_name};
my $say_anvil_name = $anvil->data->{hosts}{host_uuid}{$notification_host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$notification_host_uuid}{anvil_name} : "--"; my $say_anvil_name = $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$alert_override_host_uuid}{anvil_name} : "--";
my $notification_alert_level = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_alert_level}; my $alert_override_alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:notification_uuid' => $notification_uuid, 's1:alert_override_uuid' => $alert_override_uuid,
's2:notification_recipient_uuid' => $notification_recipient_uuid, 's2:alert_override_recipient_uuid' => $alert_override_recipient_uuid,
's3:notification_recipient_name' => $notification_recipient_name, 's3:alert_override_recipient_name' => $alert_override_recipient_name,
's4:notification_recipient_email' => $notification_recipient_email, 's4:alert_override_recipient_email' => $alert_override_recipient_email,
's5:say_recipient' => $say_recipient, 's5:say_recipient' => $say_recipient,
's6:notification_host_uuid' => $notification_host_uuid, 's6:alert_override_host_uuid' => $alert_override_host_uuid,
's7:notification_short_host_name' => $notification_short_host_name, 's7:alert_override_short_host_name' => $alert_override_short_host_name,
's8:say_anvil_name' => $say_anvil_name, 's8:say_anvil_name' => $say_anvil_name,
's9:notification_alert_level' => $notification_alert_level, 's9:alert_override_alert_level' => $alert_override_alert_level,
}}); }});
if (length($say_recipient) > $anvil->data->{longest}{notification_recipient_name}) if (length($say_recipient) > $anvil->data->{longest}{alert_override_recipient_name})
{ {
$anvil->data->{longest}{notification_recipient_name} = length($say_recipient); $anvil->data->{longest}{alert_override_recipient_name} = length($say_recipient);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::notification_recipient_name' => $anvil->data->{longest}{notification_recipient_name}, 'longest::alert_override_recipient_name' => $anvil->data->{longest}{alert_override_recipient_name},
}}); }});
} }
if (length($notification_short_host_name) > $anvil->data->{longest}{notification_host_name}) if (length($alert_override_short_host_name) > $anvil->data->{longest}{alert_override_host_name})
{ {
$anvil->data->{longest}{notification_host_name} = length($notification_short_host_name); $anvil->data->{longest}{alert_override_host_name} = length($alert_override_short_host_name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::notification_host_name' => $anvil->data->{longest}{notification_host_name}, 'longest::alert_override_host_name' => $anvil->data->{longest}{alert_override_host_name},
}}); }});
} }
if (length($say_anvil_name) > $anvil->data->{longest}{notification_anvil_name}) if (length($say_anvil_name) > $anvil->data->{longest}{alert_override_anvil_name})
{ {
$anvil->data->{longest}{notification_anvil_name} = length($say_anvil_name); $anvil->data->{longest}{alert_override_anvil_name} = length($say_anvil_name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::notification_anvil_name' => $anvil->data->{longest}{notification_anvil_name}, 'longest::alert_override_anvil_name' => $anvil->data->{longest}{alert_override_anvil_name},
}}); }});
} }
if (length($anvil->data->{say_alert}{$notification_alert_level}) > $anvil->data->{longest}{notification_alert_level}) if (length($anvil->data->{say_alert}{$alert_override_alert_level}) > $anvil->data->{longest}{alert_override_alert_level})
{ {
$anvil->data->{longest}{notification_alert_level} = length($anvil->data->{say_alert}{$notification_alert_level}); $anvil->data->{longest}{alert_override_alert_level} = length($anvil->data->{say_alert}{$alert_override_alert_level});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::notification_alert_level' => $anvil->data->{longest}{notification_alert_level}, 'longest::alert_override_alert_level' => $anvil->data->{longest}{alert_override_alert_level},
}}); }});
} }
# This will let us display over-rides by user in order. # This will let us display over-rides by user in order.
$anvil->data->{notifications}{name_to_uuid}{$notification_recipient_name} = $notification_uuid; $anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name} = $alert_override_uuid;
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{recipient_name} = $say_recipient; $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name} = $say_recipient;
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{anvil_name} = $say_anvil_name; $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name} = $say_anvil_name;
$anvil->data->{notifications}{notification_uuid}{$notification_uuid}{host_uuid} = $notification_host_uuid; $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{host_uuid} = $alert_override_host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:notifications::name_to_uuid::${notification_recipient_name}" => $anvil->data->{notifications}{name_to_uuid}{$notification_recipient_name}, "s1:alert_overrides::name_to_uuid::${alert_override_recipient_name}" => $anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name},
"s2:notifications::notification_uuid::${notification_uuid}::recipient_name" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{recipient_name}, "s2:alert_overrides::alert_override_uuid::${alert_override_uuid}::recipient_name" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name},
"s3:notifications::notification_uuid::${notification_uuid}::anvil_name" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{anvil_name}, "s3:alert_overrides::alert_override_uuid::${alert_override_uuid}::anvil_name" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name},
"s4:notifications::notification_uuid::${notification_uuid}::host_uuid" => $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{host_uuid}, "s4:alert_overrides::alert_override_uuid::${alert_override_uuid}::host_uuid" => $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{host_uuid},
}}); }});
} }
@ -767,32 +1042,32 @@ sub show_existing
print "\n"; print "\n";
} }
if ($anvil->data->{sys}{show}{notifications}) if ($anvil->data->{sys}{show}{alert_overrides})
{ {
print "-=] Notification Over-rides;\n"; print "-=] Alert Overrides;\n";
print "Recipient, Host, Anvil!, Alert Level, Notification UUID\n"; print "Recipient, Host, Anvil!, Alert Level, Notification UUID\n";
my $notifications = 0; my $alert_overrides = 0;
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{notifications}{name_to_uuid}}) foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{name_to_uuid}})
{ {
my $notification_uuid = $anvil->data->{notifications}{name_to_uuid}{$recipient_name}; my $alert_override_uuid = $anvil->data->{alert_overrides}{name_to_uuid}{$recipient_name};
my $say_recipient = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{recipient_name}; my $say_recipient = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name};
my $say_anvil_name = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{anvil_name}; my $say_anvil_name = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{anvil_name};
my $host_uuid = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_host_uuid}; my $host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_host_uuid};
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name}; my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name};
my $alert_level = $anvil->data->{notifications}{notification_uuid}{$notification_uuid}{notification_alert_level}; my $alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:notification_uuid' => $notification_uuid, 's1:alert_override_uuid' => $alert_override_uuid,
's2:say_recipient' => $say_recipient, 's2:say_recipient' => $say_recipient,
's3:say_anvil_name' => $say_anvil_name, 's3:say_anvil_name' => $say_anvil_name,
's4:alert_level' => $alert_level, 's4:alert_level' => $alert_level,
}}); }});
print $say_recipient.", ".$short_host_name.", ".$say_anvil_name.", ".$anvil->data->{say_alert}{$alert_level}.", ".$notification_uuid."\n"; print $say_recipient.", ".$short_host_name.", ".$say_anvil_name.", ".$anvil->data->{say_alert}{$alert_level}.", ".$alert_override_uuid."\n";
$notifications++; $alert_overrides++;
} }
if (not $notifications) if (not $alert_overrides)
{ {
print "# No notification over-rides found.\n"; print "# No alert override over-rides found.\n";
} }
print "\n"; print "\n";
} }
@ -883,22 +1158,22 @@ sub check_switches
$anvil->Database->get_anvils(); $anvil->Database->get_anvils();
$anvil->Database->get_mail_servers(); $anvil->Database->get_mail_servers();
$anvil->Database->get_recipients(); $anvil->Database->get_recipients();
$anvil->Database->get_notifications(); $anvil->Database->get_alert_overrides();
$anvil->Words->language_list(); $anvil->Words->language_list();
### Now sanity check ### Now sanity check
my $problem = 0; my $problem = 0;
# These will be used to limit the display of things, if/when appropriate # These will be used to limit the display of things, if/when appropriate
$anvil->data->{sys}{show}{mail_servers} = 0; $anvil->data->{sys}{show}{mail_servers} = 0;
$anvil->data->{sys}{show}{recipients} = 0; $anvil->data->{sys}{show}{recipients} = 0;
$anvil->data->{sys}{show}{notifications} = 0; $anvil->data->{sys}{show}{alert_overrides} = 0;
$anvil->data->{sys}{show}{systems} = 0; $anvil->data->{sys}{show}{systems} = 0;
$anvil->data->{sys}{say_old_security} = ""; $anvil->data->{sys}{say_old_security} = "";
$anvil->data->{sys}{say_old_auth} = ""; $anvil->data->{sys}{say_old_auth} = "";
# Validate UUIDs. # Validate UUIDs.
foreach my $switch ("mail-server-uuid", "notification-uuid", "recipient-uuid", "notification-recipient-uuid", "notification-host-uuid") foreach my $switch ("mail-server-uuid", "alert-override-uuid", "recipient-uuid", "alert-override-recipient-uuid", "alert-override-host-uuid")
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }});
if (($anvil->data->{switches}{$switch}) && (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{$switch}}))) if (($anvil->data->{switches}{$switch}) && (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{$switch}})))
@ -1019,7 +1294,7 @@ sub check_switches
} }
# Check log levels. # Check log levels.
foreach my $switch ("notification-alert-level", "recipient-level") foreach my $switch ("alert-override-alert-level", "recipient-level")
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { switch => $switch }});
if ($anvil->data->{switches}{$switch} ne "") if ($anvil->data->{switches}{$switch} ne "")
@ -1129,6 +1404,34 @@ sub check_switches
} }
} }
# If set, make sure the "alert-override-recipient-uuid" and "alert-override-host-uuid" are valid.
if ($anvil->data->{switches}{"alert-override-recipient-uuid"})
{
my $recipient_uuid = $anvil->data->{switches}{"alert-override-recipient-uuid"};
if (not exists $anvil->data->{recipients}{recipient_uuid}{$recipient_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0390", variables => {
uuid => $anvil->data->{switches}{"alert-override-recipient-uuid"},
}});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
if ($anvil->data->{switches}{"alert-override-host-uuid"})
{
my $host_uuid = $anvil->data->{switches}{"alert-override-host-uuid"};
if (not exists $anvil->data->{hosts}{host_uuid}{$host_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0391", variables => {
uuid => $anvil->data->{switches}{"alert-override-host-uuid"},
}});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
$anvil->data->{sys}{say_new_auth} = ""; $anvil->data->{sys}{say_new_auth} = "";
if ($anvil->data->{switches}{"mail-server-authentication"}) if ($anvil->data->{switches}{"mail-server-authentication"})
{ {

Loading…
Cancel
Save