* Finished adding support for deleting fence agents.

* Added the 'include_deleted' parameter to Database->get_fences().

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent f49f3cd890
commit 1edf723ea5
  1. 30
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/Striker.pm
  3. 120
      cgi-bin/striker
  4. 94
      html/skins/alteeve/anvil.html
  5. 6
      share/words.xml

@ -20,7 +20,7 @@ my $THIS_FILE = "Database.pm";
# configure_pgsql
# connect
# disconnect
# get_recipients
# get_fences
# get_host_from_uuid
# get_hosts
# get_hosts_info
@ -29,6 +29,7 @@ my $THIS_FILE = "Database.pm";
# get_local_uuid
# get_mail_servers
# get_notifications
# get_recipients
# initialize
# insert_or_update_anvils
# insert_or_update_bridges
@ -1482,7 +1483,13 @@ And, to allow for lookup by name;
If the hash was already populated, it is cleared before repopulating to ensure no stray data remains.
B<<Note>>: Deleted devices (ones where C<< fence_arguments >> is set to C<< DELETED >>) are ignored.
B<<Note>>: Deleted devices (ones where C<< fence_arguments >> is set to C<< DELETED >>) are ignored. See the C<< include_deleted >> parameter to include them.
Parameters;
=head3 include_deleted (Optional, default 0)
If set to C<< 1 >>, deleted agents are included when loading the data. When C<< 0 >> is set, the default, any fence agent with C<< fence_arguments >> set to C<< DELETED >> is ignored.
=cut
sub get_fences
@ -1493,6 +1500,10 @@ sub get_fences
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_host_from_uuid()" }});
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,
}});
if (exists $anvil->data->{fences})
{
@ -1507,9 +1518,14 @@ SELECT
fence_arguments,
modified_date
FROM
fences
fences ";
if (not $include_deleted)
{
$query .= "
WHERE
fence_arguments != 'DELETED'
fence_arguments != 'DELETED'";
}
$query .= "
;";
$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__});
@ -1529,7 +1545,7 @@ WHERE
fence_uuid => $fence_uuid,
fence_name => $fence_name,
fence_agent => $fence_agent,
fence_arguments => $fence_arguments =~ /passwd=/ ? $anvil->Log->is_secure($fence_arguments) : $fence_arguments,
fence_arguments => $fence_arguments =~ /passw=/ ? $anvil->Log->is_secure($fence_arguments) : $fence_arguments,
modified_date => $modified_date,
}});
@ -1541,7 +1557,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"fences::fence_uuid::${fence_uuid}::fence_name" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_name},
"fences::fence_uuid::${fence_uuid}::fence_agent" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_agent},
"fences::fence_uuid::${fence_uuid}::fence_arguments" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments} =~ /passwd=/ ? $anvil->Log->is_secure($anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments}) : $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments},
"fences::fence_uuid::${fence_uuid}::fence_arguments" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments} =~ /passw=/ ? $anvil->Log->is_secure($anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments}) : $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments},
"fences::fence_uuid::${fence_uuid}::modified_date" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{modified_date},
}});
@ -1552,7 +1568,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"fences::fence_name::${fence_name}::fence_uuid" => $anvil->data->{fences}{fence_name}{$fence_name}{fence_uuid},
"fences::fence_name::${fence_name}::fence_agent" => $anvil->data->{fences}{fence_name}{$fence_name}{fence_agent},
"fences::fence_name::${fence_name}::fence_arguments" => $anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments} =~ /passwd=/ ? $anvil->Log->is_secure($anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments}) : $anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments},
"fences::fence_name::${fence_name}::fence_arguments" => $anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments} =~ /passw=/ ? $anvil->Log->is_secure($anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments}) : $anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments},
"fences::fence_name::${fence_name}::modified_date" => $anvil->data->{fences}{fence_name}{$fence_name}{modified_date},
}});
}

@ -124,7 +124,7 @@ sub get_fence_data
foreach my $agent_ref (@{$parsed_xml->{agent}})
{
my $fence_agent = $agent_ref->{name};
my $fence_agent = $agent_ref->{name};
$anvil->data->{fence_data}{$fence_agent}{description} = $agent_ref->{'resource-agent'}->{longdesc};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"fence_data::${fence_agent}::description" => $anvil->data->{fence_data}{$fence_agent}{description},

@ -1584,7 +1584,7 @@ sub sanity_check_fence_agent_form
my $description = $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{description};
my $type = $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{content_type};
my $default = exists $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{'default'} ? $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{'default'} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
's1:name' => $name,
's2:option_key' => $option_key,
's3:unique' => $unique,
@ -1688,6 +1688,91 @@ sub process_fences
"cgi::fence_count::value" => $anvil->data->{cgi}{fence_count}{value},
}});
# Are we deleting an agent?
if ((exists $anvil->data->{cgi}{delete_fence_uuid}) && ($anvil->data->{cgi}{delete_fence_uuid}{value}))
{
# Verify that the UUID is valid.
$anvil->Database->get_fences({debug => 2, include_deleted => 2});
my $fence_uuid = $anvil->data->{cgi}{delete_fence_uuid}{value};
my $fence_name = $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_name};
my $fence_agent = $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_agent};
if (not exists $anvil->data->{fences}{fence_uuid}{$fence_uuid})
{
# Doesn't exist.
my $message = $anvil->Words->string({key => "warning_0034", variables => { uuid => $fence_uuid }});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
elsif ($anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments} eq "DELETED")
{
# Already deleted.
my $message = $anvil->Words->string({key => "warning_0033", variables => {
name => $fence_name,
uuid => $fence_uuid,
}});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
# Has the user confirmed?
if ((exists $anvil->data->{cgi}{confirm}) && ($anvil->data->{cgi}{confirm}{value}))
{
# Delete it
my ($fence_uuid) = $anvil->Database->insert_or_update_fences({
debug => 2,
fence_uuid => $fence_uuid,
fence_name => $fence_name,
fence_agent => $fence_agent,
fence_arguments => "DELETED",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { fence_uuid => $fence_uuid }});
if ($fence_uuid)
{
# Deleted successfully
my $message = $anvil->Words->string({key => "ok_0006", variables => { name => $fence_name }});
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::ok_message" => $anvil->data->{form}{ok_message} }});
}
else
{
# Something went wrong.
my $message = $anvil->Words->string({key => "warning_0035", variables => {
name => $fence_name,
uuid => $fence_uuid,
}});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
# Show the main menu and return.
show_fence_config_main_menu($anvil);
return(0);
}
else
{
# Ask the user to confirm.
my $fence_name = $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_name};
my $fence_arguments = $anvil->data->{fences}{fence_uuid}{$fence_uuid}{fence_arguments};
my $say_fence_device = $fence_agent." ".$fence_arguments;
$say_fence_device =~ s/passw(\w+)="(.*?)"/passw$1="--"/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
fence_uuid => $fence_uuid,
fence_agent => $fence_agent,
fence_arguments => $fence_arguments =~ /passw=/ ? $anvil->Log->is_secure($fence_arguments) : $fence_arguments,
say_fence_device => $say_fence_device,
}});
# Are we asking the user to confirm one or more?
$anvil->data->{form}{back_link} = "?anvil=true&task=fences";
$anvil->data->{form}{body} = $anvil->Template->get({file => "anvil.html", name => "fence-agent-delete-confirm", variables => {
fence_name => $fence_name,
say_device => $say_fence_device,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'form::body' => $anvil->data->{form}{body} }});
return(0);
}
}
# Are we configuring an agent/device?
if ($anvil->data->{cgi}{fence_agent}{value})
{
@ -1896,6 +1981,7 @@ sub process_fences
if ((exists $anvil->data->{cgi}{$fence_uuid_key}) && ($anvil->data->{cgi}{$fence_uuid_key}{value}))
{
$anvil->Database->get_fences({debug => 2});
my $fence_uuid = $anvil->data->{cgi}{$fence_uuid_key}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { fence_uuid => $fence_uuid }});
if (exists $anvil->data->{fences}{fence_uuid}{$fence_uuid})
@ -1924,9 +2010,28 @@ sub process_fences
{
$anvil->data->{cgi}{$fence_agent_key}{value} = "";
}
if ((not exists $anvil->data->{cgi}{$fence_arguments_key}) or (not defined $anvil->data->{cgi}{$fence_arguments_key}{value}))
# For arguments, we need to break up the arguments string, append the integer to the variable, and see if that CGI is set yet.
$old_fence_arguments =~ s/="(.*?)" /="$1",/;
foreach my $pair (split/,/, $old_fence_arguments)
{
$anvil->data->{cgi}{$fence_arguments_key}{value} = "";
$pair =~ s/^\s+//; $pair =~ s/\s+$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { pair => $pair }});
my ($variable, $value) = ($pair =~ /^(.*?)="(.*)"$/);
my $cgi_key = $variable."_".$i;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:variable' => $variable,
's2:value' => $variable =~ /passw=/ ? $anvil->Log->is_secure($value) : $value,
's3:cgi_key' => $cgi_key,
}});
if ((not defined $anvil->data->{cgi}{$cgi_key}{value}) or ($anvil->data->{cgi}{$cgi_key}{value} eq ""))
{
$anvil->data->{cgi}{$cgi_key}{value} = $value;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::${cgi_key}::value" => $anvil->data->{cgi}{$cgi_key}{value},
}});
}
# Now if we don't have a value in CGI but do from the database, set the CGI.
@ -2088,7 +2193,7 @@ sub show_fence_config_main_menu
my ($anvil) = @_;
# Read in known fence devices
$anvil->Database->get_fences({debug => 2});
$anvil->Database->get_fences({debug => 3});
# Get a list of current fence agents.
my $existing_fences = "";
@ -2107,11 +2212,11 @@ sub show_fence_config_main_menu
my $fence_agent = $anvil->data->{fences}{fence_name}{$fence_name}{fence_agent};
my $fence_arguments = $anvil->data->{fences}{fence_name}{$fence_name}{fence_arguments};
my $say_fence_device = $fence_agent." ".$fence_arguments;
$say_fence_device =~ s/passwd="(.*?)"/passwd="--"/g;
$say_fence_device =~ s/passw(\w+)="(.*?)"/passw$1="--"/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
fence_uuid => $fence_uuid,
fence_agent => $fence_agent,
fence_arguments => $fence_arguments =~ /passwd=/ ? $anvil->Log->is_secure($fence_arguments) : $fence_arguments,
fence_arguments => $fence_arguments =~ /passw=/ ? $anvil->Log->is_secure($fence_arguments) : $fence_arguments,
say_fence_device => $say_fence_device,
}});
@ -2345,7 +2450,8 @@ sub process_prep_network
if (not $host_name)
{
# Didn't find it.
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0014", variables => { host_uuid => $anvil->data->{cgi}{host_uuid}{value} } }) }});
my $message = $anvil->Words->string({key => "warning_0014", variables => { host_uuid => $anvil->data->{cgi}{host_uuid}{value} } });
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->data->{cgi}{task}{value} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::task::value" => $anvil->data->{cgi}{task}{value},

@ -210,6 +210,83 @@
</table>
<!-- end fence-agent-confirm -->
<!-- start fence-agent-delete-confirm -->
<table align="center" class="anvil_main_menu">
<script type="text/javascript" src="/skins/alteeve/anvil.js"></script>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td class="main_option_icon">
<img src="#!data!skin::url!#/images/fence.png" class="top_icon" >
</td>
<td class="title">
#!string!striker_0225!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
#!variable!confirm_string!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
<form name="conce_configuration" action="" method="post">
<table class="centered">
<tr style="border: 1px dotted #7f7f7f;">
<td colspan="2" class="column_header">
#!string!header_0023!#
</td>
</tr>
<tr style="border: 1px dotted #7f7f7f;">
<td colspan="2" class="fixed_width">
#!variable!say_device!#
<input type="hidden" name="delete_fence_uuid" id="delete_fence_uuid" value="#!data!cgi::delete_fence_uuid::value!#">
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td class="close_top">
&nbsp;<br />
<input type="submit" name="back" id="back" value="#!string!striker_0098!#" class="button">
</td>
<td class="close_top" style="text-align: right;">
&nbsp;<br />
<input type="submit" name="confirm" id="confirm" value="#!string!striker_0082!#" class="button">
</td>
<input type="hidden" name="anvil" id="anvil" value="true">
<input type="hidden" name="task" id="task" value="fences">
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
</table>
<!-- end fence-agent-delete-confirm -->
<!-- start fence-agent-option-menu -->
<tr>
<td colspan="3" class="menu_title">
@ -279,12 +356,21 @@
<table>
<div id="existing_fence_devices">
<tr style="border: 1px dotted #7f7f7f;">
<!-- Device name -->
<td class="column_header">
#!string!header_0003!#:
</td>
<td>
&nbsp;
</td>
<!-- Delete -->
<td class="column_header">
#!string!header_0022!#
</td>
<td>
&nbsp;
</td>
<!-- agent and arguments -->
<td class="column_header">
#!string!header_0021!#
</td>
@ -304,7 +390,13 @@
<!-- start existing-fence-device-entry -->
<tr style="border: 1px dotted #7f7f7f;">
<td>
<a href="?anvil=true&task=fences&fence_agent=#!variable!fence_agent!#&fence_count=1&fence_uuid_1=#!variable!fence_uuid!#" class="fixed_link_highlight">#!variable!name!#</a>:
<a href="?anvil=true&task=fences&fence_agent=#!variable!fence_agent!#&fence_count=1&fence_uuid_1=#!variable!fence_uuid!#" class="fixed_link_highlight">#!variable!name!#</a>
</td>
<td>
&nbsp;
</td>
<td style="text-align: center;">
<a href="?anvil=true&task=fences&delete_fence_uuid=#!variable!fence_uuid!#" class="fixed_link_highlight"><img src="#!data!skin::url!#/images/delete.png" alt="#!string!striker_0068!#" style="height: .8em;"></a>
</td>
<td>
&nbsp;

@ -864,6 +864,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="header_0020">At IP</key>
<key name="header_0021">Agent and Arguments</key>
<key name="header_0022">Delete</key>
<key name="header_0023">Fence Device</key>
<!-- General strings shown in Striker -->
<key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard...</key>
@ -1096,6 +1097,7 @@ If you are comfortable that the target has changed for a known reason, you can s
<key name="striker_0222">Please confirm the fence device is configured the way you like.</key>
<key name="striker_0223">This is the unique name (often the host name) of this specific fence device.</key>
<key name="striker_0224">Existing fence devices:</key>
<key name="striker_0225">Confirm deleting '#!variable!fence_name!#'</key>
<!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key>
@ -1245,6 +1247,7 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="ok_0003">The alert recipient: [#!variable!recipient_email!#] has been deleted.</key>
<key name="ok_0004">Saved the alert recipient information successfully!</key>
<key name="ok_0005">The fence device: [#!variable!name!#] has been successfully saved!</key>
<key name="ok_0006">The fence device: [#!variable!name!#] has been successfully deleted!</key>
<!-- Warnings -->
<key name="warning_0001">[ Warning ] - The IP address will change. You will need to reconnect after applying these changes.</key>
@ -1279,6 +1282,9 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="warning_0030">[ Warning ] - Databse->insert_or_update_variables() was called with 'update_value_only' set, but the 'variable_uuid' wasn't passed or the 'variable_uuid' wasn't found given the 'variable_name'. Unable to update. Passed in values are logged below this message</key>
<key name="warning_0031">[ Warning ] - No internet detected (couldn't ping: [#!variable!domain!#]). Skipping attempt to download RPMs.</key>
<key name="warning_0032">[ Warning ] - The fence device: [#!variable!name!#] appears to have not been saved.</key>
<key name="warning_0033">[ Warning ] - The fence device: [#!variable!name!#] with the UUID: [#!variable!uuid!#] has already been deleted.</key>
<key name="warning_0034">[ Warning ] - The fence device with the UUID: [#!variable!uuid!#] was not found.</key>
<key name="warning_0035">[ Warning ] - The fence device: [#!variable!name!#] with the UUID: [#!variable!uuid!#] was NOT deleted. The reason may be in the: [#!data!path::log::main!#] log file on this host.</key>
<!-- Errors -->
<key name="error_0001">There are not enough network interfaces on this machine. You have: [#!variable!interface_count!#] interface(s), and you need at least: [#!variable!required_interfaces_for_single!#] interfaces to connect to the requested networks (one for Back-Channel and one for each Internet-Facing network).</key>

Loading…
Cancel
Save