redis: fix "autoconf" to return "no" if no instances are configured

Previously it returned "yes" and empty graph with all labels having
value "0". Also remove bogus "multigraph redis" line.

TODO: die() in get_conn() makes this plugin to fail if any Redis
instance can't be connected.
This commit is contained in:
Kim B. Heino 2021-04-27 11:33:34 +03:00 committed by Lars Kruse
parent 51af0be02b
commit b392cacc4b
1 changed files with 9 additions and 5 deletions

View File

@ -95,23 +95,27 @@ for (my $i = 1; $ENV{"host$i"}; $i++)
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" );
my $autoconf = ( defined $ARGV[0] and $ARGV[0] eq "autoconf" );
if ( $autoconf ) {
if (!%INSTANCES) {
print "no (no redis instances configured)\n";
exit 0;
}
my $err = '';
for my $INSTANCE (keys %INSTANCES) {
if (! defined( $INSTANCES{$INSTANCE}{'SOCK'} ) ) {
$err .= "no (unable to connect to ".$INSTANCES{$INSTANCE}{'HOST'}."\[:". $INSTANCES{$INSTANCE}{'PORT'}."\])\n";
$err = "no (unable to connect to ".$INSTANCES{$INSTANCE}{'HOST'}."\[:". $INSTANCES{$INSTANCE}{'PORT'}."\])\n";
}
}
if ($err) {
print $err;
} else {
print 'yes';
print "yes\n";
}
exit 0;
}
my $total = 0;
my $multi_graph_output = "multigraph redis\n";
my $multi_graph_output = '';
my $instance_graph_output = '';
my $connected_clients = 0;