فهرست منبع

Upgrade to 6.0~ynh1

yalh76 1 سال پیش
والد
کامیت
24c0d172dc
12فایلهای تغییر یافته به همراه188 افزوده شده و 200 حذف شده
  1. 1 1
      conf/nginx.conf
  2. 41 0
      conf/zabbix-cli.toml
  3. 41 0
      conf/zabbix-cli_default.toml
  4. 3 13
      hooks/post_user_create
  5. 1 9
      hooks/post_user_delete
  6. 18 30
      manifest.toml
  7. 2 82
      scripts/_common.sh
  8. 3 0
      scripts/backup
  9. 54 36
      scripts/install
  10. 4 29
      scripts/remove
  11. 3 0
      scripts/restore
  12. 17 0
      scripts/upgrade

+ 1 - 1
conf/nginx.conf

@@ -4,7 +4,7 @@ location __PATH__/ {
   # Path to source
   alias /usr/share/zabbix/;
 
-  index index_http.php;
+  index index.php;
 
   # Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
   #client_max_body_size 50M;

+ 41 - 0
conf/zabbix-cli.toml

@@ -0,0 +1,41 @@
+[api]
+url = "https://__DOMAIN____PATH__"
+username = "__ZABBIX_USERNAME__"
+password = "__ZABBIX_PASSWORD__"
+auth_token = ""
+verify_ssl = true
+
+[app]
+default_hostgroups = [
+    "All-hosts",
+]
+default_admin_usergroups = []
+default_create_user_usergroups = []
+default_notification_users_usergroups = [
+    "All-notification-users",
+]
+export_directory = "/usr/share/zabbix-cli/exports"
+export_format = "json"
+export_timestamps = false
+use_auth_token_file = true
+auth_token_file = "/usr/share/zabbix-cli/.zabbix-cli_auth_token"
+auth_file = "/usr/share/zabbix-cli/.zabbix-cli_auth"
+history = true
+history_file = "/usr/share/zabbix-cli/history"
+bulk_mode = "strict"
+allow_insecure_auth_file = true
+legacy_json_format = false
+
+[app.output]
+format = "table"
+color = true
+paging = false
+theme = "default"
+
+[logging]
+enabled = true
+log_level = "INFO"
+log_file = "/usr/share/zabbix-cli/log/zabbix-cli.log"
+
+[plugins]
+

+ 41 - 0
conf/zabbix-cli_default.toml

@@ -0,0 +1,41 @@
+[api]
+url = "https://__DOMAIN____PATH__"
+username = "Admin"
+password = "zabbix"
+auth_token = ""
+verify_ssl = true
+
+[app]
+default_hostgroups = [
+    "All-hosts",
+]
+default_admin_usergroups = []
+default_create_user_usergroups = []
+default_notification_users_usergroups = [
+    "All-notification-users",
+]
+export_directory = "/usr/share/zabbix-cli/exports"
+export_format = "json"
+export_timestamps = false
+use_auth_token_file = true
+auth_token_file = "/usr/share/zabbix-cli/.zabbix-cli_auth_token"
+auth_file = "/usr/share/zabbix-cli/.zabbix-cli_auth"
+history = true
+history_file = "/usr/share/zabbix-cli/history"
+bulk_mode = "strict"
+allow_insecure_auth_file = true
+legacy_json_format = false
+
+[app.output]
+format = "table"
+color = true
+paging = false
+theme = "default"
+
+[logging]
+enabled = true
+log_level = "INFO"
+log_file = "/usr/share/zabbix-cli/log/zabbix-cli.log"
+
+[plugins]
+

+ 3 - 13
hooks/post_user_create

@@ -2,17 +2,7 @@
 source /usr/share/yunohost/helpers
 
 user=$1
-app=zabbix
 
-surname=$(ynh_user_get_info --username=$user --key=lastname)
-name=$(ynh_user_get_info --username=$user --key=firstname)
-db_name=$(ynh_app_setting_get --app=$app --key=db_name)
-db_user=$(ynh_app_setting_get --app=$app --key=db_user)
-db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
-language=$(ynh_app_setting_get --app=$app --key=language)
-
-mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
-
-lastid=$($mysqlconn -BN -e "select userid from users order by userid desc limit 1")
-lastid=$((lastid+1))
-$mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ("$lastid",'"$user"', '"$name"', '"$surname"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$language"', '30s', 1, 'default', 0, '', 0, 50);"
+lastname=$(ynh_user_get_info --username=$user --key=lastname)
+firstname=$(ynh_user_get_info --username=$user --key=firstname)
+/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $user --firstname $firstname --lastname $lastname --role user --groups 8

+ 1 - 9
hooks/post_user_delete

@@ -1,13 +1,5 @@
 #!/bin/bash
-source /usr/share/yunohost/helpers
 
 user=$1
-app=zabbix
 
-db_name=$(ynh_app_setting_get --app=$app --key=db_name)
-db_user=$(ynh_app_setting_get --app=$app --key=db_user)
-db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
-
-mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
-
-$mysqlconn -e "DELETE FROM users WHERE alias=\"$1\";"
+/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml  remove_user $user

+ 18 - 30
manifest.toml

@@ -7,7 +7,7 @@ name = "Zabbix"
 description.en = "Monitoring tool for diverse IT components, including networks, servers, VMs and cloud services"
 description.fr = "Outil pour monitorer des réseaux, des serveurs, des VMs et autres services en ligne"
 
-version = "5.0.41~ynh3"
+version = "6.0~ynh1"
 
 maintainers = []
 
@@ -19,11 +19,14 @@ code = "https://github.com/zabbix/zabbix"
 cpe = "cpe:2.3:a:zabbix:zabbix"
 
 [integration]
-yunohost = ">= 11.2"
+yunohost = ">= 11.2.30"
 architectures = ["amd64"]
 multi_instance = false
+
 ldap = true
+
 sso = true
+
 disk = "500M"
 ram.build = "200M"
 ram.runtime = "200M"
@@ -54,10 +57,15 @@ ram.runtime = "200M"
 
 [resources]
     [resources.system_user]
+    # This will provision/deprovision a unix system user
 
     [resources.install_dir]
+    # This will create/remove the install dir as /var/www/$app
+    # and store the corresponding setting $install_dir
 
     [resources.permissions]
+    # This will configure SSOwat permission for $domain/$path/
+    # The initial allowed group of user is configured via the init_main_permission question (public=visitors, private=all_users)
     main.url = "/"
 
     [resources.ports]
@@ -65,41 +73,21 @@ ram.runtime = "200M"
 
     [resources.apt]
     packages = [
-        "libapr1",
-        "libaprutil1",
-        "libaprutil1-dbd-sqlite3",
-        "libaprutil1-ldap",
-        "liblua5.2-0",
-        "fonts-dejavu-core",
-        "patch",
-        "smistrip",
-        "unzip",
-        "wget",
-        "fping",
-        "libcap2-bin",
-        "libiksemel3",
-        "libopenipmi0",
-        "libpam-cap",
-        "libsnmp-base",
-        "libsnmp40",
-        "snmptrapd",
-        "snmpd",
-        "libjs-prototype",
-        "jq",
-        "libssh-4",
-        "php7.4-fpm",
-        "php7.4-bcmath",
+        "php8.2-fpm",
         "mariadb-server",
+        "python3-venv",
     ]
 
     [resources.apt.extras.zabbix]
-    repo = "http://repo.zabbix.com/zabbix/5.0/debian __YNH_DEBIAN_VERSION__ main"
+    repo = "deb https://repo.zabbix.com/zabbix/6.0/debian __YNH_DEBIAN_VERSION__ main"
     key = "https://repo.zabbix.com/zabbix-official-repo.key"
     packages = [
-        "zabbix-agent",
-        "zabbix-frontend-php",
         "zabbix-server-mysql",
-    ]
+        "zabbix-frontend-php",
+        "zabbix-sql-scripts",
+        "zabbix-agent",
+        ]
 
     [resources.database]
+    # This will automatically provision/deprovison a DB and store the corresponding credentials in settings $db_user, $db_name, $db_pwd
     type = "mysql"

+ 2 - 82
scripts/_common.sh

@@ -89,67 +89,7 @@ import_template () {
 
 	systemctl restart zabbix-agent
 
-	# Temporarily enable visitors if needed...
-	local visitors_enabled=$(ynh_permission_has_user "main" "visitors" && echo yes || echo no)
-	if [[ $visitors_enabled == "no" ]]; then
-	    ynh_permission_update --permission "main" --add "visitors"
-	fi
- 
-	curlOptions="--noproxy $domain -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1"
-
-	curl -L $curlOptions \
-					--form "enter=Sign+in" \
-					--form "name=Admin" \
-					--form "password=zabbix" \
-					"$zabbixFullpath/index.php"
-
-	if [ $? -eq 0 ]
-	then
-		sid=$(curl $curlOptions \
-						"$zabbixFullpath/conf.import.php?rules_preset=template" \
-						| grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' )
-
-		importState=$(curl $curlOptions \
-						--form "config=1" \
-						--form "import_file=@$localpath" \
-						--form "rules[groups][createMissing]=1" \
-						--form "rules[templates][updateExisting]=1" \
-						--form "rules[templates][createMissing]=1" \
-						--form "rules[templateScreens][updateExisting]=1" \
-						--form "rules[templateScreens][createMissing]=1" \
-						--form "rules[templateLinkage][createMissing]=1" \
-						--form "rules[applications][createMissing]=1" \
-						--form "rules[items][updateExisting]=1" \
-						--form "rules[items][createMissing]=1" \
-						--form "rules[discoveryRules][updateExisting]=1" \
-						--form "rules[discoveryRules][createMissing]=1" \
-						--form "rules[triggers][updateExisting]=1" \
-						--form "rules[triggers][createMissing]=1" \
-						--form "rules[graphs][updateExisting]=1" \
-						--form "rules[graphs][createMissing]=1" \
-						--form "rules[httptests][updateExisting]=1" \
-						--form "rules[httptests][createMissing]=1" \
-						--form "rules[valueMaps][createMissing]=1" \
-						--form "import=Import" \
-						--form "backurl=templates.php" \
-						--form "form_refresh=1" \
-						--form "sid=${sid}" \ \
-						"${zabbixFullpath}/conf.import.php?rules_preset=template" \
-						| grep -c "Imported successfully")
-
-		if [ "$importState" -eq "1" ]
-		then
-			ynh_print_info --message="YunoHost template imported !"
-		else
-			ynh_print_warn --message="YunoHost template not imported !"
-		fi
-	else
-		ynh_print_warn --message="Admin user cannot connect to the interface !"
-	fi
-
-	if [[ $visitors_enabled == "no" ]]; then
-	    ynh_permission_update --permission "main" --remove "visitors"
-        fi
+	/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml import_configuration $localpath
 }
 
 # Link YunoHost template to Zabbix server
@@ -157,27 +97,7 @@ import_template () {
 link_template () {
 	ynh_print_info --message="Link YunoHost template to Zabbix server"
 
-	# Temporarily enable visitors if needed...
-	local visitors_enabled=$(ynh_permission_has_user "main" "visitors" && echo yes || echo no)
-	if [[ $visitors_enabled == "no" ]]; then
-	    ynh_permission_update --permission "main" --add "visitors"
-	fi
-
-	#apply template to host
-	tokenapi=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result')
-	zabbixHostID=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].hostid')
-	zabbixTemplateID=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid')
-	applyTemplate=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]')
-	if [ "$applyTemplate" -eq "$zabbixHostID" ]
-	then
-		ynh_print_info --message="YunoHost template linked to Zabbix server !"
-	else
-		ynh_print_warn --message="YunoHost template not linked to Zabbix server !"
-	fi
-
- 	if [[ $visitors_enabled == "no" ]]; then
-	    ynh_permission_update --permission "main" --remove "visitors"
-        fi
+	/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml link_template_to_host "Template Yunohost" "Zabbix server"
 }
 
 # Check if Zabbix server is started

+ 3 - 0
scripts/backup

@@ -39,6 +39,9 @@ ynh_backup --src_path="/etc/zabbix/zabbix_agentd.d"
 # Backup sudo file
 ynh_backup --src_path="/etc/sudoers.d/zabbix"
 
+# Backup zabbix-cli
+ynh_backup --src_path="/usr/share/zabbix-cli"
+
 #=================================================
 # BACKUP THE MYSQL DATABASE
 #=================================================

+ 54 - 36
scripts/install

@@ -7,6 +7,16 @@
 source _common.sh
 source /usr/share/yunohost/helpers
 
+#=================================================
+# INITIALIZE AND STORE SETTINGS
+#=================================================
+
+zabbix_username="svc_${app}_ldap"
+zabbix_password=$(ynh_string_random --length=32)
+
+ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
+ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
+
 #=================================================
 # DOWNLOAD, CHECK AND UNPACK SOURCE
 #=================================================
@@ -23,41 +33,14 @@ ynh_script_progression --message="Import default data in database..."
 export mysqlconn="mysql --user=$db_user --password=$db_pwd --database=$db_name"
 $mysqlconn -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
 
-zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
+zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | $mysqlconn
 
 convert_ZabbixDB
 
-#sso integration
-$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
-
-#admin creation
-surname=$(ynh_user_get_info "$admin" lastname)
-name=$(ynh_user_get_info "$admin" firstname)
-
-$mysqlconn -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 3, 'default', 0, '', 0, 50);"
-$mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
-
-#users creation in zabbix database
-i=4
-for user in $(ynh_user_list);
-do
-	if [ "$user" != "$admin" ]
-	then
-		surname=$(ynh_user_get_info --username="$user" --key=lastname)
-		name=$(ynh_user_get_info --username="$user" --key=firstname)
-		$mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 1, 'default', 0, '', 0, 50);"
-		i=$((i+1))
-	fi
-done
-
-disable_guest_user
-
-set_mediatype_default_yunohost
-
 #=================================================
-# ADD A CONFIGURATION
+# APP INITIAL CONFIGURATION
 #=================================================
-ynh_script_progression --message="Adding a configuration file..."
+ynh_script_progression --message="Adding $app's configuration files..."
 
 ynh_add_config --template="../conf/etc_zabbix_web_zabbix.conf.php" --destination="/etc/zabbix/web/zabbix.conf.php"
 
@@ -76,10 +59,10 @@ ynh_script_progression --message="Adding system configurations related to $app..
 ynh_replace_string --match_string="# $language.UTF-8 UTF-8" --replace_string="$language.UTF-8 UTF-8" --target_file=/etc/locale.gen
 locale-gen
 
-# Create a dedicated PHP-FPM config
+# Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it)
 ynh_add_fpm_config
 
-# Create a dedicated NGINX config
+# Create a dedicated NGINX config using the conf/nginx.conf template
 ynh_add_nginx_config
 
 change_timeoutAgent
@@ -93,16 +76,51 @@ yunohost service add zabbix-agent --description="Management Zabbix agent daemon
 update_initZabbixConf
 
 #=================================================
-# SETUP APPLICATION WITH CURL
+# SETUP APPLICATION
 #=================================================
-ynh_script_progression --message="Setting up application with CURL..."
+ynh_script_progression --message="Setting up application..."
 
-import_template
+mkdir -p /usr/share/zabbix-cli
+python3 -m venv /usr/share/zabbix-cli
+/usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
 
-link_template
+#ldap zabbix user creation in zabbix database
+yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
+ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
+/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $zabbix_username --firstname $zabbix_username --lastname $zabbix_username --passwd $zabbix_password --role superadmin --groups 7
+ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
+
+#sso integration activation
+$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
+#Ldap integration activation
+$mysqlconn -e "UPDATE \`config\` SET \`authentication_type\` = '1', \`ldap_host\` = '127.0.0.1', \`ldap_port\` = '389', \`ldap_base_dn\` = 'ou=users,dc=yunohost,dc=org', \`ldap_search_attribute\` = 'uid' WHERE \`config\`.\`configid\` = 1;"
+
+#admin creation in zabbix database
+lastname=$(ynh_user_get_info "$admin" lastname)
+firstname=$(ynh_user_get_info "$admin" firstname)
+/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $admin --firstname $firstname --lastname $lastname --role superadmin --groups 7
+
+#users creation in zabbix database
+for user in $(ynh_user_list);
+do
+	if [ "$user" != "$admin" ] && [ "$user" != "$zabbix_username" ] && [ "$user" != "admin" ] && [ "$user" != "guest" ]
+	then
+		lastname=$(ynh_user_get_info --username="$user" --key=lastname)
+		firstname=$(ynh_user_get_info --username="$user" --key=firstname)
+		/usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $user --firstname $firstname --lastname $lastname --role user --groups 8
+	fi
+done
+
+disable_guest_user
 
 disable_admin_user
 
+set_mediatype_default_yunohost
+
+import_template
+
+link_template
+
 #=================================================
 # START SYSTEMD SERVICE
 #=================================================

+ 4 - 29
scripts/remove

@@ -24,48 +24,23 @@ yunohost service remove snmpd
 yunohost service remove zabbix-server
 yunohost service remove zabbix-agent
 
-# Remove the dedicated NGINX config
 ynh_remove_nginx_config
 
-# Remove the dedicated PHP-FPM config
 ynh_remove_fpm_config
 
-#=================================================
-# REMOVE DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Removing $app's configuration..."
+# Remove other various files specific to the app... such as:
+
+yunohost user delete $zabbix_username --purge
 
 # Remove config file detection
 delete_initZabbixConf
-
 ynh_secure_remove --file="/usr/share/$app"
-
-#=================================================
-# REMOVE VARIOUS FILES
-#=================================================
-ynh_script_progression --message="Removing various files..."
-
-# Remove a directory securely
 ynh_secure_remove --file="/etc/$app"
-
-# Remove the log files
-
 ynh_secure_remove --file="/run/$app"
 
 ynh_secure_remove --file="/etc/sudoers.d/$app"
 
-# FIXME: useless?
-# 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 --message="Removing snmp-mibs-downloader (non-free package)"
-    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 --file="/etc/apt/sources.list.d/non-free.list"
-    fi
-fi
+ynh_secure_remove --file="/usr/share/zabbix-cli"
 
 #=================================================
 # END OF SCRIPT

+ 3 - 0
scripts/restore

@@ -51,6 +51,9 @@ fi
 # Restore sudo file
 ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
 
+# Restore zabbix-cli
+ynh_restore_file --origin_path="/usr/share/zabbix-cli"
+
 #=================================================
 # RESTORE SYSTEM CONFIGURATIONS
 #=================================================

+ 17 - 0
scripts/upgrade

@@ -61,6 +61,23 @@ chmod 750 "/usr/share/zabbix"
 chmod -R o-rwx "/usr/share/zabbix"
 chown -R "$app:www-data" "/usr/share/zabbix"
 
+if [ ! -d "/usr/share/zabbix-cli" ]; then
+    zabbix_username="svc_${app}_ldap"
+    zabbix_password=$(ynh_string_random --length=32)
+    ynh_app_setting_set --app="$app" --key=zabbix_username --value="$zabbix_username"
+    ynh_app_setting_set --app="$app" --key=zabbix_password --value="$zabbix_password"
+    yunohost user create "$zabbix_username" --fullname "${zabbix_username//_}" --domain "$domain" --password "$zabbix_password" -q 0
+
+    mkdir -p /usr/share/zabbix-cli
+    python3 -m venv /usr/share/zabbix-cli
+    /usr/share/zabbix-cli/bin/pip install zabbix-cli-uio
+    ynh_add_config --template="zabbix-cli_default.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
+    enable_admin_user
+    /usr/share/zabbix-cli/bin/zabbix-cli --config /usr/share/zabbix-cli/zabbix-cli.toml create_user $zabbix_username --firstname $zabbix_username --lastname $zabbix_username --passwd $zabbix_password --role superadmin --groups 7
+    disable_admin_user
+    ynh_add_config --template="zabbix-cli.toml" --destination="/usr/share/zabbix-cli/zabbix-cli.toml"
+fi
+
 #=================================================
 # SPECIFIC UPGRADE
 #=================================================