fix(packaging): various issues + migration to JSON config file (#5291)

- fixed missing dependency on AlmaLinux
- take into account /etc/(default|sysconfig)/centreon_vmware as EnvironmentFile, that was ignored by the systemd service
- migrate the config file from .pm to .json at update time

Refs: CTOR-1079
This commit is contained in:
omercier 2024-11-28 14:02:22 +01:00 committed by GitHub
parent d73866af31
commit 1f9e3b4340
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 72 additions and 22 deletions

View File

@ -1,3 +1,11 @@
2024-12-05 Olivier Mercier <omercier@centreon.com> - 3.4.0
* Enhancement: systemd service now takes its options from
/etc/(default|sysconfig)/centreon_vmware.
* Enhancement: the existing .pm config file is converted into a .json file
during upgrade.
* Breaking: the default config file is now the JSON one.
* Fix: added the 'perl(Text::Template)' missing dependency for AlmaLinux.
2024-10-18 Olivier Mercier <omercier@centreon.com> - 3.3.2
* Fix: regression of case sensitiveness for container names fixed
* Enhancement: log messages related to the vault have been downgraded from error to info level or explained as safe to ignore if not using the vault

View File

@ -69,18 +69,16 @@ contents:
- src: "redhat/centreon_vmware-sysconfig"
dst: "/etc/sysconfig/centreon_vmware"
type: config|noreplace
packager: rpm
- src: "debian/centreon_vmware-default"
dst: "/etc/default/centreon_vmware"
type: config|noreplace
packager: deb
- src: "config/centreon_vmware-conf.pm"
dst: "/etc/centreon/centreon_vmware.pm"
- src: "config/centreon_vmware-conf.json"
dst: "/etc/centreon/centreon_vmware.json"
type: config|noreplace
packager: rpm
- src: "config/centreon_vmware-conf.pm"
dst: "/etc/centreon/centreon_vmware.pm.new"
packager: deb
scripts:
postinstall: ./scripts/postinstall.sh
@ -92,6 +90,7 @@ overrides:
- perl(IO::Socket::INET6)
- perl(JSON::XS)
- perl(LWP::Protocol::https)
- perl(Text::Template)
- perl(ZMQ::Constants)
- perl(ZMQ::LibZMQ4)
- perl-Net-Curl

View File

@ -1,2 +1,2 @@
# centreon_vmware command line options
OPTIONS="--logfile=/var/log/centreon_vmware.log --severity=error"
OPTIONS="--config-extra=/etc/centreon/centreon_vmware.json --logfile=/var/log/centreon/centreon_vmware.log --severity=info"

View File

@ -19,7 +19,8 @@
Description=Centreon VMWare
[Service]
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl --logfile=/var/log/centreon/centreon_vmware.log --severity=error
EnvironmentFile=-/etc/default/centreon_vmware
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl $OPTIONS
Type=simple
User=centreon

View File

@ -1,2 +1,2 @@
# centreon_vmware command line options
OPTIONS="--logfile=/var/log/centreon/centreon_vmware.log --severity=error"
OPTIONS="--config-extra=/etc/centreon/centreon_vmware.json --logfile=/var/log/centreon/centreon_vmware.log --severity=info"

View File

@ -19,7 +19,8 @@
Description=Centreon VMWare
[Service]
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl --logfile=/var/log/centreon/centreon_vmware.log --severity=error
EnvironmentFile=-/etc/sysconfig/centreon_vmware
ExecStart=/usr/bin/perl /usr/bin/centreon_vmware.pl $OPTIONS
Type=simple
User=centreon

View File

@ -1,7 +1,49 @@
#!/bin/sh
#!/bin/bash
if [ "$1" = "configure" ]; then # deb
if [ ! -f "/etc/centreon/centreon_vmware.pm" ]; then
mv /etc/centreon/centreon_vmware.pm.new /etc/centreon/centreon_vmware.pm
fi
json_config_file_path='/etc/centreon/centreon_vmware.json'
perl_config_file_path='/etc/centreon/centreon_vmware.pm'
function migrateConfigFromPmToJson() {
# If the legacy config file exists, we migrate it into a JSON config file
if [[ -f "$perl_config_file_path" ]] ; then
/usr/bin/centreon_vmware_convert_config_file "$perl_config_file_path" > "$json_config_file_path"
mv "$perl_config_file_path" "${perl_config_file_path}.deprecated"
fi
chown centreon: "$json_config_file_path"
chmod 640 "$json_config_file_path"
}
function applyToSystemD() {
systemctl daemon-reload
systemctl restart centreon_vmware.service
}
action="$1"
version="$2"
if [[ "$1" == "configure" ]]; then # deb
if [[ -z "$version" ]]; then
# Alpine linux does not pass args, and deb passes $1=configure
action="install"
elif [[ -n "$version" ]]; then
# deb passes $1=configure $2=<current version>
action="upgrade"
fi
fi
case "$action" in
"1" | "install")
migrateConfigFromPmToJson
applyToSystemD
;;
"2" | "upgrade")
migrateConfigFromPmToJson
applyToSystemD
;;
*)
# $1 == version being installed
applyToSystemD
;;
esac

View File

@ -54,7 +54,7 @@ BEGIN {
use base qw(centreon::vmware::script);
my $VERSION = '3.3.2';
my $VERSION = '3.4.0';
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
my @load_modules = (

View File

@ -19,7 +19,7 @@
use strict;
use warnings FATAL => 'all';
use JSON::XS;
use JSON;
use Data::Dumper;
die "Usage: centreon_vmware_convert_config_file /etc/centreon/centreon_vmware.pm > /etc/centreon/centreon_vmware.json" if (scalar(@ARGV) < 1);
@ -34,7 +34,6 @@ my $new_config_structure = {
vsphere_server => []
};
for my $config_entry_key (keys %centreon_vmware_config){
if ($config_entry_key eq 'vsphere_server') {
for my $server_config_entry_key (keys %{$centreon_vmware_config{vsphere_server}}) {
@ -45,11 +44,11 @@ for my $config_entry_key (keys %centreon_vmware_config){
} else {
$new_config_structure->{$config_entry_key} = $centreon_vmware_config{$config_entry_key};
}
}
my $new_json_config = encode_json($new_config_structure) or die "Unable to convert this object to JSON:\n" . Dumper($new_config_structure);
my $new_json_config = JSON->new->utf8(1)->pretty(1)->encode($new_config_structure) or die "Unable to convert this object to JSON:\n" . Dumper($new_config_structure);
print($new_json_config);
exit(0);

View File

@ -45,7 +45,7 @@ sub init_response {
my (%options) = @_;
$manager_response->{code} = 0;
$manager_response->{vmware_connector_version} = '3.3.2';
$manager_response->{vmware_connector_version} = '3.4.0';
$manager_response->{short_message} = 'OK';
$manager_response->{extra_message} = '';
$manager_response->{identity} = $options{identity} if (defined($options{identity}));