Skip to content

Commit

Permalink
fix printing thruk version
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Feb 12, 2025
1 parent 8242ab3 commit 38ab0bc
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 42 deletions.
18 changes: 0 additions & 18 deletions lib/Thruk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -537,24 +537,6 @@ sub cache {
return;
}

##############################################

=head2 get_thruk_version
get_thruk_version()
return full thruk version string, ex.: 2.40.2+10~feature_branch~45a4ceb
=cut

sub get_thruk_version {
my $git_info = Thruk::Config::get_git_info(Thruk::Config::home());
if($git_info) {
return($Thruk::Config::VERSION.$git_info);
}
return($Thruk::Config::VERSION);
}

###################################################
# mod_fcgid sends a SIGTERM on timeouts, so try to determine if this is a normal
# exit or not and print the stacktrace if not.
Expand Down
24 changes: 21 additions & 3 deletions lib/Thruk/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ sub get_default_stash {
'user_profiling' => 0,
'real_page' => '',
'make_test_mode' => Thruk::Base->mode eq 'TEST' ? 1 : 0,
'thrukversion' => \&Thruk::get_thruk_version,
'thrukversion' => \&Thruk::Config::get_thruk_version,
'fileversion' => $VERSION,
'starttime' => time(),
'omd_site' => $ENV{'OMD_SITE'} || '',
Expand Down Expand Up @@ -790,8 +790,8 @@ return base config
=cut
sub get_base_config {
if(!defined $base_defaults->{'thrukversion'}) {
$base_defaults->{'thrukversion'} = \&Thruk::get_thruk_version;
$config->{'thrukversion'} = \&Thruk::get_thruk_version if $config;
$base_defaults->{'thrukversion'} = \&Thruk::Config::get_thruk_version;
$config->{'thrukversion'} = \&Thruk::Config::get_thruk_version if $config;
}
if(!defined $base_defaults->{'hostname'}) {
$base_defaults->{'hostname'} = &hostname();
Expand Down Expand Up @@ -867,6 +867,24 @@ sub get_toolkit_config {

##############################################

=head2 get_thruk_version
get_thruk_version()
return full thruk version string, ex.: 2.40.2+10~feature_branch~45a4ceb
=cut

sub get_thruk_version {
my $git_info = &get_git_info(Thruk::Config::home());
if($git_info) {
return($VERSION.$git_info);
}
return($VERSION);
}

##############################################

=head2 get_git_info
get_git_info()
Expand Down
2 changes: 1 addition & 1 deletion lib/Thruk/Controller/remote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sub index {
return;
}
if(ref $res eq 'HASH') {
$res->{'version'} = Thruk::get_thruk_version() unless defined $res->{'version'};
$res->{'version'} = Thruk::Config::get_thruk_version() unless defined $res->{'version'};
}
return $c->render(json => $res);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Thruk/Controller/rest_v1.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ sub _rest_get_thruk {
my($c) = @_;
return({
rest_version => $VERSION, # rest api version
thruk_version => Thruk::get_thruk_version(), # thruk version
thruk_version => Thruk::Config::get_thruk_version(), # thruk version
thruk_release_date => $c->config->{'released'}, # thruk release date
localtime => Time::HiRes::time(), # current server unix timestamp / epoch
project_root => $c->config->{'project_root'}, # thruk root folder
Expand Down Expand Up @@ -2148,7 +2148,7 @@ sub _rest_get_sites {
federation_name => $peer->{'fed_info'}->{'name'} || [ $peer->{'name'} ],
federation_addr => $peer->{'fed_info'}->{'addr'} || [ $peer->{'addr'} ],
federation_type => $peer->{'fed_info'}->{'type'} || [ $peer->{'type'} ],
federation_version => $peer->{'fed_info'}->{'version'} || [ $peer->{'version'} // Thruk::get_thruk_version() ],
federation_version => $peer->{'fed_info'}->{'version'} || [ $peer->{'version'} // Thruk::Config::get_thruk_version() ],
localtime => $time,
};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Thruk/Utils/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,12 @@ sub _cmd_raw {
# inject/add proxy version and config tool settings to processinfo result
if($function eq 'get_processinfo' and defined $res and ref $res eq 'ARRAY' and defined $res->[2] and ref $res->[2] eq 'HASH') {
$res->[2]->{$key}->{'thruk'} = {
'thruk_version' => Thruk::get_thruk_version(),
'thruk_version' => Thruk::Config::get_thruk_version(),
'extra_version' => $c->config->{'extra_version'},
'data_source_version' => $res->[2]->{$key}->{'data_source_version'},
};
$res->[2]->{$key}->{'localtime'} = Time::HiRes::time();
$res->[2]->{$key}->{'data_source_version'} .= ' (via Thruk '.Thruk::get_thruk_version().')';
$res->[2]->{$key}->{'data_source_version'} .= ' (via Thruk '.Thruk::Config::get_thruk_version().')';

# add config tool settings (will be read from Thruk::Backend::Manager::_do_on_peers)
my $peer = $c->db->get_peer_by_key($key);
Expand Down
3 changes: 2 additions & 1 deletion lib/Thruk/Utils/CLI/Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Show information about a Thruk cluster
use warnings;
use strict;

use Thruk::Config 'noautoload';
use Thruk::Utils::CLI ();

our $skip_backends = 1;
Expand Down Expand Up @@ -85,7 +86,7 @@ sub cmd {
}
elsif($c->cluster->is_it_me($n)) {
$status = 'OK';
$n->{'version'} = Thruk::get_thruk_version();
$n->{'version'} = Thruk::Config::get_thruk_version();
$ok++;
}
elsif($n->{'last_contact'} <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Thruk/Utils/Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ sub pong {
time => time(),
node_id => $Thruk::Globals::NODE_ID,
hostname => $Thruk::Globals::HOSTNAME,
version => Thruk::get_thruk_version(),
version => Thruk::Config::get_thruk_version(),
maintenance => $c->cluster->{'node'}->{'maintenance'},
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Thruk/Utils/Filter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ returns full version string
sub fullversion {
my($c) = @_;
die("no c") unless defined $c;
my $str = Thruk::get_thruk_version() // '';
my $str = Thruk::Config::get_thruk_version() // '';
if($c->config->{'extra_version'}) {
$str .= '/ '.$c->config->{'extra_version'};
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugins-available/conf/lib/Thruk/Utils/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ sub store_model_retention {
my $data = {
'configs' => {$backend => $model->{'configs'}->{$backend}},
'release_date' => $c->config->{'released'},
'version' => Thruk::get_thruk_version(),
'version' => Thruk::Config::get_thruk_version(),
};
store($data, $file);
$c->config->{'conf_retention'} = [stat($file)];
Expand Down Expand Up @@ -751,7 +751,7 @@ sub get_model_retention {
if(defined $data->{'release_date'}
and $data->{'release_date'} eq $c->config->{'released'}
and defined $data->{'version'}
and $data->{'version'} eq Thruk::get_thruk_version()
and $data->{'version'} eq Thruk::Config::get_thruk_version()
) {
my $model_configs = $data->{'configs'};
for my $backend (keys %{$model_configs}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Thruk Controller.
sub index {
my($c) = @_;

return unless Thruk::Action::AddDefaults::add_defaults($c, Thruk::ADD_CACHED_DEFAULTS);
return unless Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_CACHED_DEFAULTS);

$c->stash->{'hide_backends_chooser'} = 1;
$c->stash->{no_auto_reload} = 1;
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugins-available/omd/lib/Thruk/Controller/omd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ my $pluginname = Thruk::Utils::get_plugin_name(__FILE__, __PACKAGE__);
sub index {
my($c) = @_;

return unless Thruk::Action::AddDefaults::add_defaults($c, Thruk::ADD_SAFE_DEFAULTS);
return unless Thruk::Action::AddDefaults::add_defaults($c, Thruk::Constants::ADD_SAFE_DEFAULTS);

$c->stash->{title} = 'Top Statistics';
$c->stash->{page} = 'status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3678,7 +3678,7 @@ sub _add_misc_details {
$c->stats->profile(begin => "_add_misc_details");
_add_json_dashboard_timestamps($c, $json, $c->req->parameters->{'current_tab'});
_add_json_pi_detail($c, $json);
$json->{'server_version'} = Thruk::get_thruk_version();
$json->{'server_version'} = Thruk::Config::get_thruk_version();
$json->{'server_extra_version'} = $c->config->{'extra_version'};
$json->{'broadcasts'} = Thruk::Utils::Broadcast::get_broadcasts($c, undef, undef, 1);
$c->stats->profile(end => "_add_misc_details");
Expand Down
2 changes: 1 addition & 1 deletion script/check_thruk_rest
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if($options->{'help'} || scalar @{$options->{'commandoptions'}} == 1) {
exit(3);
}
if($options->{'version'}) {
print "check_thruk_rest v", Thruk::get_thruk_version(), "\n"; exit 0;
print "check_thruk_rest v", Thruk::Config::get_thruk_version(), "\n"; exit 0;
}

require Thruk::Utils::CLI;
Expand Down
2 changes: 1 addition & 1 deletion script/nagexp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ sub new {
##############################################
sub run {
my($self) = @_;
my $vers = Thruk::get_thruk_version();
my $vers = Thruk::Config::get_thruk_version();
my $host = `hostname`;
my $args = $0.' '.join(' ', @ARGV);
chomp($host);
Expand Down
2 changes: 1 addition & 1 deletion script/nagimp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ sub run {
) or
pod2usage( { -verbose => 2, -message => 'error in options' } );

if($self->{'opt'}->{'version'}) { print "nagimp v",Thruk::get_thruk_version()),"\n"; exit 0; }
if($self->{'opt'}->{'version'}) { print "nagimp v",Thruk::Config::get_thruk_version()),"\n"; exit 0; }
pod2usage( { -verbose => 2, -exit => 3 } ) if $self->{'opt'}->{'help'};
pod2usage( { -verbose => 2, -exit => 3, -message => "ERROR: missing export file\n" } ) if scalar @{$self->{'opt'}->{'files'}} == 0;
pod2usage( { -verbose => 2, -exit => 3, -message => "ERROR: too many export files\n" } ) if scalar @{$self->{'opt'}->{'files'}} > 1;
Expand Down
2 changes: 1 addition & 1 deletion script/naglint
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ sub run {
"<>" => sub { push @{$self->{'opt'}->{'files'}}, $_[0] },
) or _usage('error in options');

if($self->{'opt'}->{'version'}) { print "naglint v",Thruk::get_thruk_version(),"\n"; exit 0; }
if($self->{'opt'}->{'version'}) { print "naglint v",Thruk::Config::get_thruk_version(),"\n"; exit 0; }
pod2usage( { -verbose => 2, -exit => 3 } ) if $self->{'opt'}->{'help'};

# do we have a rc file?
Expand Down
2 changes: 1 addition & 1 deletion script/thruk
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ if($options->{'help'}) {
if($options->{'version'}) {
require Thruk::Config;
printf("thruk v%s%s\n",
Thruk::get_thruk_version(),
Thruk::Config::get_thruk_version(),
($Thruk::Config::GIT_HASH ? " (".$Thruk::Config::GIT_HASH.")" : ""),
);
exit 0;
Expand Down
1 change: 0 additions & 1 deletion script/thruk_format_perl_modules
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ sub _check_missing {
for my $b (values %{$blocks}) {
for my $f (@{$b->{'missing'}}) {
my($m, $line) = @{$f};
next if $m eq 'Thruk';
next if $m eq $b->{'package'}.'::Defaults';
my $found = 0;
for my $b (values %{$blocks}) {
Expand Down
2 changes: 1 addition & 1 deletion t/001-app.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ok($request->headers('content-length'), "static content request has content-leng

use_ok("Thruk::Config");

diag(sprintf("Thruk: %s - Perl: %s - Arch: %s", Thruk::get_thruk_version(), $^V, $Config{'archname'}));
diag(sprintf("Thruk: %s - Perl: %s - Arch: %s", Thruk::Config::get_thruk_version(), $^V, $Config{'archname'}));
2 changes: 1 addition & 1 deletion t/002-config.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use_ok("Thruk::Action::AddDefaults");

my $config = Thruk::Config::set_config_env();
is(ref Thruk->config, 'HASH', "got a config");
ok(defined Thruk::get_thruk_version(), "got a version");
ok(defined Thruk::Config::get_thruk_version(), "got a version");

chomp(my $makefile_version = `grep "^VERSION\ *=" Makefile | head -n 1 | awk '{ print \$3 }'`);
is($makefile_version, $Thruk::Config::VERSION, "Makefile shows Thruk::Config::VERSION: ".$Thruk::Config::VERSION);
Expand Down

0 comments on commit 38ab0bc

Please sign in to comment.