拼接json,发送给server
钉钉实现告警
#!/bin/bash dbid=1 host_ip='测试' alterFile=/root/error.log alertLineFile=/tmp/alertLine message= if [ ! -f "$alertLineFile" ] || [ ! -s "$alertLineFile" ]; then echo 0 > $alertLineFile fi alertLine=$(cat "$alertLineFile") if [ $alertLine -eq 0 ]; then alertLine=$(awk 'END{print NR}' $alterFile) echo $alertLine > $alertLineFile exit else endLine=$(awk 'END{print NR}' $alterFile) [[ $alertLine -gt $endLine ]] && exit message=$(sed -n "$alertLine,$endLine p" $alterFile |grep -E 'ORA-'|grep -v 'ORA-00060'|sed 's/\"//g') let endLine++ echo $endLine > $alertLineFile fi if [ ! -z "$message" ]; then json="{\"dbid\":\"$dbid\",\"host_ip\":\"$host_ip\",\"message\":\"$message\"}" ##send message curl -H "Content-Type: application/json" -X POST --data "$json" http://10.15.49.54:8090/interface/getloginfo fi