RACT: Run to apply a JSON list of settings to indexes matching a pattern
use strict;
use warnings;
use App::ElasticSearch::Utilities qw(:all);
use CLI::Helpers qw(:all);
use JSON::MaybeXS;
use Getopt
Read JSON Settings
my $RawJSON = '';
$RawJSON .= $_ while <>;
my $settings = undef;
eval {
$settings = decode_json $RawJSON;
};
if( my $err = $@ ) {
output({color=>'red'}, "Invalid JSON stru
cture passed, error was '$err'");
debug('JSON Passed was:', $RawJSON);
exit 1;
}
debug("Settings to apply");
debug_var($settings);
# Delete Indexes older than a certain point
my @indices = es
RSION = '8.8'; # VERSION
use CLI::Helpers qw(:output);
use File::Slurp::Tiny qw(read_lines);
use JSON::MaybeXS;
use Ref::Util qw(is_ref is_arrayref is_hashref);
use Text::CSV_XS;
use namespace::autoc
ers = (
txt => \&_parse_txt,
dat => \&_parse_txt,
csv => \&_parse_csv,
json => \&_parse_json,
);
sub handle_token {
my($self,$token) = @_;
my $makeMatcher = sub {
}
}
}
return \%uniq;
}
sub _parse_json {
my ($file,$field) = @_;
die "For new line delimited JSON, please specify the key, ie <field>:$file\[key.path.i.want\]"
se JSON::MaybeXS qw(:legacy);
use Pod::Usage;
use POSIX qw(strftime);
use Ref::Util qw(is_ref is_arrayref is_hashref);
use Time::HiRes qw(sleep time);
use YAML::XS;
local $YAML::XS::Boolean = "JSON::P
bg-filter=s
by=s
desc
exists=s@
fields
filter
format=s
help|h
json|jq
manual|m
match-all
max-batch-size=i
missing=s@
no-decorators|no-header
size => ($OPT{size} && $OPT{size} > 0) ? int($OPT{size}) : 20,
format => $OPT{json} ? 'json'
: $OPT{format} ? lc $OPT{format}
: 'yaml',
'max-batch-si
Search::Utilities::Aggregations;
use CLI::Helpers qw(:output);
use Getopt::Long::Descriptive;
use JSON::MaybeXS;
use Pod::Usage;
use Storable qw(dclone);
use YAML::XS ();
# Grab a copy of the args
my
"Sort ascending, default is descnding" ],
[],
["Display"],
['json', "Results as JSON"],
['show-aggs', "Show computed aggregation block"],
['show-raw', "Show raw
rint $usage->text;
exit 0;
}
pod2usage(-exitval => 0, -verbose => 2) if $opt->manual;
my $json = JSON->new->utf8->canonical;
my $qs = App::ElasticSearch::Utilities::QueryString->new();
my $q = $
> join(',', sort keys %fields),
bytes => 'b',
format => 'json'
}
}
);
$cache->set('_cat/indices', $result);
}
foreach my $
posix_default no_ignore_case no_ignore_case_always);
use Hash::Merge::Simple qw(clone_merge);
use JSON::MaybeXS;
use Pod::Usage;
use Ref::Util qw(is_hashref);
use Time::HiRes qw(time);
#-------------
-----------------------------------------------------------------------#
# Build the Query
my $JSON = JSON->new->pretty->canonical;
my $qs = App::ElasticSearch::Utilities::QueryString->new();
my $q =
eval {
push @settings, $JSON->decode($content);
1;
} or do {
debug($content);
die "Parsing JSON from $OPT{settings} failed: $@";
ngs;
use App::ElasticSearch::Utilities qw(:all);
use CLI::Helpers qw(:all);
use Const::Fast;
use JSON::MaybeXS;
use Getopt::Long::Descriptive;
use Pod::Usage;
#--------------------------------------
$opt->manual;
#------------------------------------------------------------------------#
my $json = JSON->new->pretty->utf8->canonical;
my $current = es_request('/_cluster/settings', { uri_param =>
;
}
else {
output({color=>'red'}, "FAILED applying settings:");
}
output($json->encode($data));
# Show resulting settings
my $now = es_request('/_cluster/settings', {
brev);
use Hash::Flatten qw(flatten);
use Hash::Merge::Simple qw(clone_merge);
use IPC::Run3;
use JSON::MaybeXS;
use LWP::UserAgent;
use Net::Netrc;
use Ref::Util qw(is_ref is_arrayref is_hashref);
us
.8'; # VERSION
use App::ElasticSearch::Utilities::HTTPRequest;
use CLI::Helpers qw(:output);
use JSON::MaybeXS;
use LWP::UserAgent;
use Module::Load;
use Ref::Util qw(is_ref is_arrayref is_hashref);
alized a UA: %s%s", $ua->agent, $self->password ? ' (password provided)' : '');
# Decode the JSON Automatically
$ua->add_handler( response_done => sub {
my ($response,$lwp_ua,$headers
se->content_type() || 'invalid';
# JSON Transform
if( $ctype =~ m{^application/json\b} ) {
debug({color=>'yellow',indent=>1},"JSON Decoding Response Content");
'; # VERSION
use App::ElasticSearch::Utilities qw(es_connect);
use CLI::Helpers qw(:output);
use JSON::MaybeXS;
use Ref::Util qw(is_ref is_arrayref is_hashref);
use Types::Standard qw( ArrayRef Bool
{
uri_param => {
local => 'true',
format => 'json',
bytes => 'b',
h => join(',', qw( index prirep docs store id st
PIs
use v5.16;
use warnings;
no warnings 'uninitialized';
our $VERSION = '8.8'; # VERSION
use JSON::MaybeXS;
use Ref::Util qw(is_ref is_arrayref is_hashref);
use parent 'HTTP::Request';
sub new
$class = shift;
my $self = $class->SUPER::new(@_);
$self->header('Accept' => 'application/json');
return $self;
}
sub content {
my ($self,$body) = @_;
if( is_arrayref($body) ) {
sh @body, ref $entry ? encode_json($entry) : $entry;
}
$body = join '', map { "$_\n" } @body;
$self->header('Content-Type' => 'application/x-ndjson');
}
elsif( is_hashr
:ElasticSearch::Utilities::QueryString::FileExpansion
If the match ends in .dat, .txt, .csv, or .json then we attempt to read a file with that name and OR the condition:
$ cat test.dat
50 1
2.3.7
Or
$ cat test.txt
1.2.3.4
1.2.3.5
1.2.3.6
1.2.3.7
Or
$ cat test.json
{ "ip": "1.2.3.4" }
{ "ip": "1.2.3.5" }
{ "ip": "1.2.3.6" }
{ "ip": "1.2.3.7" }
that file:
src_ip:test.dat => src_ip:(1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7)
src_ip:test.json[ip] => src_ip:(1.2.3.4 1.2.3.5 1.2.3.6 1.2.3.7)
This make it simple to use the --data-file outpu
ngs;
use App::ElasticSearch::Utilities qw(:all);
use CLI::Helpers qw(:all);
use Const::Fast;
use JSON::MaybeXS;
use Getopt::Long::Descriptive;
use Pod::Usage;
#--------------------------------------
$opt->manual;
#------------------------------------------------------------------------#
my $json = JSON->new->pretty->utf8->canonical;
my %indices = map { $_ => (es_index_days_old($_) || 0) } es_i