参考:curl命令详解
yum install -y jq
#!/bin/bash
kylo_host=192.168.10.1
feedCategorie=hello
kylo_cookie_file=/var/log/kylo-ui/cookies.txt
logFile=/var/log/kylo-services/moniter.log
# 简介:
# eg1 : sh moniter.sh login
# 重新获取cookie
# eg2: sh moniter.sh start feedName
# 启动feed 并监控feed执行结果
# eg3: sh moniter.sh status feedName
# 查看feed 状态
loginAndGetCookie(){
#获取kylo登陆的cookies
echo "用户 登录......"
if [[ -z $kylo_cookie_file ]]; then
#statements
sed -i "d" $kylo_cookie_file
fi
loginStatus=`curl -s -X POST -c $kylo_cookie_file --header "Accept: application/json" -d "username=dladmin&password=thinkbig&targetUrl=" http://$kylo_host:8400/login`
echo "$loginStatus"
}
getFeedHealth(){
# 获取feed健康状态
# COMPLETED
# FAILED
#EXECUTING
fhFeedName=$1
healthyResult=`curl -s -X GET --header "Accept: application/json" -b $kylo_cookie_file http://$kylo_host:8400/proxy/v1/feeds/health/$fhFeedName`
echo "$healthyResult"
}
startFeed(){
sfFeedName=$1
echo "start feed: $sfFeedName"
result_st1=$(getFeedHealth $sfFeedName)
kylo_feedId_1=`echo $result_st1 | jq '.feeds[0].feedId'`
kylo_feedId=`echo $kylo_feedId_1 | sed 's/\"//g'`
echo $kylo_feedId
if [[ -n $kylo_feedId ]]; then
#statements
start_status=`curl -s -X POST -b $kylo_cookie_file http://$kylo_host:8400/proxy/v1/feedmgr/feeds/start/$kylo_feedId`
statusValue=`echo $start_status | grep -Po 'status[":]+\K[^"]+'`
message=`echo $start_status | grep -Po 'message[":]+\K[^"]+'`
statusValue=`echo $statusValue | sed 's/,//g'`
case $statusValue in
401 )
echo "cookie 已过期。。。"
loginAndGetCookie
sleep 1.2s
startFeed $1
;;
405 )
echo "kylo_feedId 为空。。。"
getFeedHealth $1
sleep 1.2s
startFeed $1
;;
success )
echo "feed 启动成功。。。"
echo "feed 启动成功。。。"
echo "$start_status"
;;
esac
else
echo "feedID 为空。。。。"
echo "程序退出。。。"
echo "程序退出。。。"
exit 1
fi
}
moniterFeed(){
mFeedName=$1
echo "$feedName"
current=$(date "+%Y-%m-%d %H:%M:%S")
echo " kylo 任务监控中 ...."
echo "当前时间:$current kylo 任务监控中"
echo " "
while [[ true ]]; do
#statements
sleep 3.0
result=$(getFeedHealth $mFeedName);
lastExitCode=`echo $result | jq '.feeds[0].lastOpFeed.exitCode'`
# COMPLETED
# FAILED
#EXECUTING
echo "运行监控中 "
exitCode=`echo $lastExitCode | sed 's/\"//g'`
case $exitCode in
COMPLETED )
echo "feed任务已完成。。。$mFeedName"
current_cmp=$(date "+%Y-%m-%d %H:%M:%S")
echo "监控任务结束 exit 0"
echo "监控任务结束时间:$current_cmp kylo 任务执行完成。。"
echo "程序退出。。。"
echo "程序退出。。。"
exit 0
;;
FAILED )
echo "feed任务已失败。。。$mFeedName"
echo "监控任务结束 exit 1"
current_fd=$(date "+%Y-%m-%d %H:%M:%S")
echo "监控任务结束时间:$current_fd kylo 任务执行失败。。"
echo "程序退出。。。"
echo "程序退出。。。"
exit 1
;;
EXECUTING )
echo "任务进行中。。。$mFeedName"
;;
esac
done
}
word=$1
case $word in
login)
echo "登录"
loginAndGetCookie
;;
start)
cp /root/userdata1.csv /var/dropzone/.
startFeed $feedCategorie.$2
sleep 2.0
moniterFeed $feedCategorie.$2
# moniterFeed feedCategorie.$2
;;
status)
echo "查询feed 执行状态 : $feedCategorie.$2"
result=$(getFeedHealth $feedCategorie.$2);
lastExitCode=`echo $result | jq '.feeds[0].lastOpFeed.exitCode'`
exitCode=`echo $lastExitCode | sed 's/\"//g'`
echo "feedStatus: $exitCode"
;;
stop)
echo "stop something"
;;
*)
echo "您的输入有误,请重新输入"
;;
esac
网友评论