change: logic in upgrade handling
This commit is contained in:
@@ -227,17 +227,60 @@ class ZabbixAgentTool:
|
||||
|
||||
def _upgrade_zabbix_package(self):
|
||||
"""Upgrade Zabbix agent package based on distribution family"""
|
||||
commands = {
|
||||
'debian': ["sudo apt update", "sudo apt upgrade -y zabbix-agent*"],
|
||||
'rhel': ["sudo yum update -y zabbix-agent* || sudo dnf update -y zabbix-agent*"]
|
||||
}
|
||||
|
||||
if self.distro_family not in commands:
|
||||
raise Exception(f"Unsupported distribution family: {self.distro_family}")
|
||||
|
||||
logger.info(f"Upgrading Zabbix agent on {self.distro_family}-based system")
|
||||
for cmd in commands[self.distro_family]:
|
||||
self._run_command(cmd)
|
||||
|
||||
if self.distro_family == 'debian':
|
||||
# Update package lists
|
||||
self._run_command("sudo apt update")
|
||||
|
||||
# Check what zabbix packages are installed first
|
||||
result = self._run_command("dpkg -l | grep -E 'zabbix-agent'", check=False, log_output=True)
|
||||
if result.returncode != 0:
|
||||
logger.warning("No Zabbix agent packages found installed")
|
||||
return
|
||||
|
||||
# Get list of installed zabbix agent packages
|
||||
installed_packages = []
|
||||
if result.stdout:
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
if 'zabbix-agent' in line:
|
||||
# Extract package name from dpkg output
|
||||
parts = line.split()
|
||||
if len(parts) >= 2:
|
||||
package_name = parts[1]
|
||||
installed_packages.append(package_name)
|
||||
|
||||
if not installed_packages:
|
||||
logger.warning("No Zabbix agent packages found to upgrade")
|
||||
return
|
||||
|
||||
# Upgrade each installed package individually
|
||||
for package in installed_packages:
|
||||
try:
|
||||
logger.info(f"Upgrading {package}")
|
||||
# Use DEBIAN_FRONTEND=noninteractive to avoid prompts
|
||||
self._run_command(f"sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y {package}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not upgrade {package}: {e}")
|
||||
|
||||
elif self.distro_family == 'rhel':
|
||||
# For RHEL-based systems
|
||||
try:
|
||||
# Try yum first
|
||||
result = self._run_command("yum list installed | grep zabbix-agent", check=False)
|
||||
if result.returncode == 0:
|
||||
self._run_command("sudo yum update -y zabbix-agent*")
|
||||
else:
|
||||
# Try dnf
|
||||
result = self._run_command("dnf list installed | grep zabbix-agent", check=False)
|
||||
if result.returncode == 0:
|
||||
self._run_command("sudo dnf update -y zabbix-agent*")
|
||||
else:
|
||||
logger.warning("No Zabbix agent packages found to upgrade")
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not upgrade packages: {e}")
|
||||
else:
|
||||
raise Exception(f"Unsupported distribution family: {self.distro_family}")
|
||||
|
||||
def _merge_custom_settings(self, new_config_file, custom_settings, backup_path):
|
||||
"""Merge custom settings into new configuration file"""
|
||||
|
||||
Reference in New Issue
Block a user