From ed7e5f55cb49d97621ad594e8afa1bfd0485867f Mon Sep 17 00:00:00 2001 From: SyllasGS Date: Thu, 7 May 2026 14:20:40 -0300 Subject: [PATCH] =?UTF-8?q?Pos=20teste=20de=20instala=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + docs/INSTALACAO_DEBIAN13.md | 4 ++ installer/install_debian13.sh | 88 +++++++++++++++++++++++-------- installer/vfire-stack.env.example | 5 +- vfire_monitor/core.py | 17 +++--- 5 files changed, 83 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index f9f99e0..2d2d242 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ config_nodes.json mapa_dispositivos.json license.key app_secret.key +installer/vfire-stack.env diff --git a/docs/INSTALACAO_DEBIAN13.md b/docs/INSTALACAO_DEBIAN13.md index 8d11b3a..6bdf5e6 100644 --- a/docs/INSTALACAO_DEBIAN13.md +++ b/docs/INSTALACAO_DEBIAN13.md @@ -49,6 +49,10 @@ cp installer/vfire-stack.env.example installer/vfire-stack.env Edite `installer/vfire-stack.env`. +Observacoes importantes: +- `ZABBIX_ADMIN_PASSWORD` deve respeitar a politica da interface do Zabbix. Evite senhas contendo `zabbix`, `admin` ou `administrator`. +- Se quiser instalar em modo laboratorio usando a chave legada embutida, ajuste `ALLOW_LEGACY_LICENSE_KEY=1`. Nesse caso o instalador publica `VFM_ALLOW_LEGACY_LICENSE_KEY=1` no servico do app. + Campos minimos que voce deve revisar: - `PUBLIC_HOSTNAME` diff --git a/installer/install_debian13.sh b/installer/install_debian13.sh index 563d038..7311966 100644 --- a/installer/install_debian13.sh +++ b/installer/install_debian13.sh @@ -110,7 +110,7 @@ load_config() { assert_command_dependencies() { local cmd - for cmd in curl jq gpg wget rsync python3 psql runuser systemctl ss; do + for cmd in apt-get python3 runuser systemctl; do command -v "${cmd}" >/dev/null 2>&1 || die "Comando obrigatorio ausente: ${cmd}" done } @@ -118,9 +118,13 @@ assert_command_dependencies() { assert_ports_available() { local port [[ "${DRY_RUN}" == "1" ]] && return 0 + command -v ss >/dev/null 2>&1 || return 0 + if [[ "${VFM_APP_PORT}" == "${ZABBIX_WEB_PORT}" || "${VFM_APP_PORT}" == "${GRAFANA_PORT}" || "${ZABBIX_WEB_PORT}" == "${GRAFANA_PORT}" ]]; then + die "As portas configuradas para V-Fire Monitor, Zabbix e Grafana precisam ser distintas." + fi for port in "${VFM_APP_PORT}" "${ZABBIX_WEB_PORT}" "${GRAFANA_PORT}"; do if ss -ltn "( sport = :${port} )" | tail -n +2 | grep -q .; then - die "Porta ${port} ja esta em uso." + log "Porta ${port} ja esta em uso. O instalador vai prosseguir para permitir reexecucoes e atualizacoes." fi done } @@ -136,9 +140,9 @@ apt_install() { write_zabbix_repo() { run_cmd install -d -m 0755 /usr/share/keyrings if [[ "${DRY_RUN}" == "1" ]]; then - printf '[dry-run] curl -fsSL https://repo.zabbix.com/zabbix-official-repo.key | gpg --dearmor -o %s\n' "${ZABBIX_APT_KEYRING}" + printf '[dry-run] curl -fsSL https://repo.zabbix.com/zabbix-official-repo.key | gpg --dearmor --yes -o %s\n' "${ZABBIX_APT_KEYRING}" else - curl -fsSL "https://repo.zabbix.com/zabbix-official-repo.key" | gpg --dearmor -o "${ZABBIX_APT_KEYRING}" + curl -fsSL "https://repo.zabbix.com/zabbix-official-repo.key" | gpg --dearmor --yes -o "${ZABBIX_APT_KEYRING}" fi run_cmd chmod 0644 "${ZABBIX_APT_KEYRING}" cat >"${ZABBIX_APT_LIST}" < /etc/zabbix/web/zabbix.conf.php </dev/null - zabbix_api_request "$(jq -cn --arg auth "${auth_token}" '{jsonrpc:"2.0",method:"user.logout",params:[],auth:$auth,id:1}')" >/dev/null || true + '{jsonrpc:"2.0",method:"user.update",params:{userid:$userid,current_passwd:$current,passwd:$passwd},id:1}')" "${auth_token}" || true)" + zabbix_require_success "${auth_response}" "Falha ao atualizar a senha administrativa do Zabbix" return 0 fi auth_payload="$(jq -cn --arg username "${ZABBIX_ADMIN_USERNAME}" --arg password "${ZABBIX_ADMIN_PASSWORD}" '{jsonrpc:"2.0",method:"user.login",params:{username:$username,password:$password},id:1}')" auth_response="$(zabbix_api_request "${auth_payload}" || true)" + zabbix_require_success "${auth_response}" "Falha ao autenticar na API do Zabbix com as credenciais administrativas configuradas" auth_token="$(printf '%s' "${auth_response}" | jq -r '.result // empty')" [[ -n "${auth_token}" ]] || die "Nao foi possivel autenticar na API do Zabbix com as credenciais administrativas configuradas." - zabbix_api_request "$(jq -cn --arg auth "${auth_token}" '{jsonrpc:"2.0",method:"user.logout",params:[],auth:$auth,id:1}')" >/dev/null || true } zabbix_login() { local response response="$(zabbix_api_request "$(jq -cn --arg username "${ZABBIX_ADMIN_USERNAME}" --arg password "${ZABBIX_ADMIN_PASSWORD}" '{jsonrpc:"2.0",method:"user.login",params:{username:$username,password:$password},id:1}')")" + zabbix_require_success "${response}" "Falha ao obter token da API do Zabbix" printf '%s' "${response}" | jq -r '.result // empty' } @@ -451,8 +500,7 @@ zabbix_get_single_id() { --arg method "${method}" \ --arg key "${filter_key}" \ --arg value "${filter_value}" \ - --arg auth "${auth}" \ - '{jsonrpc:"2.0",method:$method,params:{output:["'"${id_key}"'"],filter:{($key):[$value]}},auth:$auth,id:1}')" \ + '{jsonrpc:"2.0",method:$method,params:{output:["'"${id_key}"'"],filter:{($key):[$value]}},id:1}')" "${auth}" \ | jq -r ".result[0].${id_key} // empty" } @@ -462,9 +510,8 @@ import_zabbix_template() { [[ -f "${ZABBIX_TEMPLATE_FILE}" ]] || die "Template do Zabbix nao encontrado: ${ZABBIX_TEMPLATE_FILE}" source="$(cat "${ZABBIX_TEMPLATE_FILE}")" zabbix_api_request "$(jq -cn \ - --arg auth "${auth}" \ --arg source "${source}" \ - '{jsonrpc:"2.0",method:"configuration.import",params:{format:"yaml",source:$source,rules:{template_groups:{createMissing:true,updateExisting:true},templates:{createMissing:true,updateExisting:true},discoveryRules:{createMissing:true,updateExisting:true,deleteMissing:false},items:{createMissing:true,updateExisting:true,deleteMissing:false},triggers:{createMissing:true,updateExisting:true,deleteMissing:false},valueMaps:{createMissing:true,updateExisting:true,deleteMissing:false},templateDashboards:{createMissing:true,updateExisting:true,deleteMissing:false}}},auth:$auth,id:1}')" >/dev/null + '{jsonrpc:"2.0",method:"configuration.import",params:{format:"yaml",source:$source,rules:{template_groups:{createMissing:true,updateExisting:true},templates:{createMissing:true,updateExisting:true},discoveryRules:{createMissing:true,updateExisting:true,deleteMissing:false},items:{createMissing:true,updateExisting:true,deleteMissing:false},triggers:{createMissing:true,updateExisting:true,deleteMissing:false},valueMaps:{createMissing:true,updateExisting:true,deleteMissing:false},templateDashboards:{createMissing:true,updateExisting:true,deleteMissing:false}}},id:1}')" "${auth}" >/dev/null } ensure_zabbix_host_group() { @@ -475,7 +522,7 @@ ensure_zabbix_host_group() { printf '%s' "${group_id}" return 0 fi - zabbix_api_request "$(jq -cn --arg auth "${auth}" --arg name "${ZABBIX_HOST_GROUP}" '{jsonrpc:"2.0",method:"hostgroup.create",params:{name:$name},auth:$auth,id:1}')" | jq -r '.result.groupids[0]' + zabbix_api_request "$(jq -cn --arg name "${ZABBIX_HOST_GROUP}" '{jsonrpc:"2.0",method:"hostgroup.create",params:{name:$name},id:1}')" "${auth}" | jq -r '.result.groupids[0]' } ensure_zabbix_monitored_host() { @@ -489,22 +536,20 @@ ensure_zabbix_monitored_host() { host_id="$(zabbix_get_single_id "host.get" "host" "${ZABBIX_MONITORED_HOST}" "hostid" "${auth}")" if [[ -n "${host_id}" ]]; then zabbix_api_request "$(jq -cn \ - --arg auth "${auth}" \ --arg hostid "${host_id}" \ --arg host "${ZABBIX_MONITORED_HOST}" \ --arg group_id "${group_id}" \ --arg template_id "${template_id}" \ - '{jsonrpc:"2.0",method:"host.update",params:{hostid:$hostid,host:$host,name:$host,status:0,groups:[{groupid:$group_id}],templates:[{templateid:$template_id}]},auth:$auth,id:1}')" >/dev/null + '{jsonrpc:"2.0",method:"host.update",params:{hostid:$hostid,host:$host,name:$host,status:0,groups:[{groupid:$group_id}],templates:[{templateid:$template_id}]},id:1}')" "${auth}" >/dev/null printf '%s' "${host_id}" return 0 fi zabbix_api_request "$(jq -cn \ - --arg auth "${auth}" \ --arg host "${ZABBIX_MONITORED_HOST}" \ --arg group_id "${group_id}" \ --arg template_id "${template_id}" \ - '{jsonrpc:"2.0",method:"host.create",params:{host:$host,name:$host,status:0,groups:[{groupid:$group_id}],templates:[{templateid:$template_id}],tags:[{tag:"application",value:"vfire-monitor"}]},auth:$auth,id:1}')" | jq -r '.result.hostids[0]' + '{jsonrpc:"2.0",method:"host.create",params:{host:$host,name:$host,status:0,groups:[{groupid:$group_id}],templates:[{templateid:$template_id}],tags:[{tag:"application",value:"vfire-monitor"}]},id:1}')" "${auth}" | jq -r '.result.hostids[0]' } seed_vfire_runtime_config() { @@ -554,7 +599,6 @@ provision_zabbix_objects() { [[ -n "${group_id}" ]] || die "Falha ao criar ou localizar host group do Zabbix." host_id="$(ensure_zabbix_monitored_host "${auth}" "${group_id}")" [[ -n "${host_id}" ]] || die "Falha ao criar ou localizar host monitorado do Zabbix." - zabbix_api_request "$(jq -cn --arg auth "${auth}" '{jsonrpc:"2.0",method:"user.logout",params:[],auth:$auth,id:1}')" >/dev/null || true seed_vfire_runtime_config } diff --git a/installer/vfire-stack.env.example b/installer/vfire-stack.env.example index 3a86047..ff6376d 100644 --- a/installer/vfire-stack.env.example +++ b/installer/vfire-stack.env.example @@ -18,9 +18,10 @@ ZABBIX_DB_NAME=zabbix ZABBIX_DB_USER=zabbix ZABBIX_DB_PASSWORD= ZABBIX_ADMIN_USERNAME=Admin -ZABBIX_ADMIN_PASSWORD=zabbix +# Evite usar "zabbix", "admin" ou "administrator" na senha do Admin do Zabbix. +ZABBIX_ADMIN_PASSWORD= ZABBIX_TEMPLATE_FILE=/opt/vfire-monitor/zbx_export_templates.yaml -ZABBIX_TEMPLATE_NAME=Notifier NFS320 +ZABBIX_TEMPLATE_NAME="Notifier NFS320" ZABBIX_HOST_GROUP=Notifier ZABBIX_MONITORED_HOST=NFS-320 diff --git a/vfire_monitor/core.py b/vfire_monitor/core.py index e029eb3..4ac8f38 100644 --- a/vfire_monitor/core.py +++ b/vfire_monitor/core.py @@ -127,14 +127,15 @@ def normalize_config(data: dict, default_password: str) -> dict: return config -def load_license_key(require_env: bool) -> bytes: - env_key = os.getenv("VFM_LICENSE_MASTER_KEY") - if env_key: - return env_key.encode("utf-8") - if require_env: - raise RuntimeError( - "VFM_LICENSE_MASTER_KEY e obrigatoria em producao. Defina a variavel de ambiente antes de iniciar o sistema." - ) +def load_license_key(require_env: bool) -> bytes: + env_key = os.getenv("VFM_LICENSE_MASTER_KEY") + allow_legacy = os.getenv("VFM_ALLOW_LEGACY_LICENSE_KEY", os.getenv("ALLOW_LEGACY_LICENSE_KEY", "0")) == "1" + if env_key: + return env_key.encode("utf-8") + if require_env and not allow_legacy: + raise RuntimeError( + "VFM_LICENSE_MASTER_KEY e obrigatoria em producao. Defina a variavel de ambiente antes de iniciar o sistema." + ) LOGGER.warning( "VFM_LICENSE_MASTER_KEY nao definido. Usando chave legada embutida; mova a chave para variavel de ambiente." )