Skip to content

Commit aca932e

Browse files
committed
check_thruk_rest: no need to initialize livestatus for static checks
1 parent 2dc8430 commit aca932e

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/Thruk/Utils/CLI/Rest.pm

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ The rest command is a cli interface to the rest api.
1313
Usage:
1414
1515
- simple query:
16-
thruk [globaloptions] rest [-m method] [-d postdata] <url>
16+
thruk [global options] rest [-m method] [-d postdata] <url>
1717
1818
- multiple queries_:
19-
thruk [globaloptions] rest [-m method] [-d postdata] <url> [-m method] [-d postdata] <url>
19+
thruk [global options] rest [-m method] [-d postdata] <url> [-m method] [-d postdata] <url>
2020
2121
=cut
2222

@@ -98,7 +98,13 @@ sub _fetch_results {
9898
if($ENV{'THRUK_CLI_SRC'} && $ENV{'THRUK_CLI_SRC'}) {
9999
# text data
100100
if($opt->{'string'}) {
101-
$opt->{'result'} = Cpanel::JSON::XS->new->pretty->encode({ text => $url });
101+
$opt->{'result'} = Cpanel::JSON::XS->new->pretty->encode({
102+
text => $url,
103+
output => $url,
104+
stdout => $url,
105+
stderr => '',
106+
rc => 0,
107+
});
102108
$opt->{'rc'} = 0;
103109
_debug("text data from command line argument:");
104110
_debug($opt->{'result'});
@@ -111,6 +117,7 @@ sub _fetch_results {
111117
chomp($stdout) if defined $stdout;
112118
chomp($stderr) if defined $stderr;
113119
$opt->{'result'} = Cpanel::JSON::XS->new->pretty->encode({
120+
text => $output,
114121
output => $output,
115122
rc => $rc,
116123
stdout => $stdout // '',
@@ -757,15 +764,20 @@ sub _get_value_ref_check {
757764
# determines if command requires backends or not
758765
sub _skip_backends {
759766
my($c, $opts, $src) = @_;
760-
Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_SAFE_DEFAULTS) unless $c->stash->{'processinfo_time'};
761-
return unless $opts->{'commandoptions'};
767+
if(!$opts->{'commandoptions'}) {
768+
# no idea what command this is, use safe defaults
769+
Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_SAFE_DEFAULTS) unless $c->stash->{'processinfo_time'};
770+
return;
771+
}
762772
my $cmds = _parse_args($opts->{'commandoptions'}, $src);
763773
$opts->{'_parsed_args'} = $cmds;
764774
for my $cmd (@{$cmds}) {
765-
if(!$cmd->{'url'} || $cmd->{'url'} !~ m/^https?:\/\//mx) {
775+
if(!$cmd->{'url'} || ($cmd->{'url'} !~ m/^https?:\/\//mx && !$cmd->{'string'} && !$cmd->{'command'})) {
776+
Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_SAFE_DEFAULTS) unless $c->stash->{'processinfo_time'};
766777
return;
767778
}
768779
}
780+
Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_USER_ONLY) unless $c->stash->{'processinfo_time'};
769781
return(1);
770782
}
771783

0 commit comments

Comments
 (0)