mirror of
https://github.com/librenms/librenms-agent.git
synced 2024-05-09 09:54:52 +00:00
[add-opensearch-options] Add secure(-S) and disable hostname validation(-i) options for opensearch script
This commit is contained in:
+15
-3
@@ -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.
|
||||
@@ -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 = {
|
||||
@@ -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} ) {
|
||||
@@ -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 ) {
|
||||
|
||||
Reference in New Issue
Block a user