From c1e6d2566a06a8d4d4190f8fb291d2b014f7045e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raul=20Lib=C3=B3rio?= Date: Sat, 19 Dec 2015 00:20:01 -0300 Subject: [PATCH 1/5] Update zbxtg.sh Resume script --- zbxtg.sh | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/zbxtg.sh b/zbxtg.sh index 1c91280..b815ce6 100755 --- a/zbxtg.sh +++ b/zbxtg.sh @@ -31,24 +31,13 @@ METHOD="txt" # sendMessage (simple text) or sendPhoto (attached image) echo "${BODY}" | grep -q "${ZBX_TG_PREFIX};graphs" && METHOD="image" echo "${BODY}" | grep -q "${ZBX_TG_PREFIX};chat" && TG_CHAT=1 -if [ "${TG_CHAT}" -eq 1 ] -then - TG_CONTACT_TYPE="chat" -else - TG_CONTACT_TYPE="user" -fi - -TG_CHAT_ID=$(cat ${TMP_UIDS} | awk -F ';' '{if ($1 == "'${TO}'" && $2 == "'${TG_CONTACT_TYPE}'") print $3}' | tail -1) +TG_CHAT_ID=$(cat ${TMP_UIDS} | awk -F ';' END'{ print $NF}') if [ -z "${TG_CHAT_ID}" ] then TG_UPDATES=$(${CURL_TG}/getUpdates) - if [ "${TG_CHAT}" -eq 1 ] - then - TG_CHAT_ID=$(echo "${TG_UPDATES}" | sed -e 's/["}{]//g' | awk -F ',' '{if ($8 == "type:group" && $7 == "title:'${TO}'") {gsub("chat:id:", "", $6); print $6}}' | tail -1) - else - TG_CHAT_ID=$(echo "${TG_UPDATES}" | sed -e 's/["}{]//g' | awk -F ',' '{if ($10 == "type:private" && $5 == "username:'${TO}'") {gsub("chat:id:", "", $6); print $6}}' | tail -1) - fi + TG_CHAT_ID=$(echo "${TG_UPDATES}" | awk -F ',' END'{print $6}' | sed 's/"chat":{"id"://g;/^$/d' + echo "${TO};${TG_CONTACT_TYPE};${TG_CHAT_ID}" >> ${TMP_UIDS} fi From 54dc596214378eb52809e2ff85e30423698aa947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raul=20Lib=C3=B3rio?= Date: Sat, 19 Dec 2015 00:26:06 -0300 Subject: [PATCH 2/5] Update zbxtg.sh update in TMP_UIDS --- zbxtg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zbxtg.sh b/zbxtg.sh index b815ce6..2b1fe0c 100755 --- a/zbxtg.sh +++ b/zbxtg.sh @@ -38,7 +38,7 @@ then TG_UPDATES=$(${CURL_TG}/getUpdates) TG_CHAT_ID=$(echo "${TG_UPDATES}" | awk -F ',' END'{print $6}' | sed 's/"chat":{"id"://g;/^$/d' - echo "${TO};${TG_CONTACT_TYPE};${TG_CHAT_ID}" >> ${TMP_UIDS} + echo "${TO};${TG_CHAT_ID}" >> ${TMP_UIDS} fi TG_TEXT=$(echo "${BODY}" | grep -vE "^${ZBX_TG_PREFIX};"; echo "--") From 5327e28b8894096d3baca38bd267a210c9ae35e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raul=20Lib=C3=B3rio?= Date: Sat, 19 Dec 2015 03:23:49 -0300 Subject: [PATCH 3/5] Update zbxtg.sh Resume code --- zbxtg.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zbxtg.sh b/zbxtg.sh index 2b1fe0c..9c202fc 100755 --- a/zbxtg.sh +++ b/zbxtg.sh @@ -52,9 +52,9 @@ ${TG_TEXT}" 2>/dev/null "image") PERIOD=3600 # default period - echo "${BODY}" | grep -q "^${ZBX_TG_PREFIX};graphs_period" && PERIOD=$(echo "${BODY}" | awk -F 'zbxtg;graphs_period=' '{if ($2 != "") print $2}' | tail -1 | grep -Eo '[0-9]+' || echo 3600) - ZBX_ITEMID=$(echo "${BODY}" | awk -F 'zbxtg;itemid:' '{if ($2 != "") print $2}' | tail -1 | grep -Eo '[0-9]+') - ZBX_TITLE=$(echo "${BODY}" | awk -F 'zbxtg;title:' '{if ($2 != "") print $2}' | tail -1) + echo "${BODY}" | grep -q "^${ZBX_TG_PREFIX};graphs_period" && PERIOD=$(echo "${BODY}" | awk -F '=' /graphs_period/'{print $NF}') || PERIOD=3600 + ZBX_ITEMID=$(echo "${BODY}" | awk -F ':' /itemid/'{print $NF}') + ZBX_TITLE=$(echo "${BODY}" | awk -F ':' /title/'{print $NF}') URL="${ZBX_SERVER}/chart3.php?period=${PERIOD}&name=${ZBX_TITLE}&width=900&height=200&graphtype=0&legend=1&items[0][itemid]=${ZBX_ITEMID}&items[0][sortorder]=0&items[0][drawtype]=5&items[0][color]=00CC00" login CACHE_IMAGE="${TMP_DIR}/graph.${ZBX_ITEMID}.png" From 5ca935b31ef78559df1cd14cd6cd3a7fb27625a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raul=20Lib=C3=B3rio?= Date: Tue, 22 Dec 2015 12:21:31 -0300 Subject: [PATCH 4/5] Update zbxtg.sh Remove variable PERIOD in line 54 (unnecessary) --- zbxtg.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/zbxtg.sh b/zbxtg.sh index 9c202fc..3f663f4 100755 --- a/zbxtg.sh +++ b/zbxtg.sh @@ -51,7 +51,6 @@ ${TG_TEXT}" 2>/dev/null ;; "image") - PERIOD=3600 # default period echo "${BODY}" | grep -q "^${ZBX_TG_PREFIX};graphs_period" && PERIOD=$(echo "${BODY}" | awk -F '=' /graphs_period/'{print $NF}') || PERIOD=3600 ZBX_ITEMID=$(echo "${BODY}" | awk -F ':' /itemid/'{print $NF}') ZBX_TITLE=$(echo "${BODY}" | awk -F ':' /title/'{print $NF}') From f4f52ad3b5010761d41a9bed69aebc77d637ac5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raul=20Lib=C3=B3rio?= Date: Tue, 22 Dec 2015 16:25:04 -0300 Subject: [PATCH 5/5] Update zbxtg.sh Update in PERIOD variable --- zbxtg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zbxtg.sh b/zbxtg.sh index 3f663f4..bb90d14 100755 --- a/zbxtg.sh +++ b/zbxtg.sh @@ -51,7 +51,7 @@ ${TG_TEXT}" 2>/dev/null ;; "image") - echo "${BODY}" | grep -q "^${ZBX_TG_PREFIX};graphs_period" && PERIOD=$(echo "${BODY}" | awk -F '=' /graphs_period/'{print $NF}') || PERIOD=3600 + PERIOD=$(echo "${BODY}" | awk -F '=' /graphs_period/'{print $NF}') && [ -z $PERIOD ] && PERIOD=3600 ZBX_ITEMID=$(echo "${BODY}" | awk -F ':' /itemid/'{print $NF}') ZBX_TITLE=$(echo "${BODY}" | awk -F ':' /title/'{print $NF}') URL="${ZBX_SERVER}/chart3.php?period=${PERIOD}&name=${ZBX_TITLE}&width=900&height=200&graphtype=0&legend=1&items[0][itemid]=${ZBX_ITEMID}&items[0][sortorder]=0&items[0][drawtype]=5&items[0][color]=00CC00"