Skip to content

Commit

Permalink
[add-opensearch-options] Add secure(-S) and disable hostname validati…
Browse files Browse the repository at this point in the history
…on(-i) options for opensearch script
  • Loading branch information
EdwinHoksberg authored and edwinrocketcode committed Apr 23, 2024
1 parent 80d6ac6 commit 716519d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions snmp/opensearch
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Supported command line options are as below.
Default: 127.0.0.1
-p <port> The port to use.
Default: 9200
-S Use https instead of http.
-I Do not verify hostname (when used with -S).
-P Pretty print.
The last is only really relevant to the usage with SNMP.
Expand All @@ -59,21 +61,27 @@ sub main::HELP_MESSAGE {
. " Default: 127.0.0.1\n"
. "-p <port> The port to use.\n"
. " Default: 9200\n"
. "-S Use https instead of http.\n"
. "-I Do not verify hostname (when used with -S).\n"
. "-P Pretty print.\n";
}

my $protocol = 'http';
my $host = '127.0.0.1';
my $port = 9200;

#gets the options
my %opts;
getopts( 'h:p:P', \%opts );
getopts( 'h:p:SIP', \%opts );
if ( defined( $opts{h} ) ) {
$host = $opts{h};
}
if ( defined( $opts{p} ) ) {
$port = $opts{p};
}
if ( $opts{S} ) {
$protocol = 'https';
}

#
my $to_return = {
Expand All @@ -83,8 +91,8 @@ my $to_return = {
date => {},
};

my $stats_url = 'http://' . $host . ':' . $port . '/_stats';
my $health_url = 'http://' . $host . ':' . $port . '/_cluster/health';
my $stats_url = $protocol . '://' . $host . ':' . $port . '/_stats';
my $health_url = $protocol . '://' . $host . ':' . $port . '/_cluster/health';

my $json = JSON->new->allow_nonref->canonical(1);
if ( $opts{P} ) {
Expand All @@ -93,6 +101,10 @@ if ( $opts{P} ) {

my $ua = LWP::UserAgent->new( timeout => 10 );

if ( $opts{I} ) {
$ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00 );
}

my $stats_response = $ua->get($stats_url);
my $stats_json;
if ( $stats_response->is_success ) {
Expand Down

0 comments on commit 716519d

Please sign in to comment.