App-ElasticSearch-Utilities
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
scripts/es-alias-manager.pl view on Meta::CPAN
#!perl
# PODNAME: es-alias-manager.pl
# ABSTRACT: Allow easy alias management for daily indexes
use strict;
use warnings;
use App::ElasticSearch::Utilities qw(:default);
use CLI::Helpers qw(:all);
use DateTime;
use Getopt::Long qw(:config no_ignore_case no_ignore_case_always);
use Pod::Usage;
use Ref::Util qw( is_ref );
use YAML::XS ();
#------------------------------------------------------------------------#
# Argument Collection
my %opt;
GetOptions(\%opt,
'all',
'config=s',
'skip=s',
# Basic options
'help|h',
'manual|m',
);
#------------------------------------------------------------------------#
# Documentations!
pod2usage(1) if $opt{help};
pod2usage(-exitstatus => 0, -verbose => 2) if $opt{manual};
my %actions = (
add => 'Create any missing aliases',
remove => 'Remove any aliases not in the desired set',
);
# We might skip one thing or another
if( exists $opt{skip} && !exists $actions{$opt{skip}} ) {
output({color=>'red',sticky=>1}, "Invalid action to skip: $opt{skip}");
output({clear=>1},"Valid actions to skip are:");
output({indent=>1}, sprintf "%s - %s", $_, $actions{$_}) for sort keys %actions;
pod2usage(-exitstatus => 1);
}
my %CFG = (
config => '/etc/elasticsearch/aliases.yml',
);
# Extract from our options if we've overridden defaults
foreach my $setting (keys %CFG) {
$CFG{$setting} = $opt{$setting} if exists $opt{$setting} and defined $opt{$setting};
}
if ( !exists $CFG{config} and ! -f $CFG{config} ) {
pod2usage(1);
}
my $ALIAS = YAML::XS::LoadFile( $CFG{config} ) or die "unable to read $CFG{config}";
# Create the target uri for the ES Cluster
my $TARGET = exists $opt{host} && defined $opt{host} ? $opt{host} : 'localhost';
# Grab a connection to ElasticSearch
my $es = es_connect();
# Delete Indexes older than a certain point
my $TODAY = DateTime->now()->truncate( to => 'day' );
my $indices = es_request('_aliases');
if ( !defined $indices ) {
output({color=>"red"}, "Unable to locate indices by get_aliases()!");
exit 1;
}
debug_var($indices);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.442 second using v1.00-cache-2.02-grep-82fe00e-cpan-48ebf85a1963 )