From 14e6ae1973dceb64d59d370745d40ee05ac4fb8d Mon Sep 17 00:00:00 2001 From: Vassiliy Yegorov Date: Sat, 13 Jul 2019 11:10:56 +0700 Subject: [PATCH] - move scripts from folder to git-repo - install script manual only --- main.tf | 17 +++++------ scripts/setupagent.sh | 1 + scripts/setupzabbix.sh | 3 ++ scripts/zabscripts/slack.sh | 23 --------------- scripts/zabscripts/slack1.sh | 52 ---------------------------------- scripts/zabscripts/smsc.conf | 4 --- scripts/zabscripts/smsc.sh | 31 -------------------- scripts/zabscripts/telegram.sh | 15 ---------- scripts/zabscripts/zviewer.sh | 10 ------- 9 files changed, 11 insertions(+), 145 deletions(-) delete mode 100644 scripts/zabscripts/slack.sh delete mode 100755 scripts/zabscripts/slack1.sh delete mode 100644 scripts/zabscripts/smsc.conf delete mode 100755 scripts/zabscripts/smsc.sh delete mode 100755 scripts/zabscripts/telegram.sh delete mode 100755 scripts/zabscripts/zviewer.sh diff --git a/main.tf b/main.tf index 3d35342..2674511 100644 --- a/main.tf +++ b/main.tf @@ -51,21 +51,18 @@ resource "google_compute_instance" "zabbix" { private_key = "${file("~/.ssh/id_rsa")}" } - # provisioner "file" { - # source = "scripts/setupzabbix.sh" - # destination = "~/setupzabbix.sh" - # } - - metadata_startup_script = "${file("scripts/setupzabbix.sh")}" - provisioner "file" { - source = "scripts/zabscripts" - destination = "/usr/lib/zabbix/alertscripts " + source = "scripts/setupzabbix.sh" + destination = "~/setupzabbix.sh" } + # provisioner "remote-exec" { + # inline = ["${file("scripts/setupzabbix.sh")}"] + # } + provisioner "file" { source = "scripts/zabconf" - destination = "/etc/zabbix" + destination = "~/" } } diff --git a/scripts/setupagent.sh b/scripts/setupagent.sh index 53ee577..c759ccb 100755 --- a/scripts/setupagent.sh +++ b/scripts/setupagent.sh @@ -1,5 +1,6 @@ #!/bin/bash +cd ~ sudo wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+bionic_all.deb sudo dpkg -i zabbix-release_4.0-2+bionic_all.deb sudo apt-get update diff --git a/scripts/setupzabbix.sh b/scripts/setupzabbix.sh index ac10dbd..236fedf 100755 --- a/scripts/setupzabbix.sh +++ b/scripts/setupzabbix.sh @@ -6,6 +6,7 @@ sudo apt update sudo apt install zabbix-server-mysql -y sudo apt install zabbix-frontend-php -y +sudo apt install git -y sudo mysql -uroot -e "create database zabbix character set utf8 collate utf8_bin;" sudo mysql -uroot -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'V7F4Uj12dcn5WAu';" @@ -14,6 +15,8 @@ sudo mysql -uroot -e "quit" sudo zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | sudo mysql -uzabbix zabbix -pV7F4Uj12dcn5WAu +git clone https://github.com/vasyakrg/zabbix-alert-scripts.git /usr/lib/zabbix/alertscripts + sudo service apache2 restart sudo service zabbix-server start sudo update-rc.d zabbix-server enable diff --git a/scripts/zabscripts/slack.sh b/scripts/zabscripts/slack.sh deleted file mode 100644 index a11bfdb..0000000 --- a/scripts/zabscripts/slack.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -KEY="https://hooks.slack.com/services/" -TO="$1" -SUB="$2" -MESS="$3" - -if [[ $SUB == 'PROBLEM' ]] -then - ICON=":scream:" -elif [[ $SUB == 'OK' ]] -then - ICON=":ok_hand:" -else - ICON=":point_up_2:" -fi - -/usr/local/bin/curl -X POST --data-urlencode "payload={\"channel\": \"$TO\", \"username\": \"TradeNarK\", \"text\": \"$ICON $SUB\n$MESS\"}" $KEY - - -# settings to zabbix-server -# {ALERT.SENDTO} -# {ALERT.SUBJECT} -# {ALERT.MESSAGE} diff --git a/scripts/zabscripts/slack1.sh b/scripts/zabscripts/slack1.sh deleted file mode 100755 index 7c1c8ba..0000000 --- a/scripts/zabscripts/slack1.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -# Slack incoming web-hook URL and user name -url='https://hooks.slack.com/services/' # example: url='https://hooks.slack.com/services/QW3R7Y/D34DC0D3/BCADFGabcDEF123' -username='zabbix-server' - -## Values received by this script: -# To = $1 / Slack channel or user to send the message to, specified in the Zabbix web interface; "@username" or "#channel" -# Subject = $2 / subject of the message sent by Zabbix; by default, it is usually something like "(Problem|Resolved): Lack of free swap space on Zabbix server" -# Message = $3 / message body sent by Zabbix; by default, it is usually approximately 4 lines detailing the specific trigger involved -# Alternate URL = $4 (optional) / alternative Slack.com web-hook URL to replace the above hard-coded one; useful when multiple groups have seperate Slack teams -# Proxy = $5 (optional) / proxy host including port (such as "example.com:8080") - -# Get the user/channel ($1), subject ($2), and message ($3) -to="$1" -subject="$2" -message="$3" - -# Change message emoji and notification color depending on the subject indicating whether it is a trigger going in to problem state or recovering -#recoversub='^RECOVER(Y|ED)?$|^OK$|^Resolved*' -recoversub='Resolved' -problemsub='Problem' -#problemsub='^Беда*' -updatesub='Update' - -if [[ "$subject" =~ $recoversub ]]; then - emoji=':smile:' - color='#0C7BDC' -elif [[ "$subject" =~ $problemsub ]]; then - emoji=':face_palm:' - color='#FFC20A' -elif [[ "$subject" =~ $updatesub ]]; then - emoji=':scream:' - color='#FFC20A' -else - emoji=':pager:' - color='#CCCCCC' -fi - -# Replace the above hard-coded Slack.com web-hook URL entirely, if one was passed via the optional 4th parameter -url=${4-$url} - -# Use optional 5th parameter as proxy server for curl -proxy=${5-""} -if [[ "$proxy" != '' ]]; then - proxy="-x $proxy" -fi - -# Build JSON payload which will be HTTP POST'ed to the Slack.com web-hook URL -payload="payload={\"channel\": \"${to//\"/\\\"}\", \ -\"username\": \"${username//\"/\\\"}\", \ -\"attachments\": [{\"fallback\": \"${subject//\"/\\\"}\", \"title\": \"${subject//\"/\\\"}\", \"text\": \"${message//\"/\\\"}\", \"color\": \"${color}\"}], \ diff --git a/scripts/zabscripts/smsc.conf b/scripts/zabscripts/smsc.conf deleted file mode 100644 index f02a447..0000000 --- a/scripts/zabscripts/smsc.conf +++ /dev/null @@ -1,4 +0,0 @@ -PATH=/bin:/usr/bin:/usr/local/bin - -USER_ID=X -PASSWORD=X diff --git a/scripts/zabscripts/smsc.sh b/scripts/zabscripts/smsc.sh deleted file mode 100755 index c505cb5..0000000 --- a/scripts/zabscripts/smsc.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -TO_NUMBER="$1" -SUBJECT="$2" -MESSAGE="$3" -echo ${TO_NUMBER} >> /tmp/out.txt -echo ${SUBJECT} >> /tmp/out.txt -echo ${MESSAGE} >> /tmp/out.txt - -. smsc.conf - -SMSC_URL=${SMSC_URL:-"https://smsc.ru/sys/send.php"} - -TO_NUMBER=$(echo "${TO_NUMBER}" | sed 's/[^0123456789]//g') - -NL='' - -RESULT=$(curl --get --silent --show-error \ - --data-urlencode "login=${USER_ID}" \ - --data-urlencode "psw=${PASSWORD}" \ - --data-urlencode "phones=${TO_NUMBER}" \ - --data-urlencode "mes=${SUBJECT}:${MESSAGE}" \ - "${SMSC_URL}" 2>&1 -) - -STATUS=$? - -echo ${RESULT} -echo ${RESULT} >> /tmp/smsc.txt - -exit ${STATUS} diff --git a/scripts/zabscripts/telegram.sh b/scripts/zabscripts/telegram.sh deleted file mode 100755 index 7d9d3e0..0000000 --- a/scripts/zabscripts/telegram.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -TOKEN='' - -which curl &>/dev/null -if [ $? -ne 0 ] ; then echo 'FAIL: curl not found.' && exit 1 ; fi -if [ $# -ne 3 ] ; then echo 'FAIL: Params not defined.' && echo 'Usage: zabbix-to-telegram-notify.sh TelegramID Subject Message' && exit 1 ; fi - -CHAT_ID="$1" -SUBJECT="$2" -MESSAGE="$3" - -curl -s --header 'Content-Type: application/json' --request 'POST' --data "{\"chat_id\":\"${CHAT_ID}\",\"text\":\"${SUBJECT}\n${MESSAGE}\"}" "https:// -api.telegram.org/bot${TOKEN}/sendMessage" | grep -q '"ok":false,' -if [ $? -eq 0 ] ; then exit 1 ; fi diff --git a/scripts/zabscripts/zviewer.sh b/scripts/zabscripts/zviewer.sh deleted file mode 100755 index c81ea5f..0000000 --- a/scripts/zabscripts/zviewer.sh +++ /dev/null @@ -1,10 +0,0 @@ -#/bin/bash -if [ $# -eq 0 ] ; then echo 'FAIL: Params not defined.' && echo 'Usage: zbxviewer.sh Token Subject Message' && exit 1 ; fi - -if wget -V >/dev/null 2>&1 ; then - #use wget - wget -q "https://zbx.vovanys.com/push/sendPush.php?token=$1&title=$2&desc=$3" -else - #if wget not found, use curl - curl -kdG "https://zbx.vovanys.com/push/sendPush.php?token=$1&title=$2&desc=$3" -fi