1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/zabbix_ynh.git synced 2024-09-03 20:36:14 +02:00

Revert "Delete ynh_add_extra_apt_repos__3"

This reverts commit 99d93bbc7a00c433d3f088176f347b15ae1e9431
This commit is contained in:
Mickael-Martin 2020-04-26 14:45:45 +02:00
parent 691a07f48a
commit 2285ee09b1
12 changed files with 165 additions and 52 deletions

View file

@ -18,7 +18,7 @@ location __PATH__/ {
try_files $uri $uri/ index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
fastcgi_pass unix:/var/run/php/php7.0-fpm-__NAME__.sock;
fastcgi_index index.php;
include fastcgi_params;

View file

@ -18,5 +18,5 @@ catch_workers_output = yes
php_value[post_max_size] = 16M
php_value[max_execution_time] = 300
php_value[max_input_time] = 300
php_value[open_basedir] = /var/www/zabbix/:/usr/share/fonts/:/tmp
php_value[open_basedir] = /var/www/zabbix/:/usr/share/fonts/:/tmp:/etc/zabbix/web
php_value[date.timezone] = Europe/Paris

View file

@ -6,7 +6,7 @@
"en": "A monitoring tool for diverse IT components, including networks, servers, VMs and cloud services.",
"fr": "Un outil pour monitorer des réseaux, des serveurs, des VMs et autres services en ligne"
},
"version": "3.1",
"version": "3.2",
"url": "https://www.zabbix.com",
"license": "free",
"maintainer": {

View file

@ -178,4 +178,33 @@ remove_zabbix_repo(){
ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ /etc/yunohost/apps/zabbix/ -name "ynh_add_extra_apt_repos__3" | tail -n 1)
source "$ynh_add_extra_apt_repos__3_path"
ynh_remove_extra_repo --name=zabbix
}
update_initZabbixConf(){
if [ ! -d /etc/zabbix/web ] ;then mkdir -p /etc/zabbix/web ;fi
cp $(find /var/cache/yunohost/ -name "etc_zabbix_web_init.zabbix.conf.php.sh") /etc/zabbix/web/init.zabbix.conf.php.sh
chmod 700 /etc/zabbix/web/init.zabbix.conf.php.sh
cp $(find /var/cache/yunohost/ -name "etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config") /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config
}
delete_initZabbixConf(){
if [ -f /etc/zabbix/web/init.zabbix.conf.php.sh ] ; then ynh_secure_remove /etc/zabbix/web/init.zabbix.conf.php.sh;fi
if [ -f /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ] ;then ynh_secure_remove /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ;fi
}
#Patch timeout too short for zabbix agent if needed
change_timeoutAgent(){
timeout_ok=$(grep "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null || true;)
if [ -z "$timeout_ok" ] ;then
ynh_replace_string --match_string="# Timeout=3" --replace_string="Timeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf
grep -C 2 "Timeout" /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
fi
}
convert_ZabbixDB(){
mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
for t in $(mysql -B -N --user=$db_user --password=$db_pwd --database=$db_name -e "show tables";)
do
mysql --user=$db_user --password=$db_pwd --database=$db_name -e "ALTER TABLE $t CONVERT TO character set utf8 collate utf8_bin;"
done
}

View file

@ -39,31 +39,42 @@ nonfree=$(ynh_app_setting_get $app nonfree)
#=================================================
#backup frontend config
ynh_print_info "Backup $final_path conf/zabbix.conf.php"
ynh_backup "$final_path/conf/zabbix.conf.php"
ynh_print_info "Backup /etc/zabbix/web"
ynh_backup "/etc/zabbix/web"
#ynh_print_info "Backup /etc/zabbix/web/init.zabbix.conf.php.sh"
#ynh_backup "/etc/zabbix/web/init.zabbix.conf.php.sh"
ynh_print_info "Backup /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
ynh_backup "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
#backup server confif
ynh_print_info "Backup /etc/zabbix/zabbix_server.conf"
ynh_backup "/etc/zabbix/zabbix_server.conf"
#backup agent config
ynh_print_info "Backup /etc/zabbix/zabbix_agentd.conf"
ynh_backup "/etc/zabbix/zabbix_agentd.conf"
ynh_print_info "Backup /etc/zabbix/zabbix_agentd.d"
ynh_backup "/etc/zabbix/zabbix_agentd.d"
#backup sudo file
ynh_print_info "Backup /etc/sudoers.d/zabbix"
ynh_backup "/etc/sudoers.d/zabbix"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_print_info "Backup /etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_print_info "Backup /etc/php/7.0/fpm/pool.d/$app.conf"
ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf"
#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info "Backup Zabbix database"
ynh_mysql_dump_db "$db_name" > db.sql

View file

@ -57,7 +57,7 @@ ynh_webpath_register "$app" "$domain" "$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_print_info "Get infos from manifest"
ynh_script_progression --message="Get infos from manifest" -w 1
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path "$path_url"
@ -95,14 +95,14 @@ ynh_app_setting_set "$app" language "$language"
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
ynh_print_info "Remove Zabbix if already installed"
apt purge zabbix* -y
ynh_script_progression --message="Remove Zabbix if already installed" -w 1
apt-get purge zabbix* -y
rm -fr /var/cache/apt/archives/zabbix-server-mysql*
ynh_print_info "Install Zabbix repository"
ynh_script_progression --message="Install Zabbix repository" -w 3
install_zabbix_repo
ynh_print_info "Update and install dependencies"
ynh_script_progression --message="Update and install dependencies" -w 5
#ynh_package_update no need cause ynh_install_app_dependencies after
ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php
dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql*
@ -116,7 +116,7 @@ rm "$final_path/conf/zabbix.conf.php"
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_print_info "Create and add default data in db"
ynh_script_progression --message="Creation of database " -w 10
### Use these lines if you need a database for the application.
### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password.
@ -133,11 +133,15 @@ db_user="$db_name"
ynh_app_setting_set "$app" db_name "$db_name"
ynh_app_setting_set "$app" db_user "$db_user"
ynh_mysql_setup_db "$db_user" "$db_name"
export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
ynh_script_progression --message="Import default data in database..." -w 25
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
convert_ZabbixDB
#sso integration
$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
@ -180,7 +184,7 @@ ynh_app_setting_set "$app" final_path "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
#ynh_setup_source "$final_path"
ynh_print_info "Generate web config"
ynh_script_progression --message="Generate web config" -w 5
#=================================================
# NGINX CONFIGURATION
@ -274,7 +278,9 @@ systemctl reload nginx
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
ynh_print_info "Generate zabbix config files"
ynh_script_progression -m "Generate zabbix config files" -w 5
confServerPath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php")
cp "$confServerPath" /usr/share/zabbix/conf/zabbix.conf.php
ynh_replace_string --match_string="db_name" --replace_string="$db_name" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
@ -287,10 +293,14 @@ ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_n
ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf
systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
change_timeoutAgent
systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
systemctl enable zabbix-agent && systemctl restart zabbix-agent
systemctl enable zabbix-server && systemctl restart zabbix-server
#=================================================
# INSTALL hook to verify if conf file is broken (after an update for example)
#=================================================
update_initZabbixConf
#=================================================
# STORE THE CONFIG FILE CHECKSUM
@ -365,11 +375,13 @@ yunohost app ssowatconf
#=================================================
# Import Yunohost template
#=================================================
ynh_script_progression -m "Importing last template Yunohost in Zabbix" -w 5
import_template
#=================================================
# Link Yunohost template to the ZAbbix Server Host
#=================================================
ynh_script_progression -m "Importing last template Yunohost in Zabbix" -w 5
link_template
#=================================================
@ -402,3 +414,9 @@ check_proc_zabbixagent
#test if zabbix agent is started
check_proc_zabbixserver
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -42,20 +42,23 @@ ynh_remove_fpm_config
#=================================================
timeout 5 systemctl stop zabbix-server || killall zabbix_server
systemctl disable zabbix-server
systemctl disable zabbix-server --quiet
killall zabbix_server
timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd
systemctl disable zabbix-agent
systemctl disable zabbix-agent --quiet
killall zabbix_agentd
DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y
#Remove config file detection
delete_initZabbixConf
DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
ynh_remove_app_dependencies
#force removing if ynh_remove_app_dependencies not work (old zabbix version)
for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
do
DEBIAN_FRONTEND=noninteractive apt purge --allow-change-held-packages "$zabbix_pkg" -y
DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
done
#=================================================
@ -97,20 +100,20 @@ fi
remove_zabbix_repo
#remove symlink
rm /var/www/zabbix
if [ -d /var/www/zabbix ] ;then ynh_secure_remove /var/www/zabbix;fi
# Remove a directory securely
ynh_secure_remove "/etc/zabbix"
if [ -d /etc/zabbix ] ;then ynh_secure_remove "/etc/zabbix";fi
# Remove the log files
ynh_secure_remove "/var/log/zabbix"
if [ -d /var/log/zabbix ] ;then ynh_secure_remove "/var/log/zabbix";fi
# Remove the pid/socket files
ynh_secure_remove "/run/zabbix"
if [ -d /run/zabbix ] ;then ynh_secure_remove "/run/zabbix";fi
# Remove the sudoers file
ynh_secure_remove "/etc/sudoers.d/zabbix"
if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove "/etc/sudoers.d/zabbix";fi
#REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)

View file

@ -96,8 +96,10 @@ db_user=$(ynh_app_setting_get $app db_user)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
convert_ZabbixDB
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql
#=================================================
# Restore configs files
#=================================================
@ -110,13 +112,20 @@ ynh_restore_file "/usr/share/zabbix/conf/zabbix.conf.php"
chown -R www-data. /usr/share/zabbix
ynh_restore_file "/etc/zabbix"
# systemd and yunohost service management
systemctl enable zabbix-server && systemctl start zabbix-server
ls -Rail "/etc/zabbix"
#ynh_restore_file "/etc/zabbix/web"
#ynh_restore_file "/etc/zabbix/web/init.zabbix.conf.php.sh"
ynh_restore_file "/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
if [ ! -L /etc/zabbix/zabbix_agentd.d ];then
ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
fi
systemctl enable zabbix-agent && systemctl restart zabbix-agent
change_timeoutAgent
systemctl enable zabbix-server && systemctl restart zabbix-server
yunohost service add snmpd -d "Management of SNMP Daemon"
yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
yunohost service add zabbix-client -d "Management Zabbix client daemon : send informations about this host to the server"
yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server"
#=================================================
# SETUP LOGROTATE

View file

@ -93,25 +93,8 @@ disable_guest_user
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path "$path_url")
#REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then
ynh_print_info "Removing snmp-mibs-downloader (non-free package)"
#want backup file , cannot use ynh_replace_string
cp /var/lib/dpkg/status{,.$(date "+%m%d%y")}
ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status
DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
if [ -f /etc/apt/sources.list.d/non-free.list ];then
ynh_secure_remove /etc/apt/sources.list.d/non-free.list
fi
fi
#Patch timeout too short for zabbix agent if needed
timeout_ok=$(grep -c "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null)
if [ $timeout_ok -ne 1 ] ;then
ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf
systemctl enable zabbix-agent && systemctl restart zabbix-agent
fi
change_timeoutAgent
#patch if zabbix-release installed
if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then
@ -189,6 +172,35 @@ else
ynh_print_info "No repo update ! (Trusted version)"
fi
#=================================================
# INSTALL hook to verify if conf file is broken (after an update for example)
#=================================================
update_initZabbixConf
#=================================================
# Update db to utf8
#=================================================
convert_ZabbixDB
#=================================================
# Update php-fpm confi
#=================================================
ynh_print_info "Update php-fpm config"
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
# Create a dedicated php-fpm config
ynh_add_fpm_config
#=================================================
# Update nginx config
#=================================================
ynh_print_info "Update nginx config"
# Remove the dedicated nginx config
ynh_remove_nginx_config
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# RE-ENABLE SSOWAT
#=================================================

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>4.4</version>
<date>2020-01-13T12:25:26Z</date>
<date>2020-04-22T11:49:47Z</date>
<groups>
<group>
<name>Templates/Applications</name>
@ -545,4 +545,4 @@ fi</description>
</mappings>
</value_map>
</value_maps>
</zabbix_export>
</zabbix_export>

View file

@ -0,0 +1 @@
DPkg::Post-Invoke {"/etc/zabbix/web/init.zabbix.conf.php.sh;"};

View file

@ -0,0 +1,30 @@
#!/bin/bash
if [ ! -e "/var/www/zabbix/conf/zabbix.conf.php" ] ; then
if [ ! -f /etc/zabbix/web/zabbix.conf.php ];then
cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php
fi
ln -s /etc/zabbix/web/zabbix.conf.php /usr/share/zabbix/conf/zabbix.conf.php
source /usr/share/yunohost/helpers
echo "<?php
// Zabbix GUI configuration file.
global \$DB, \$HISTORY;
\$DB['TYPE'] = 'MYSQL';
\$DB['SERVER'] = 'localhost';
\$DB['PORT'] = '0';
\$DB['DATABASE'] = '"$(yunohost app setting zabbix db_name)"';
\$DB['USER'] = '"$(yunohost app setting zabbix db_user)"';
\$DB['PASSWORD'] = '"$(yunohost app setting zabbix mysqlpwd)"';
// Schema name. Used for IBM DB2 and PostgreSQL.
\$DB['SCHEMA'] = '';
\$ZBX_SERVER = 'localhost';
\$ZBX_SERVER_PORT = '10051';
\$ZBX_SERVER_NAME = '';
\$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;">/etc/zabbix/web/zabbix.conf.php
echo "Frontend Zabbix Configuration fixed !"
fi