Skip to content

Commit

Permalink
reduce required queries when using lmd
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 14, 2024
1 parent 31c064b commit 6db8cfc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ next:
- add support for base64 encoded obfuscate pattern
- reworked status page column editor
- improve performance when having custom column layout on status pages
- reduce required queries when using lmd
- Rest:
- add support for host/service note commands
ex.: /hosts/<name>/cmd/note
Expand Down
5 changes: 5 additions & 0 deletions lib/Thruk/Action/AddDefaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ sub add_defaults {

###############################
$c->stash->{'has_lmd'} = $c->config->{'use_lmd_core'} ? 1 : 0;
if($c->stash->{'has_lmd'}) {
## no critic
$ENV{'THRUK_LMD_VERSION'} = Thruk::Utils::LMD::get_lmd_version($c->config) unless $ENV{'THRUK_LMD_VERSION'};
## use critic
}
$c->stash->{'has_expire_acks'} = $c->config->{'has_expire_acks'} // 1;
$c->stash->{'require_comments_for_disable_cmds'} = $c->config->{'require_comments_for_disable_cmds'} || 0;

Expand Down
21 changes: 18 additions & 3 deletions lib/Thruk/Utils/Status.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1729,13 +1729,28 @@ sub get_comments_filter {
return(\@hostfilter, \@servicefilter) unless Thruk::Utils::is_valid_regular_expression( $c, $value );

my $num;
if($value eq '') {

# LMD can simple search comments and downtimes, no need for a subquery (since version 2.2.2)
if($ENV{'THRUK_USE_LMD'} && Thruk::Utils::version_compare($ENV{'THRUK_LMD_VERSION'}, '2.2.2')) {
if($op eq '=' or $op eq '~~') {
push @hostfilter, { -or => [ comments_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]};
push @servicefilter, { -or => [ host_comments_with_info => { $op => $value }, comments_with_info => { $op => $value },
host_downtimes_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]};
} else {
push @hostfilter, { -and => [ comments_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]};
push @servicefilter, { -and => [ host_comments_with_info => { $op => $value }, comments_with_info => { $op => $value },
host_downtimes_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]};
}
}
elsif($value eq '') {
if($op eq '=' or $op eq '~~') {
push @hostfilter, { -and => [ comments => { $op => undef }, downtimes => { $op => undef } ]};
push @servicefilter, { -and => [ comments => { $op => undef }, downtimes => { $op => undef } ]};
push @servicefilter, { -and => [ host_comments => { $op => undef }, comments => { $op => undef },
host_downtimes => { $op => undef }, downtimes => { $op => undef } ]};
} else {
push @hostfilter, { -or => [ comments => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]};
push @servicefilter, { -or => [ comments => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]};
push @servicefilter, { -or => [ host_comments => { $op => { '!=' => undef }}, comments => { $op => { '!=' => undef }},
host_downtimes => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]};
}
}
else {
Expand Down

0 comments on commit 6db8cfc

Please sign in to comment.