Created
May 24, 2013 18:30
-
-
Save skarllot/5645558 to your computer and use it in GitHub Desktop.
Zabbix Extras 1.2
http://spinola.net.br/blog/?p=382
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INSTALAR="N"; | |
AUTOR="[email protected]"; | |
TMP_DIR="/tmp/upgZabbix"; | |
DATA_BACKUP=`date +%Y%m%d`; | |
idioma() { | |
# Selecao de Idioma ------------------------------------------------------------------------- | |
if [ -d $TMP_DIR ]; then | |
if [ -f $TMP_DIR/resposta_dialog.txt ]; then | |
rm $TMP_DIR/resposta_dialog.txt; | |
fi | |
else | |
mkdir $TMP_DIR; | |
fi | |
dialog \ | |
--title 'Zabbix Extras Installer' \ | |
--radiolist 'Informe o idioma (Enter the language for the installer) ' \ | |
0 0 0 \ | |
pt 'Portugues / Brasil' on \ | |
en 'Ingles' off \ | |
2> $TMP_DIR/resposta_dialog.txt | |
OPCOES=`cat $TMP_DIR/resposta_dialog.txt `; | |
if [ "`echo $OPCOES| wc -m`" -eq 3 ]; then | |
INSTALAR="S"; | |
else | |
echo $OPCOES| wc -m | |
echo "Instalacao abortada ($OPCOES)..."; | |
exit; | |
fi | |
case $OPCOES in | |
"pt" ) | |
M_BASE="Este instalador ira adicionar um menu extra ao final da barra de menus do seu ambiente. Para a correta instalacao sao necessarios alguns parametros."; | |
M_CAMINHO="Favor informar o caminho para o frontend do zabbix"; | |
M_ERRO_CAMINHO="O caminho informado para o frontend do zabbix nao foi encontrado " | |
M_ERRO_ABORT="Instalacao abortada!"; | |
M_PATCH="Efetuar download dos arquivos do patch (S)?"; | |
M_PATCH_CAMINHO="Favor informar caminho para os arquivos do patch"; | |
M_PATCH_ERRO="O arquivo de patch nao foi localizado no caminho informado"; | |
M_INSTALL_ALL="Selecione os modulos a instalar"; | |
M_ZABBIX_CAT="Instalar o modulo de Gestao de Capacidade."; | |
M_ZABBIX_SC="Instalar o modulo de Gestao de Armazenamento."; | |
M_ZABBIX_NS="Instalar o modulo de Relatorio de itens nao suportados."; | |
M_ZABBIX_EM="Instalar o modulo de Correlacionamento de eventos."; | |
M_RESUMO_FRONT="Caminho do frontend: "; | |
M_RESUMO_PATCH="Localizacao dos arquivos do patch: "; | |
M_RESUMO_INSTALA="Confirma a instalacao nos moldes acima?"; | |
;; | |
*) | |
M_BASE="This installer will add an extra menu to the end of the menu bar of your environment. For installation are needed to inform some parameters."; | |
M_CAMINHO="Please enter the path to the zabbix frontend "; | |
M_ERRO_CAMINHO="The informed path to zabbix frontend is not valid " | |
M_ERRO_ABORT="Install aborted!"; | |
M_PATCH="Download the patch files (S) (S = Yes)?"; | |
M_PATCH_CAMINHO="Please inform the path to patch files"; | |
M_PATCH_ERRO="The patch file not found on informed path"; | |
M_INSTALL_ALL="Select the available menu items"; | |
M_ZABBIX_CAT="Install Capacity and Trends."; | |
M_ZABBIX_SC="Install Storage Costs."; | |
M_ZABBIX_NS="Install Not Supported Itens Report."; | |
M_ZABBIX_NS="Install Event Management."; | |
M_RESUMO_FRONT="Path to the Zabbix frontend: "; | |
M_RESUMO_PATCH="Path to patch files: "; | |
M_RESUMO_INSTALA="Confirm installation?"; | |
;; | |
esac | |
} | |
# Pre-requisitos para o funcionamento do instalador ============================ | |
preReq() { | |
# Verificando e instalando o wget | |
RESULT=`which wget 2>&- | wc -l`; | |
if [ "$RESULT" -eq 0 ]; then | |
echo "--> Instalando wget (pre requisito para todo o processo)"; | |
instalaPacote "wget"; | |
fi | |
# Verificando e instalando o dialog | |
if [ `which dialog 2>&- | wc -l` -eq 0 ]; then | |
echo "--> Instalando dialog (pre requisito para todo o processo)"; | |
instalaPacote "dialog"; | |
fi | |
} | |
# Define os parametros especificos de cada distribuicao ======================== | |
identificaDistro() { | |
TMP=`cat /etc/issue | head -n1 | tr "[:upper:]" "[:lower:]" | sed 's/release//g' | sed 's/ / /g' | sed 's/welcome\ to\ //g' `; | |
LINUX_DISTRO=`echo $TMP | head -n1 | awk -F' ' '{print $1}'` ; | |
LINUX_VER=`echo $TMP | sed 's/release//g' | awk -F' ' '{print $2}'`; | |
if [ -f /etc/redhat-release ]; then | |
PATHDEF="/var/www/html"; | |
RESTART_XINETD='service xinetd restart'; | |
GERENCIADOR_PACOTES='yum install -y '; | |
else | |
if [ `which zypper 2>&- | wc -l` -eq 1 ]; then | |
PATHDEF="/usr/share/zabbix"; | |
RESTART_XINETD='/etc/init.d/xinetd restart'; | |
GERENCIADOR_PACOTES='zypper install -y '; | |
else | |
PATHDEF="/var/www"; | |
RESTART_XINETD='/etc/init.d/xinetd restart'; | |
GERENCIADOR_PACOTES='apt-get install -y '; | |
fi | |
fi | |
case $LINUX_DISTRO in | |
"ubuntu" | "debian" | "red hat" | "centos" | "opensuse") | |
CAMINHO_RCLOCAL="/etc/rc.local"; | |
echo "-- Versao do Linux - OK ($LINUX_DISTRO - $LINUX_VER)" | |
;; | |
*) | |
echo "Distribucao nao prevista ($LINUX_DISTRO)... favor contactar $AUTOR"; exit 1; | |
;; | |
esac | |
} | |
instalaPacote() { | |
echo "============== Instalando pacote(s) ($1 $2 $3 $4 $5 $6 $7 $8 $9) ================="; | |
$GERENCIADOR_PACOTES $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} \ | |
${11} ${12} ${13} ${14} ${15} ${16} ${17} ${18} ${19} ${20} \ | |
${21} ${22} ${23} ${24} ${25} ${26} ${27} ${28} ${29} ${30}; | |
} | |
caminhoFrontend() { | |
dialog --inputbox "$M_BASE\n$M_CAMINHO" 0 0 "$PATHDEF" 2> $TMP_DIR/resposta_dialog.txt; | |
CAMINHO_FRONTEND=`cat $TMP_DIR/resposta_dialog.txt`; | |
# Questionando o usuario sobre o que executar ----------------------------------------------- | |
if [ ! -d "$CAMINHO_FRONTEND" ]; then | |
echo $M_ERRO_CAMINHO"($CAMINHO_FRONTEND). "$M_ERRO_ABORT; | |
exit 0; | |
fi | |
} | |
downloadPacote() { | |
dialog --yesno "$M_PATCH" 7 60; | |
response=$? | |
case $response in | |
0) DOWNLOAD="S"; | |
CAMINHO_EXTRAS="/tmp/tmpInstallZabbixExtras.tgz"; | |
;; | |
1) DOWNLOAD="N"; | |
dialog --inputbox "$M_PATCH_CAMINHO:" 0 0 "/tmp/tmpInstallZabbixExtras.tgz" 2> $TMP_DIR/resposta_dialog.txt; | |
CAMINHO_EXTRAS=`cat $TMP_DIR/resposta_dialog.txt`; | |
# Questionando o usuario sobre o que executar ----------------------------------------------- | |
if [ ! -f "$CAMINHO_EXTRAS" ]; then | |
echo $M_PATCH_ERRO"($CAMINHO_EXTRAS). "$M_ERRO_ABORT; | |
exit 0; | |
fi | |
;; | |
255) echo "[ESC] $M_ERRO_ABORT."; exit 0; ;; | |
esac | |
} | |
selecionaModulos() { | |
dialog --checklist "$M_INSTALL_ALL" \ | |
0 0 0 \ | |
cat "$M_ZABBIX_CAT" on \ | |
sc "$M_ZABBIX_SC" on \ | |
ns "$M_ZABBIX_NS" on \ | |
em "$M_ZABBIX_EM" on \ | |
2> $TMP_DIR/resposta_dialog.txt; | |
OPCOES=`cat $TMP_DIR/resposta_dialog.txt | sed 's/\"//g'`; | |
if [ ` echo $OPCOES | grep "cat" | wc -l ` -eq "1" ]; then | |
ZABBIX_CAT="S"; | |
fi | |
if [ ` echo $OPCOES | grep "sc" | wc -l ` -eq "1" ]; then | |
ZABBIX_SC="S"; | |
fi | |
if [ ` echo $OPCOES | grep "ns" | wc -l ` -eq "1" ]; then | |
ZABBIX_NS="S"; | |
fi | |
if [ ` echo $OPCOES | grep "em" | wc -l ` -eq "1" ]; then | |
ZABBIX_EM="S"; | |
fi | |
} | |
confirmaInstalacao() { | |
# Apresentando resumo do que sera feito ----------------------------------------------------- | |
TMP="$M_RESUMO_FRONT$CAMINHO_FRONTEND.\n$M_RESUMO_PATCH $CAMINHO_EXTRAS."; | |
if [ "$ZABBIX_CAT" = "S" ]; then | |
TMP="$TMP \n$M_ZABBIX_CAT"; | |
fi | |
if [ "$ZABBIX_SC" = "S" ]; then | |
TMP="$TMP \n$M_ZABBIX_SC"; | |
fi | |
if [ "$ZABBIX_NS" = "S" ]; then | |
TMP="$TMP \n$M_ZABBIX_NS"; | |
fi | |
if [ "$ZABBIX_EM" = "S" ]; then | |
TMP="$TMP \n$M_ZABBIX_EM"; | |
fi | |
TMP="$TMP\n$M_RESUMO_INSTALA"; | |
dialog --yesno "$TMP" 15 60; | |
response=$?; | |
case $response in | |
0) INSTALAR="S"; ;; | |
1) INSTALAR="N"; exit 0; ;; | |
255) echo "[ESC] $M_ERRO_ABORT."; exit 0; ;; | |
esac | |
} | |
expandePatch() { | |
# Download de arquivos para instalacao ------------------------------------------------------ | |
if [ "$DOWNLOAD" = "S" ]; then | |
if [ -f "$CAMINHO_EXTRAS" ]; then | |
rm -f "$CAMINHO_EXTRAS"; | |
fi | |
wget "http://spinola.net.br/zabbix-extras/installBeta.tgz" -O $CAMINHO_EXTRAS; | |
fi | |
# Instalando arquivos da customizacao ------------------------------------------------------- | |
clear; | |
cd $CAMINHO_FRONTEND; | |
tar -xzvf "$CAMINHO_EXTRAS"; | |
} | |
instalaMenus() { | |
# Instalando menu --------------------------------------------------------------------------- | |
if [ "$INSTALAR" = "S" ]; then | |
# Verificação de instalação prévia do patch no javascript -------------- | |
if [ "`cat js/main.js | grep spinola | wc -l`" -eq 0 ]; then | |
LINHA=`cat js/main.js | sed -ne "/{'empty'\:/{=;q;}"`; | |
echo "Instalando menu no javascript..."; | |
sed -i "106s/'admin': 0/'admin': 0,'spinolaExtras':0/g" js/main.js | |
fi | |
# Verificacao de instalacao previa do patch -- Menu.inc.php ------------ | |
cp include/menu.inc.php include/menu.inc.php.original | |
#NUMLINHA=`cat include/menu.inc.php | sed -ne "/login'\ =>\ a/{=;q;}"`; | |
INIINST=`cat include/menu.inc.php | sed -ne "/\#\#Zabbix\-Extras/{=;q;}"`; | |
FIMINST=`cat include/menu.inc.php | sed -ne "/\#\#Zabbix\-Extras\-FIM/{=;q;}"`; | |
if [ ! -z $INIINST ]; then | |
echo "Existe instalacao previa no arquivo... removendo customizacao!"; | |
sed -i "$INIINST,$FIMINST d" include/menu.inc.php | |
fi | |
echo "Instalando tags identificadoras do menu..."; | |
NUMLINHA=`cat include/menu.inc.php | sed -ne "/login'\ =>\ a/{=;q;}"`; | |
sed -i "$NUMLINHA i##Zabbix-Extras\n##Zabbix-Extras-FIM" include/menu.inc.php | |
INIINST=`cat include/menu.inc.php | sed -ne "/\#\#Zabbix\-Extras/{=;q;}"`; | |
FIMINST=`cat include/menu.inc.php | sed -ne "/\#\#Zabbix\-Extras\-FIM/{=;q;}"`; | |
# Instalando menu Extras | |
sed -i "$FIMINST i'spinolaExtras' => array('label'=> 'Extras', 'user_type' => USER_TYPE_ZABBIX_USER, 'node_perm' => PERM_READ_LIST, 'default_page_id' => 0," include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
sed -i "$FIMINST i'pages' => array(" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
# Instalacao do Zabbix-CAT - Modulo de gestao de capacidade | |
if [ "$ZABBIX_CAT" = "S" ]; then | |
sed -i "$FIMINST iarray('url' => 'zabbix-cat.php', 'label' => _('Zabbix-CAT'))" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
fi | |
# Instalacao do Zabbix-SC - Modulo de gestao de armazenamento | |
if [ "$ZABBIX_CAT" = "S" ]; then | |
sed -i "$FIMINST i,array('url' => 'zabbix-sc.php', 'label' => _('Zabbix-SC'))" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
fi | |
if [ "$ZABBIX_NS" = "S" ]; then | |
sed -i "$FIMINST i,array('url' => 'zabbix-ns.php', 'label' => _('Zabbix-NS'))" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
fi | |
if [ "$ZABBIX_EM" = "S" ]; then | |
sed -i "$FIMINST i,array('url' => 'zabbix-em.php', 'label' => _('Zabbix-EM'))" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
fi | |
sed -i "$FIMINST i)" include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
# Fim da instalacao dos menus | |
sed -i "$FIMINST i)," include/menu.inc.php | |
FIMINST=$(($FIMINST+1)); | |
echo "Patch e menus instalados entre as linhas $INIINST e $FIMINST do include/menu.inc.php"; | |
fi # Fim instalacao menus | |
} | |
identificaDistro; | |
preReq; | |
idioma; | |
caminhoFrontend; | |
downloadPacote; | |
selecionaModulos; | |
confirmaInstalacao; | |
expandePatch; | |
instalaMenus; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment