1
0
mirror of https://github.com/Nivolis/1c_zabbix_template_ce.git synced 2024-11-24 08:02:19 +02:00

Решение issue-#5

This commit is contained in:
Alexey Y. Fedotov 2019-10-24 14:50:36 +03:00
parent eb9b99e109
commit 5267ce8165

View File

@ -7,22 +7,47 @@
# Email: fedotov@kaminsoft.ru
#
TM_MODULE="1c_common_tm.sh"
DUMP_CODE_0=0 # Local or Remote copy successful
DUMP_CODE_1=1 # Local copy exists
DUMP_CODE_2=2 # Local copy failed
DUMP_CODE_3=3 # Remote copy failed
STORE_PERIOD=30 # Problem log store period - 30 days
LOG_DIR=${1%/}
LOG_SUBDIR="zabbix/locks"
WAIT_LIMIT=${2}
[[ -f ${0%/*}/${TM_MODULE} ]] && source ${0%/*}/${TM_MODULE} 2>/dev/null && TM_AVAILABLE=1
[[ ! -d ${LOG_DIR}/${LOG_SUBDIR} ]] && echo "ОШИБКА: Неверно задан каталог технологического журнала!" && exit 1
G_BINDIR=$(ls -d /opt/1C/v8*/x*)
LOG_FILE=$(date --date="@$(($(date "+%s") - 3600))" "+%y%m%d%H")
function save_logs {
if [[ $(echo ${1} | grep -ic $(hostname)) -ne 0 ]]; then
if [[ -f ${LOG_DIR}/${LOG_SUBDIR%/*}/problem_log/${LOG_FILE}.tgz ]]; then
DUMP_RESULT=${DUMP_CODE_1}
else
cd ${LOG_DIR}/${LOG_SUBDIR} && tar czf ../problem_log/${LOG_FILE}.tgz ./rphost_*/${LOG_FILE}.log && \
DUMP_RESULT=${DUMP_CODE_0} || DUMP_RESULT=${DUMP_CODE_2}
fi
else
zabbix_get -s ${1} -k 1c.rphost.locks[${LOG_DIR},${WAIT_LIMIT},${RAS_PORT},dump] 2>/dev/null || \
DUMP_RESULT=${DUMP_CODE_3}
fi
[[ ${DUMP_RESULT} -gt 1 ]] && DUMP_TEXT="ОШИБКА: не удалось сохранить файлы технологического журнала!" ||
DUMP_TEXT="Файлы технологического журнала сохранены (${LOG_DIR}/${LOG_SUBDIR%/*}/problem_log/${LOG_FILE}.tgz)"
[[ -n ${DUMP_RESULT} ]] && echo "[${1} (${DUMP_RESULT})] ${DUMP_TEXT}" && unset DUMP_RESULT
}
if [[ ${4} != "dump" ]]; then
[[ -n ${3} ]] && RAS_PORT=${3} || RAS_PORT=1545
@ -43,7 +68,7 @@ if [[ ${4} != "dump" ]]; then
COUNTERS=${RESULT[0]%<*}
if [[ ${COUNTERS##*:} != 0 || $(expr ${COUNTERS%%:*} ">" "${WAIT_LIMIT}.0") != 0 || $(echo ${COUNTERS} | cut -d: -f2) != 0 ]]; then
if [[ ${COUNTERS##*:} != 0 || $(echo "${COUNTERS%%:*} > ${WAIT_LIMIT}" | bc) != 0 || $(echo ${COUNTERS} | cut -d: -f2) != 0 ]]; then
for CURR_RMNGR in ${RMNGR_LIST[*]}
do
@ -67,23 +92,15 @@ fi
for CURR_LIST in ${RPHOST_LIST[*]}
do
for CURR_RPHOST in ${CURR_LIST//:/ }
do
if [[ $(echo ${CURR_RPHOST} | grep -ic $(hostname)) -ne 0 ]]; then
if [[ -f ${LOG_DIR}/${LOG_SUBDIR%/*}/problem_log/${LOG_FILE}.tgz ]]; then
DUMP_RESULT=${DUMP_CODE_1}
else
cd ${LOG_DIR}/${LOG_SUBDIR} && tar czf ../problem_log/${LOG_FILE}.tgz ./rphost_*/${LOG_FILE}.log && \
DUMP_RESULT=${DUMP_CODE_0} || DUMP_RESULT=${DUMP_CODE_2}
fi
else
zabbix_get -s ${CURR_RPHOST} -k 1c.rphost.locks[${LOG_DIR},${WAIT_LIMIT},${RAS_PORT},dump] 2>/dev/null || \
DUMP_RESULT=${DUMP_CODE_3}
fi
[[ ${DUMP_RESULT} -gt 1 ]] && DUMP_TEXT="ОШИБКА: не удалось сохранить файлы технологического журнала!" ||
DUMP_TEXT="Файлы технологического журнала сохранены (${LOG_DIR}/${LOG_SUBDIR%/*}/problem_log/${LOG_FILE}.tgz)"
[[ -n ${DUMP_RESULT} ]] && echo "[${CURR_RPHOST} (${DUMP_RESULT})] ${DUMP_TEXT}" && unset DUMP_RESULT
done
if [[ -z ${TM_AVAILABLE} ]]; then
for CURR_RPHOST in ${CURR_LIST//:/ }
do
save_logs ${CURR_RPHOST}
done
else
TASKS_LIST=(${CURR_LIST//:/ })
tasks_manager save_logs 0
fi
done
find ${LOG_DIR}/${LOG_SUBDIR%/*}/problem_log/ -mtime +${STORE_PERIOD} -name "*.tgz" -exec rm -f {} \;