Merge pull request #257 from ClusterLabs/anvil-tools-dev

Formatted the output of anvil-manage-alerts data (not yet machines) t…
main
Digimer 2 years ago committed by GitHub
commit 5d323c3ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 66
      man/anvil-manage-alerts.8
  2. 35
      share/words.xml
  3. 482
      tools/anvil-manage-alerts

@ -35,6 +35,44 @@ NOTE: All fields are required when editing an existing mail server or recipient!
\fB\-\-delete\fR \fB\-\-delete\fR
This deletes an existing mail server or alert recipient. This deletes an existing mail server or alert recipient.
.TP .TP
\fB\-\-alert-overrides\fR
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
\fB\-\-alert-override-uuid\fR <uuid>
This is required for \fB\-\-edit\fR and \fB\-\-delete\fR. It is the existing alert-override override being worked on.
.TP
\fB\-\-alert-override-recipient-uuid\fR <uuid>
This is the recipients -> recipient_uuid who we are creating the override for.
.TP
\fB\-\-alert-override-host-uuid\fR
This is the hosts -> host_uuid of the machine that you are creating the alert
.TP
\fB\-\-alert-override-alert-level\fR <1, 2, 3 or 4>
This is the desired override alert level.
Valid values are:
1 = "critical" alerts only
2 = "warning" and critical alerts
3 = "notice", warning and critical alerts
4 = "info"; All alerts. This generates almost constant alerts!
.TP
\fB\-\-level\fR <1, critical, 2, warning, 3, notice, 4, or info>
When \fB\-\-test\fR is used, this sets the level the test alert is to be sent at.
Valid values are:
1 or "critical"
2 or "warning"
3 or "notice"
4 or "info"
.TP
\fB\-\-mail-servers\fR \fB\-\-mail-servers\fR
This is used to manage mail servers. Specifically, this control the mail server that we send alert emails to. The options used with this are; This is used to manage mail servers. Specifically, this control the mail server that we send alert emails to. The options used with this are;
.TP .TP
@ -76,31 +114,6 @@ 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\-\-alert-overrides\fR
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
\fB\-\-alert-override-uuid\fR <uuid>
This is required for \fB\-\-edit\fR and \fB\-\-delete\fR. It is the existing alert-override override being worked on.
.TP
\fB\-\-alert-override-recipient-uuid\fR <uuid>
This is the recipients -> recipient_uuid who we are creating the override for.
.TP
\fB\-\-alert-override-host-uuid\fR
This is the hosts -> host_uuid of the machine that you are creating the alert
.TP
\fB\-\-alert-override-alert-level\fR <1, 2, 3 or 4>
This is the desired override alert level.
Valid values are:
1 = "critical" alerts only
2 = "warning" and critical alerts
3 = "notice", warning and critical alerts
4 = "info"; All alerts. This generates almost constant alerts!
.TP
\fB\-\-recipients\fR \fB\-\-recipients\fR
This is used to manage alert recipients. Specifically, this control the mail server that we send alert emails to. The options used with this are; This is used to manage alert recipients. Specifically, this control the mail server that we send alert emails to. The options used with this are;
.TP .TP
@ -133,6 +146,9 @@ Valid values are:
4 = "info"; All alerts. This generates almost constant alerts! 4 = "info"; All alerts. This generates almost constant alerts!
.TP .TP
\fB\-\-test\fR
Tells the program to send a test alert at the desired \fB\-\-level\fR. The requested level is required.
.TP
.SH AUTHOR .SH AUTHOR
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"

@ -556,6 +556,16 @@ The definition data passed in was:
<key name="error_0389">[ Error ] - I was asked to delete a notification over-ride, but no 'notification_uuid' was provides.</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_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> <key name="error_0391">[ Error ] - The host UUID: [#!variable!uuid!#] wasn't found in the database.</key>
<key name="error_0392">[ Error ] - The switch '--test' requires an alert level to send the test '--alert X' at. Valid alert levels are;
* 1 or "critical"
* 2 or "warning"
* 3 or "notice"
* 4 or "info"</key>
<key name="error_0393">[ Error ] - The test alert requires an alert level, but the passed: [#!variable!level!#] is incorrect. Valid options are:
* 1 or "critical"
* 2 or "warning"
* 3 or "notice"
* 4 or "info"</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 -->
@ -949,11 +959,31 @@ resource #!variable!server!# {
<key name="header_0078">Storage Group</key> <key name="header_0078">Storage Group</key>
<key name="header_0079">Used</key> <key name="header_0079">Used</key>
<key name="header_0080">Free</key> <key name="header_0080">Free</key>
<key name="header_0081">Anvil! Node Pair</key> <key name="header_0081">Anvil! Node</key>
<key name="header_0082">Interface</key> <key name="header_0082">Interface</key>
<key name="header_0083">Gateway (*DG)</key> <key name="header_0083">Gateway (*DG)</key>
<key name="header_0084">Transmitted</key> <key name="header_0084">Transmitted</key>
<key name="header_0085">Received</key> <key name="header_0085">Received</key>
<key name="header_0086">Mail Server Address</key>
<key name="header_0087">TCP Port</key>
<key name="header_0088">User Name</key>
<key name="header_0089">Password</key>
<key name="header_0090">Connection Security</key>
<key name="header_0091">Authentication Method</key>
<key name="header_0092">HELO Domain</key>
<key name="header_0093">Mail Server UUID</key>
<key name="header_0094">Recipients</key>
<key name="header_0095">E-mail</key>
<key name="header_0096">Alert Level</key>
<key name="header_0097">Language</key>
<key name="header_0098">Recipient UUID</key>
<key name="header_0099">Alert Overrides</key>
<key name="header_0100">Recipient</key>
<key name="header_0101">Anvil! Node</key>
<key name="header_0102">Alert Override UUID</key>
<key name="header_0103">Host Type</key>
<key name="header_0104">Host UUID</key>
<key name="header_0105">Machines</key>
<!-- Strings used by jobs --> <!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key> <key name="job_0001">Configure Network</key>
@ -2762,6 +2792,8 @@ Proceed? [y/N]</key>
* Host: ...... [#!variable!old_host!#] * Host: ...... [#!variable!old_host!#]
* Alert Level: [#!variable!old_level!#] * Alert Level: [#!variable!old_level!#]
Proceed? [y/N]</key> Proceed? [y/N]</key>
<key name="message_0306">This is a test alert message sent at alert level: [#!variable!level!#].</key>
<key name="message_0307">Failed to send a test alert at level: [#!variable!level!#]. Is anyone listening at that level? Is the mail server configured?</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 -->
@ -3104,6 +3136,7 @@ If you are comfortable that the target has changed for a known reason, you can s
<key name="striker_0295">This indicates that this node has had pacemaker configured.</key> <key name="striker_0295">This indicates that this node has had pacemaker configured.</key>
<key name="striker_0296">This indicates that this node or DR host has had base DRBD configured.</key> <key name="striker_0296">This indicates that this node or DR host has had base DRBD configured.</key>
<key name="striker_0297">This indicates that this node or DR host has completed all tasks needed to be a full member of the Anvil!.</key> <key name="striker_0297">This indicates that this node or DR host has completed all tasks needed to be a full member of the Anvil!.</key>
<key name="striker_0298">TCP Port</key>
<!-- These are generally units and appended to numbers --> <!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key> <key name="suffix_0001">#!variable!number!#/sec</key>

@ -22,6 +22,12 @@ $anvil->Get->switches({list => [
"add", "add",
"edit", "edit",
"delete", "delete",
"alert-overrides",
"alert-override-uuid",
"alert-override-recipient-uuid",
"alert-override-host-uuid",
"alert-override-alert-level",
"level",
"mail-servers", "mail-servers",
"mail-server-uuid", "mail-server-uuid",
"mail-server-address", "mail-server-address",
@ -31,17 +37,13 @@ $anvil->Get->switches({list => [
"mail-server-security", "mail-server-security",
"mail-server-authentication", "mail-server-authentication",
"mail-server-helo-domain", "mail-server-helo-domain",
"alert-overrides",
"alert-override-uuid",
"alert-override-recipient-uuid",
"alert-override-host-uuid",
"alert-override-alert-level",
"recipients", "recipients",
"recipient-uuid", "recipient-uuid",
"recipient-name", "recipient-name",
"recipient-email", "recipient-email",
"recipient-language", "recipient-language",
"recipient-level", "recipient-level",
"test",
"y", "y",
"yes", "yes",
]}); ]});
@ -78,6 +80,10 @@ elsif ($anvil->data->{switches}{"alert-overrides"})
}}); }});
handle_alert_overrides($anvil); handle_alert_overrides($anvil);
} }
elsif ($anvil->data->{switches}{"test"})
{
handle_test_alert($anvil);
}
else else
{ {
$anvil->data->{sys}{show}{mail_servers} = 1; $anvil->data->{sys}{show}{mail_servers} = 1;
@ -100,6 +106,68 @@ $anvil->nice_exit({exit_code => 0});
# Functions # # Functions #
############################################################################################################# #############################################################################################################
sub handle_test_alert
{
my ($anvil) = @_;
# * 1 or "critical"
# * 2 or "warning"
# * 3 or "notice"
# * 4 or "info"
my $level = "";
my $say_level = "";
if (($anvil->data->{switches}{level} eq "critical") or ($anvil->data->{switches}{level} eq "1"))
{
$level = "critical";
$say_level = $anvil->Words->string({key => "unit_0024"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
level => $level,
say_level => $say_level,
}});
}
elsif (($anvil->data->{switches}{level} eq "warning") or ($anvil->data->{switches}{level} eq "2"))
{
$level = "warning";
$say_level = $anvil->Words->string({key => "unit_0025"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
level => $level,
say_level => $say_level,
}});
}
elsif (($anvil->data->{switches}{level} eq "notice") or ($anvil->data->{switches}{level} eq "3"))
{
$level = "notice";
$say_level = $anvil->Words->string({key => "unit_0026"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
level => $level,
say_level => $say_level,
}});
}
elsif (($anvil->data->{switches}{level} eq "info") or ($anvil->data->{switches}{level} eq "4"))
{
$level = "info";
$say_level = $anvil->Words->string({key => "unit_0027"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
level => $level,
say_level => $say_level,
}});
}
my $alert_uuid = $anvil->Alert->register({debug => 2, alert_level => $level, message => "message_0306", variables => { level => $say_level }, set_by => $THIS_FILE, sort_position => 0});
if ($alert_uuid)
{
print $anvil->Words->string({key => "message_0306", variables => { level => $say_level }})."\n";
$anvil->Email->send_alerts();
}
else
{
# No one is listening, or no mail servers are configured.
print $anvil->Words->string({key => "message_0307", variables => { level => $say_level }})."\n";
}
return(0);
}
sub handle_alert_overrides sub handle_alert_overrides
{ {
my ($anvil) = @_; my ($anvil) = @_;
@ -744,21 +812,28 @@ 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} = length($anvil->Words->string({key => "header_0086"}));
$anvil->data->{longest}{mail_server_port} = 0; $anvil->data->{longest}{mail_server_port} = length($anvil->Words->string({key => "header_0087"}));
$anvil->data->{longest}{mail_server_username} = 0; $anvil->data->{longest}{mail_server_username} = length($anvil->Words->string({key => "header_0088"}));
$anvil->data->{longest}{mail_server_password} = 0; $anvil->data->{longest}{mail_server_password} = length($anvil->Words->string({key => "header_0089"}));
$anvil->data->{longest}{mail_server_security} = 0; $anvil->data->{longest}{mail_server_security} = length($anvil->Words->string({key => "header_0090"}));
$anvil->data->{longest}{mail_server_authentication} = 0; $anvil->data->{longest}{mail_server_authentication} = length($anvil->Words->string({key => "header_0091"}));
$anvil->data->{longest}{mail_server_helo_domain} = 0; $anvil->data->{longest}{mail_server_helo_domain} = length($anvil->Words->string({key => "header_0092"}));
$anvil->data->{longest}{alert_override_recipient_name} = 0; $anvil->data->{longest}{mail_server_uuid} = length($anvil->Words->string({key => "header_0093"}));
$anvil->data->{longest}{alert_override_host_name} = 0; $anvil->data->{longest}{recipient_name} = length($anvil->Words->string({key => "header_0003"}));
$anvil->data->{longest}{alert_override_anvil_name} = 0; $anvil->data->{longest}{recipient_email} = length($anvil->Words->string({key => "header_0095"}));
$anvil->data->{longest}{alert_override_alert_level} = 0; $anvil->data->{longest}{recipient_alert_level} = length($anvil->Words->string({key => "header_0096"}));
$anvil->data->{longest}{recipient_name} = 0; $anvil->data->{longest}{recipient_language} = length($anvil->Words->string({key => "header_0097"}));
$anvil->data->{longest}{recipient_email} = 0; $anvil->data->{longest}{recipient_uuid} = length($anvil->Words->string({key => "header_0098"}));
$anvil->data->{longest}{recipient_language} = 0; $anvil->data->{longest}{alert_override_recipient_name} = length($anvil->Words->string({key => "header_0100"}));
$anvil->data->{longest}{recipient_alert_level} = 0; $anvil->data->{longest}{alert_override_host_name} = length($anvil->Words->string({key => "header_0026"}));
$anvil->data->{longest}{alert_override_anvil_name} = length($anvil->Words->string({key => "header_0101"}));
$anvil->data->{longest}{alert_override_alert_level} = length($anvil->Words->string({key => "header_0096"}));
$anvil->data->{longest}{alert_override_uuid} = length($anvil->Words->string({key => "header_0102"}));
$anvil->data->{longest}{host_name} = length($anvil->Words->string({key => "header_0026"}));
$anvil->data->{longest}{host_type} = length($anvil->Words->string({key => "header_0103"}));
$anvil->data->{longest}{host_anvil_name} = length($anvil->Words->string({key => "header_0081"}));
$anvil->data->{longest}{host_uuid} = length($anvil->Words->string({key => "header_0104"}));
$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"}).")";
@ -850,6 +925,14 @@ sub show_existing
'longest::mail_server_helo_domain' => $anvil->data->{longest}{mail_server_helo_domain}, 'longest::mail_server_helo_domain' => $anvil->data->{longest}{mail_server_helo_domain},
}}); }});
} }
if (length($mail_server_uuid) > $anvil->data->{longest}{mail_server_uuid})
{
$anvil->data->{longest}{mail_server_uuid} = length($mail_server_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::mail_server_uuid' => $anvil->data->{longest}{mail_server_uuid},
}});
}
} }
foreach my $alert_override_uuid (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{alert_override_uuid}}) foreach my $alert_override_uuid (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{alert_override_uuid}})
@ -906,6 +989,14 @@ sub show_existing
}}); }});
} }
if (length($alert_override_uuid) > $anvil->data->{longest}{alert_override_uuid})
{
$anvil->data->{longest}{alert_override_uuid} = length($alert_override_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::alert_override_uuid' => $anvil->data->{longest}{alert_override_uuid},
}});
}
# This will let us display over-rides by user in order. # This will let us display over-rides by user in order.
$anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name} = $alert_override_uuid; $anvil->data->{alert_overrides}{name_to_uuid}{$alert_override_recipient_name} = $alert_override_uuid;
$anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name} = $say_recipient; $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{recipient_name} = $say_recipient;
@ -966,16 +1057,131 @@ sub show_existing
'longest::recipient_alert_level' => $anvil->data->{longest}{recipient_alert_level}, 'longest::recipient_alert_level' => $anvil->data->{longest}{recipient_alert_level},
}}); }});
} }
if (length($recipient_uuid) > $anvil->data->{longest}{recipient_uuid})
{
$anvil->data->{longest}{recipient_uuid} = length($recipient_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::recipient_uuid' => $anvil->data->{longest}{recipient_uuid},
}});
}
}
# Pull out the Strikers, node pair members and DR hosts.
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}})
{
my $host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name};
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name};
my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type};
my $anvil_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} : "--";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:host_name' => $host_name,
's2:short_host_name' => $short_host_name,
's3:host_type' => $host_type,
's4:anvil_name' => $anvil_name,
}});
if (length($short_host_name) > $anvil->data->{longest}{host_name})
{
$anvil->data->{longest}{host_name} = length($short_host_name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::host_name' => $anvil->data->{longest}{host_name},
}});
}
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = "";
if ($host_type eq "striker")
{
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0003"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type},
}});
}
elsif ($host_type eq "node")
{
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0007"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type},
}});
}
elsif ($host_type eq "dr")
{
$anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type} = $anvil->Words->string({key => "brand_0008"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"hosts::host_uuid::${host_uuid}::say_host_type" => $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type},
}});
}
if (length($anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type}) > $anvil->data->{longest}{host_type})
{
$anvil->data->{longest}{host_type} = length($anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::host_type' => $anvil->data->{longest}{host_type},
}});
}
if (length($anvil_name) > $anvil->data->{longest}{host_anvil_name})
{
$anvil->data->{longest}{host_anvil_name} = length($anvil_name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::host_anvil_name' => $anvil->data->{longest}{host_anvil_name},
}});
}
if (length($host_uuid) > $anvil->data->{longest}{host_uuid})
{
$anvil->data->{longest}{host_uuid} = length($host_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'longest::host_uuid' => $anvil->data->{longest}{host_uuid},
}});
}
} }
# Now show the data. # Now show the data.
if ($anvil->data->{sys}{show}{mail_servers}) if ($anvil->data->{sys}{show}{mail_servers})
{ {
# my $break_line = "+-".sprintf("%0${longest_anvil_name}d", 0); my $longest_mail_server_address = $anvil->data->{longest}{mail_server_address};
# my $header_line = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." "; my $longest_mail_server_port = $anvil->data->{longest}{mail_server_port};
# my $blank_lead = "| ".sprintf("%-${longest_anvil_name}s", $anvil_header)." "; my $longest_mail_server_username = $anvil->data->{longest}{mail_server_username};
print "-=] Mail Servers;\n"; my $longest_mail_server_password = $anvil->data->{longest}{mail_server_password};
print "Address, Port, Login User, Password, Security, Authentication, HELO Domaon, Mail Server UUID\n"; my $longest_mail_server_security = $anvil->data->{longest}{mail_server_security};
my $longest_mail_server_authentication = $anvil->data->{longest}{mail_server_authentication};
my $longest_mail_server_helo_domain = $anvil->data->{longest}{mail_server_helo_domain};
my $longest_mail_server_uuid = $anvil->data->{longest}{mail_server_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:longest_mail_server_address' => $longest_mail_server_address,
's2:longest_mail_server_port' => $longest_mail_server_port,
's3:longest_mail_server_username' => $longest_mail_server_username,
's4:longest_mail_server_password' => $longest_mail_server_password,
's5:longest_mail_server_security' => $longest_mail_server_security,
's6:longest_mail_server_authentication' => $longest_mail_server_authentication,
's7:longest_mail_server_helo_domain' => $longest_mail_server_helo_domain,
's8:longest_mail_server_uuid' => $longest_mail_server_uuid,
}});
my $break_line = "+-".sprintf("%0${longest_mail_server_address}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_port}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_username}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_password}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_security}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_authentication}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_helo_domain}d", 0);
$break_line .= "-+-".sprintf("%0${longest_mail_server_uuid}d", 0)."-+";
$break_line =~ s/0/-/g;
my $header_line = "| ".sprintf("%-${longest_mail_server_address}s", $anvil->Words->string({key => "header_0086"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_port}s", $anvil->Words->string({key => "header_0087"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_username}s", $anvil->Words->string({key => "header_0088"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_password}s", $anvil->Words->string({key => "header_0089"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_security}s", $anvil->Words->string({key => "header_0090"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", $anvil->Words->string({key => "header_0091"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", $anvil->Words->string({key => "header_0092"}))." ";
$header_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", $anvil->Words->string({key => "header_0093"}))." |";
# Display
print "-=] ".$anvil->Words->string({key => "striker_0187"})."\n";
print $break_line."\n";
print $header_line."\n";
print $break_line."\n";
my $mail_servers = 0; my $mail_servers = 0;
foreach my $mail_server_address (sort {$a cmp $b} keys %{$anvil->data->{mail_servers}{address_to_uuid}}) foreach my $mail_server_address (sort {$a cmp $b} keys %{$anvil->data->{mail_servers}{address_to_uuid}})
{ {
@ -998,20 +1204,68 @@ sub show_existing
}}); }});
next if $mail_server_helo_domain eq "DELETED"; next if $mail_server_helo_domain eq "DELETED";
print $mail_server_address.", ".$mail_server_port.", ".$mail_server_username.", ".$mail_server_password.", ".$mail_server_security.", ".$mail_server_authentication.", ".$mail_server_helo_domain.", ".$mail_server_uuid."\n"; my $entry_line = "| ".sprintf("%-${longest_mail_server_address}s", $mail_server_address)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_port}s", $mail_server_port)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_username}s", $mail_server_username)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_password}s", $mail_server_password)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_security}s", $mail_server_security)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", $mail_server_authentication)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", $mail_server_helo_domain)." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", $mail_server_uuid)." |";
print $entry_line."\n";
$mail_servers++; $mail_servers++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mail_servers => $mail_servers }});
} }
if (not $mail_servers) if (not $mail_servers)
{ {
print "# No mail servers configured yet!\n"; my $entry_line = "| ".sprintf("%-${longest_mail_server_address}s", '--')." ";
} $entry_line .= "| ".sprintf("%-${longest_mail_server_port}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_username}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_password}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_security}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_authentication}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_helo_domain}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_mail_server_uuid}s", '--')." |";
print $entry_line."\n";
}
print $break_line."\n";
print "\n"; print "\n";
} }
if ($anvil->data->{sys}{show}{recipients}) if ($anvil->data->{sys}{show}{recipients})
{ {
print "-=] Recipients;\n"; my $longest_recipient_name = $anvil->data->{longest}{recipient_name};
print "Name, Email, Alert Level, Language, Recipient UUID\n"; my $longest_recipient_email = $anvil->data->{longest}{recipient_email};
my $longest_recipient_alert_level = $anvil->data->{longest}{recipient_alert_level};
my $longest_recipient_language = $anvil->data->{longest}{recipient_language};
my $longest_recipient_uuid = $anvil->data->{longest}{recipient_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:longest_recipient_name' => $longest_recipient_name,
's2:longest_recipient_email' => $longest_recipient_email,
's3:longest_recipient_alert_level' => $longest_recipient_alert_level,
's4:longest_recipient_language' => $longest_recipient_language,
's5:longest_recipient_uuid' => $longest_recipient_uuid,
}});
my $break_line = "+-".sprintf("%0${longest_recipient_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_recipient_email}d", 0);
$break_line .= "-+-".sprintf("%0${longest_recipient_alert_level}d", 0);
$break_line .= "-+-".sprintf("%0${longest_recipient_language}d", 0);
$break_line .= "-+-".sprintf("%0${longest_recipient_uuid}d", 0)."-+";
$break_line =~ s/0/-/g;
my $header_line = "| ".sprintf("%-${longest_recipient_name}s", $anvil->Words->string({key => "header_0003"}))." ";
$header_line .= "| ".sprintf("%-${longest_recipient_email}s", $anvil->Words->string({key => "header_0095"}))." ";
$header_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", $anvil->Words->string({key => "header_0096"}))." ";
$header_line .= "| ".sprintf("%-${longest_recipient_language}s", $anvil->Words->string({key => "header_0097"}))." ";
$header_line .= "| ".sprintf("%-${longest_recipient_uuid}s", $anvil->Words->string({key => "header_0098"}))." |";
# Display
print "-=] ".$anvil->Words->string({key => "header_0094"})."\n";
print $break_line."\n";
print $header_line."\n";
print $break_line."\n";
my $recipients = 0; my $recipients = 0;
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{recipients}{name_to_uuid}}) foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{recipients}{name_to_uuid}})
{ {
@ -1032,20 +1286,63 @@ sub show_existing
# Get the translated log level name. # Get the translated log level name.
my $say_recipient_level = say_recipient_level($anvil, $recipient_level); my $say_recipient_level = say_recipient_level($anvil, $recipient_level);
print $recipient_name.", ".$recipient_email.", ".$say_recipient_level.", ".$say_language.", ".$recipient_uuid."\n"; my $entry_line = "| ".sprintf("%-${longest_recipient_name}s", $recipient_name)." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_email}s", $recipient_email)." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", $say_recipient_level)." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_language}s", $say_language)." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_uuid}s", $recipient_uuid)." |";
print $entry_line."\n";
$recipients++; $recipients++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { recipients => $recipients }});
} }
if (not $recipients) if (not $recipients)
{ {
print "# No alert recipients added yet!\n"; my $entry_line = "| ".sprintf("%-${longest_recipient_name}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_email}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_alert_level}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_language}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_recipient_uuid}s", '--')." |";
print $entry_line."\n";
} }
print $break_line."\n";
print "\n"; print "\n";
} }
if ($anvil->data->{sys}{show}{alert_overrides}) if ($anvil->data->{sys}{show}{alert_overrides})
{ {
print "-=] Alert Overrides;\n"; my $longest_alert_override_recipient_name = $anvil->data->{longest}{alert_override_recipient_name};
print "Recipient, Host, Anvil!, Alert Level, Notification UUID\n"; my $longest_alert_override_host_name = $anvil->data->{longest}{alert_override_host_name};
my $longest_alert_override_anvil_name = $anvil->data->{longest}{alert_override_anvil_name};
my $longest_alert_override_alert_level = $anvil->data->{longest}{alert_override_alert_level};;
my $longest_alert_override_uuid = $anvil->data->{longest}{alert_override_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:longest_alert_override_recipient_name' => $longest_alert_override_recipient_name,
's2:longest_alert_override_host_name' => $longest_alert_override_host_name,
's3:longest_alert_override_anvil_name' => $longest_alert_override_anvil_name,
's4:longest_alert_override_alert_level' => $longest_alert_override_alert_level,
's5:longest_alert_override_uuid' => $longest_alert_override_uuid,
}});
my $break_line = "+-".sprintf("%0${longest_alert_override_recipient_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_alert_override_host_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_alert_override_anvil_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_alert_override_alert_level}d", 0);
$break_line .= "-+-".sprintf("%0${longest_alert_override_uuid}d", 0)."-+";
$break_line =~ s/0/-/g;
my $header_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", $anvil->Words->string({key => "header_0100"}))." ";
$header_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", $anvil->Words->string({key => "header_0026"}))." ";
$header_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", $anvil->Words->string({key => "header_0101"}))." ";
$header_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", $anvil->Words->string({key => "header_0096"}))." ";
$header_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", $anvil->Words->string({key => "header_0102"}))." |";
# Display
print "-=] ".$anvil->Words->string({key => "header_0099"})."\n";
print $break_line."\n";
print $header_line."\n";
print $break_line."\n";
my $alert_overrides = 0; my $alert_overrides = 0;
foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{name_to_uuid}}) foreach my $recipient_name (sort {$a cmp $b} keys %{$anvil->data->{alert_overrides}{name_to_uuid}})
{ {
@ -1055,55 +1352,96 @@ sub show_existing
my $host_uuid = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_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->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level}; my $alert_level = $anvil->data->{alert_overrides}{alert_override_uuid}{$alert_override_uuid}{alert_override_alert_level};
my $say_alert_level = $anvil->data->{say_alert}{$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:alert_override_uuid' => $alert_override_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,
's5:say_alert_level' => $say_alert_level,
}}); }});
print $say_recipient.", ".$short_host_name.", ".$say_anvil_name.", ".$anvil->data->{say_alert}{$alert_level}.", ".$alert_override_uuid."\n"; my $entry_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", $say_recipient)." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", $short_host_name)." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", $say_anvil_name)." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", $say_alert_level)." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", $alert_override_uuid)." |";
print $entry_line."\n";
$alert_overrides++; $alert_overrides++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { alert_overrides => $alert_overrides }});
} }
if (not $alert_overrides) if (not $alert_overrides)
{ {
print "# No alert override over-rides found.\n"; my $entry_line = "| ".sprintf("%-${longest_alert_override_recipient_name}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_host_name}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_anvil_name}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_alert_level}s", '--')." ";
$entry_line .= "| ".sprintf("%-${longest_alert_override_uuid}s", '--')." |";
print $entry_line."\n";
} }
print $break_line."\n";
print "\n"; print "\n";
} }
# Lastly, show machines. # Lastly, show machines.
if ($anvil->data->{sys}{show}{systems}) if ($anvil->data->{sys}{show}{systems})
{ {
print "-=] Striker Dashboards;\n"; my $longest_host_name = $anvil->data->{longest}{host_name};
my $longest_host_type = $anvil->data->{longest}{host_type};
my $longest_host_anvil_name = $anvil->data->{longest}{host_anvil_name};
my $longest_host_uuid = $anvil->data->{longest}{host_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:longest_host_name' => $longest_host_name,
's2:longest_host_type' => $longest_host_type,
's3:longest_host_anvil_name' => $longest_host_anvil_name,
's4:longest_host_uuid' => $longest_host_uuid,
}});
my $break_line = "+-".sprintf("%0${longest_host_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_host_type}d", 0);
$break_line .= "-+-".sprintf("%0${longest_host_anvil_name}d", 0);
$break_line .= "-+-".sprintf("%0${longest_host_uuid}d", 0)."-+";
$break_line =~ s/0/-/g;
my $header_line = "| ".sprintf("%-${longest_host_name}s", $anvil->Words->string({key => "header_0026"}))." ";
$header_line .= "| ".sprintf("%-${longest_host_type}s", $anvil->Words->string({key => "header_0103"}))." ";
$header_line .= "| ".sprintf("%-${longest_host_anvil_name}s", $anvil->Words->string({key => "header_0081"}))." ";
$header_line .= "| ".sprintf("%-${longest_host_uuid}s", $anvil->Words->string({key => "header_0104"}))." |";
# Display
print "-=] ".$anvil->Words->string({key => "header_0105"})."\n";
print $break_line."\n";
print $header_line."\n";
print $break_line."\n";
foreach my $show_host_type ("striker", "node", "dr")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { show_host_type => $show_host_type }});
foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}}) foreach my $host_name (sort {$a cmp $b} keys %{$anvil->data->{sys}{hosts}{by_name}})
{ {
my $host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name}; my $host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name};
my $short_host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{short_host_name};
my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type}; my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type};
next if $host_type ne "striker"; my $say_host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{say_host_type};
my $anvil_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} ? $anvil->data->{hosts}{host_uuid}{$host_uuid}{anvil_name} : "--";
next if $host_type ne $show_host_type;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:host_name' => $host_name, 's1:host_name' => $host_name,
's2:host_uuid' => $host_uuid, 's2:host_uuid' => $host_uuid,
's3:short_host_name' => $short_host_name,
's4:host_type' => $host_type,
's5:say_host_type' => $say_host_type,
's6:anvil_name' => $anvil_name,
}}); }});
print "- ".$host_name.", UUID: [".$host_uuid."]\n"; my $entry_line = "| ".sprintf("%-${longest_host_name}s", $short_host_name)." ";
$entry_line .= "| ".sprintf("%-${longest_host_type}s", $say_host_type)." ";
$entry_line .= "| ".sprintf("%-${longest_host_anvil_name}s", $anvil_name)." ";
$entry_line .= "| ".sprintf("%-${longest_host_uuid}s", $host_uuid)." |";
print $entry_line."\n";
} }
print "\n";
print "-=] Anvil! Nodes;\n";
foreach my $anvil_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_name}})
{
my $anvil_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid};
my $anvil_description = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description};
my $anvil_node1_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node1_host_uuid};
my $anvil_node2_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid};
my $anvil_dr1_host_uuid = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_dr1_host_uuid};
my $say_dr1_name = $anvil_dr1_host_uuid ? $anvil->data->{hosts}{host_uuid}{$anvil_dr1_host_uuid}{short_host_name} : "--";
my $say_dr1_uuid = $anvil_dr1_host_uuid ? $anvil_dr1_host_uuid : "--";
print "- Name: [".$anvil_name."], UUID: [".$anvil_uuid."], Description: [".$anvil_uuid."]\n";
print " - Node 1: .. [".$anvil->data->{hosts}{host_uuid}{$anvil_node1_host_uuid}{short_host_name}."], UUID: [".$anvil_node1_host_uuid."]\n";
print " - Node 2: .. [".$anvil->data->{hosts}{host_uuid}{$anvil_node2_host_uuid}{short_host_name}."], UUID: [".$anvil_node2_host_uuid."]\n";
print " - DR Host 1: [".$say_dr1_name."], UUID: [".$say_dr1_uuid."]\n";
} }
print $break_line."\n";
} }
return(0); return(0);
@ -1172,6 +1510,42 @@ sub check_switches
$anvil->data->{sys}{say_old_security} = ""; $anvil->data->{sys}{say_old_security} = "";
$anvil->data->{sys}{say_old_auth} = ""; $anvil->data->{sys}{say_old_auth} = "";
# If we're given 'test', make sure the level is provides.
if ($anvil->data->{switches}{test})
{
if (not $anvil->data->{switches}{level})
{
# Test requires a level
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0392"});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
# Is the level valid?
# * 1 or "critical"
# * 2 or "warning"
# * 3 or "notice"
# * 4 or "info"
if (($anvil->data->{switches}{level} ne "critical") &&
($anvil->data->{switches}{level} ne "1") &&
($anvil->data->{switches}{level} ne "warning") &&
($anvil->data->{switches}{level} ne "2") &&
($anvil->data->{switches}{level} ne "notice") &&
($anvil->data->{switches}{level} ne "3") &&
($anvil->data->{switches}{level} ne "info") &&
($anvil->data->{switches}{level} ne "4"))
{
# Invalid test alert level.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0393", variables => {
level => $anvil->data->{switches}{level},
}});
$problem = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
}
}
# Validate UUIDs. # Validate UUIDs.
foreach my $switch ("mail-server-uuid", "alert-override-uuid", "recipient-uuid", "alert-override-recipient-uuid", "alert-override-host-uuid") foreach my $switch ("mail-server-uuid", "alert-override-uuid", "recipient-uuid", "alert-override-recipient-uuid", "alert-override-host-uuid")
{ {

Loading…
Cancel
Save