View | Details | Raw Unified | Return to bug 37509
Collapse All | Expand All

(-)a/about.pl (-78 / +80 lines)
Lines 179-184 if ( $tab eq 'about' ) { Link Here
179
    }
179
    }
180
180
181
    message_broker_check($template);
181
    message_broker_check($template);
182
    elasticsearch_check($template);
182
183
183
    $template->param(
184
    $template->param(
184
        effective_caching_method => $effective_caching_method,
185
        effective_caching_method => $effective_caching_method,
Lines 400-482 if($tab eq 'sysinfo') { Link Here
400
        $template->param( warnXSLT => \@warnXSLT ) if @warnXSLT;
401
        $template->param( warnXSLT => \@warnXSLT ) if @warnXSLT;
401
    }
402
    }
402
403
403
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
404
    elasticsearch_check( $template );
404
        # Check ES configuration health and runtime status
405
406
        my $es_status;
407
        my $es_config_error;
408
        my $es_running = 1;
409
        my $es_has_missing = 0;
410
411
        my $es_conf;
412
        try {
413
            $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
414
        }
415
        catch {
416
            if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
417
                $template->param( elasticsearch_fatal_config_error => $_->message );
418
                $es_config_error = 1;
419
            }
420
        };
421
        if ( !$es_config_error ) {
422
423
            my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
424
            my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
425
426
            my @indexes = ($biblios_index_name, $authorities_index_name);
427
            # TODO: When new indexes get added, we could have other ways to
428
            #       fetch the list of available indexes (e.g. plugins, etc)
429
            $es_status->{nodes} = $es_conf->{nodes};
430
            my $es = Search::Elasticsearch->new( $es_conf );
431
            my $es_status->{version} = $es->info->{version}->{number};
432
433
            foreach my $index ( @indexes ) {
434
                my $index_count;
435
                try {
436
                    $index_count = $es->indices->stats( index => $index )
437
                        ->{_all}{primaries}{docs}{count};
438
                }
439
                catch {
440
                    if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
441
                        push @{ $es_status->{errors} }, "Index not found ($index)";
442
                        $index_count = -1;
443
                    }
444
                    elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
445
                        $es_running = 0;
446
                    }
447
                    else {
448
                        # TODO: when time comes, we will cover more use cases
449
                        die $_;
450
                    }
451
                };
452
453
                my $db_count = -1;
454
                my $missing_count = 0;
455
                if ( $index eq $biblios_index_name ) {
456
                    $db_count = Koha::Biblios->search->count;
457
                } elsif ( $index eq $authorities_index_name ) {
458
                    $db_count = Koha::Authorities->search->count;
459
                }
460
                if ( $db_count != -1 && $index_count != -1 ) {
461
                    $missing_count = $db_count - $index_count;
462
                    $es_has_missing = 1 if $missing_count > 0;
463
                }
464
                push @{ $es_status->{indexes} },
465
                {
466
                    index_name    => $index,
467
                    index_count   => $index_count,
468
                    db_count      => $db_count,
469
                    missing_count => $missing_count,
470
                };
471
            }
472
            $es_status->{running} = $es_running;
473
474
            $template->param(
475
                elasticsearch_status      => $es_status,
476
                elasticsearch_has_missing => $es_has_missing,
477
            );
478
        }
479
    }
480
405
481
    if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
406
    if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
482
        # Do we have the required deps?
407
        # Do we have the required deps?
Lines 899-904 if ( $tab eq 'history' ) { Link Here
899
    }
824
    }
900
}
825
}
901
826
827
sub elasticsearch_check {
828
    my $template = shift;
829
830
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
831
832
        my $es_status;
833
        my $es_config_error;
834
        my $es_running     = 1;
835
        my $es_has_missing = 0;
836
837
        my $es_conf;
838
        try {
839
            $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
840
        } catch {
841
            if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
842
                $template->param( elasticsearch_fatal_config_error => $_->message );
843
                $es_config_error = 1;
844
            }
845
        };
846
        if ( !$es_config_error ) {
847
848
            my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
849
            my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
850
851
            my @indexes = ( $biblios_index_name, $authorities_index_name );
852
853
            # TODO: When new indexes get added, we could have other ways to
854
            #       fetch the list of available indexes (e.g. plugins, etc)
855
            $es_status->{nodes} = $es_conf->{nodes};
856
            my $es = Search::Elasticsearch->new($es_conf);
857
            my $es_status->{version} = $es->info->{version}->{number};
858
859
            foreach my $index (@indexes) {
860
                my $index_count;
861
                try {
862
                    $index_count = $es->indices->stats( index => $index )->{_all}{primaries}{docs}{count};
863
                } catch {
864
                    if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
865
                        push @{ $es_status->{errors} }, "Index not found ($index)";
866
                        $index_count = -1;
867
                    } elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
868
                        $es_running = 0;
869
                    } else {
870
871
                        # TODO: when time comes, we will cover more use cases
872
                        die $_;
873
                    }
874
                };
875
876
                my $db_count      = -1;
877
                my $missing_count = 0;
878
                if ( $index eq $biblios_index_name ) {
879
                    $db_count = Koha::Biblios->search->count;
880
                } elsif ( $index eq $authorities_index_name ) {
881
                    $db_count = Koha::Authorities->search->count;
882
                }
883
                if ( $db_count != -1 && $index_count != -1 ) {
884
                    $missing_count  = $db_count - $index_count;
885
                    $es_has_missing = 1 if $missing_count > 0;
886
                }
887
                push @{ $es_status->{indexes} },
888
                    {
889
                    index_name    => $index,
890
                    index_count   => $index_count,
891
                    db_count      => $db_count,
892
                    missing_count => $missing_count,
893
                    };
894
            }
895
            $es_status->{running} = $es_running;
896
897
            $template->param(
898
                elasticsearch_status      => $es_status,
899
                elasticsearch_has_missing => $es_has_missing,
900
            );
901
        }
902
    }
903
}
904
902
sub message_broker_check {
905
sub message_broker_check {
903
    my $template = shift;
906
    my $template = shift;
904
    {
907
    {
905
- 

Return to bug 37509