zabbix.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. echo -e '
  3. _ _ _
  4. _____ _| |__| |__(_)__
  5. |_ / _` | `_ \ `_ \ / _|
  6. /__\__,_|_.__/_.__/_\__|
  7. '
  8. . bin/checkroot.sh
  9. # get the current position
  10. _cwd="$(pwd)"
  11. # check for assets forlder
  12. _assets="$_cwd/assets"
  13. if [ ! -d "$_assets" ]; then
  14. _assets="$_cwd/../assets"
  15. if [ ! -d "$_assets" ]; then
  16. echo "!! can't find assets directory !!"
  17. exit
  18. fi
  19. fi
  20. apk add zabbix-agent
  21. # configure
  22. echo -n "Please provide the current server's public ip : "
  23. read _cur_ip
  24. echo -n "Please provide the zabbix-server's ip : "
  25. read _ip
  26. echo -n "Please provide the hostname of this agent : "
  27. read _host_name
  28. echo -n "Please provide the mysql root password : "
  29. read _root_mysql_passwd
  30. # configure zabbix agent
  31. sed -i "s#Server=127.0.0.1#Server=$_ip#g" /etc/zabbix/zabbix_agentd.conf
  32. sed -i "s#ServerActive=127.0.0.1#ServerActive=$_ip#g" /etc/zabbix/zabbix_agentd.conf
  33. sed -i "s#Hostname=Zabbix server#Hostname=$_host_name#g" /etc/zabbix/zabbix_agentd.conf
  34. _agent_conf_d="/etc/zabbix/zabbix_agentd.d"
  35. mkdir $_agent_conf_d
  36. sed -i "s|#\ Include=$|Include= $_agent_conf_d|g" /etc/zabbix/zabbix_agentd.conf
  37. # apk
  38. # check for alpine security updates
  39. # # MYSQL
  40. # # https://serverfault.com/questions/737018/zabbix-user-parameter-mysql-status-setting-home
  41. # # create zabbix user home
  42. # mkdir /var/lib/zabbix
  43. # # generate random password for zabbix mysql user
  44. # _passwd="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12)"
  45. # # add mysql credentials to zabbix home
  46. # printf "[client]\n
  47. # user=zabbix\n
  48. # password=$_passwd" > /var/lib/zabbix/.my.cnf
  49. # # create zabbix mysql user
  50. # mysql -uroot -p"$_root_mysql_passwd" -e "CREATE USER 'zabbix' IDENTIFIED BY '$_passwd';"
  51. # mysql -uroot -p"$_root_mysql_passwd" -e "GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY '$_passwd';"
  52. # # add zabbix-agent parameter
  53. # cp "$_assets"/zabbix/userparameter_mysql.conf "$_agent_conf_d"/
  54. # NGINX
  55. # https://github.com/sfuerte/zbx-nginx
  56. # nginxconf already included in default.nginxconf asset
  57. sed -i "s/# allow CURRENT-SERVER-IP/allow $_cur_ip/g" /etc/nginx/conf.d/default.conf
  58. cp "$_assets"/zabbix/userparameter_nginx.conf "$_agent_conf_d"/
  59. mkdir /etc/zabbix/zabbix_agentd.scripts
  60. cp "$_assets"/zabbix/scripts/nginx-stat.py /etc/zabbix/zabbix_agentd.scripts/
  61. chmod +x /etc/zabbix/zabbix_agentd.scripts/nginx-stat.py
  62. echo -n "This is box is a proxmox CT? [Y|n] "
  63. read yn
  64. yn=${yn:-y}
  65. if [ "$yn" = "Y" ] || [ "$yn" = "y" ]; then
  66. cp "$_assets"/zabbix/proxmox-ct.conf "$_agent_conf_d"/
  67. fi
  68. # allow comm. port with zabbix-server
  69. ufw allow from "$_ip" to any port 22
  70. ufw allow from "$_ip" to any port 10050
  71. # ufw allow from "$_ip" to any port 10051
  72. rc-update add zabbix-agentd
  73. service zabbix-agentd restart
  74. echo -e "Zabbix-agent installed and configured, please add the host $_host_name in your zabbix-server"
  75. echo -e "And import requested templates in assets/zabbix/templates/"
  76. # echo -e "zabbix user mysql password is $_passwd"