#! /bin/bash
function judge()
{
K8sCluster=$1
#Dir=webapps/ROOT/WEB-INF/lib/
Dir=$2
FileName=$3
FileFullName=$4
rm -f /tmp/detail.list
rm -f /tmp/app.list
for pod in $(kubectl get pod | grep dmo | awk '{print $1}')
do
jar=$(kubectl exec -it $pod -- sh -c "ls $Dir | grep $FileName" | grep $FileName)
# if [ -z "$jar" ]; then
# echo $jar" "null
# fi
if [ -n "$jar" ]; then
count=$(echo $jar | grep $FileFullName | wc -l)
if [ 0 -eq $count ]; then
image=$(curl -G -d "k8sCluster=$K8sCluster" -d "type=pod" -d "name=$pod" http://172.37.66.177:30380/k8s-openapi/apiMonopolistic/findImage)
app=$(echo $image | awk -F"/|:" '{print $3}')
detail=$(echo $app"::::"$image"::::"$jar)
echo $app >> /tmp/app.list
echo $detail >> /tmp/detail.list
fi
fi
done
#cp jar.json /tmp
#rm -f /tmp/test
#awk 'NR == 1 {p = $0} NR > 1 {print p; p = $0} END{printf p} ' /tmp/detail.list > /tmp/detailNew.list
for app in $(cat /tmp/app.list | sort | uniq)
do
sed -i "s#result#${app}|result#g" /tmp/jar.json
done
cat /tmp/detail.list | sort | uniq | while read originline
do
# ^M的输入方式是 Ctrl + v ,然后Ctrl + M
line=$(echo $originline | sed -e 's/
//g')
APP=""
IMAGE=""
JAR=""
eval $(echo $line | awk -F"::::" '{printf("APP=%s;IMAGE=%s;JAR=%s",$1,$2,$3)}')
# sed -i "s#result#${APP}|result#g" /tmp/jar.json
sed -i "s#DESCdesc#${line}|DESCdesc#g" /tmp/jar.json
done
sed -i "s#|result##g" /tmp/jar.json
sed -i "s#result##g" /tmp/jar.json
sed -i "s#|DESCdesc##g" /tmp/jar.json
sed -i "s#DESCdesc##g" /tmp/jar.json
curl -H "Content-Type: application/json" -X POST -d @/tmp/jar.json http://172.37.66.177:30380/alert/common/alert
}
function main(){
CLUSTER=$1
echo $CLUSTER
curl -G -d "categoryNo=CONFIG" -d "codeNo=shell/alert/file_version" http://172.37.66.177:30480/rpp/apiMonopolistic/code/getCacheValue | grep $CLUSTER | grep -v "#" > /tmp/req.list
cat /tmp/req.list | while read req
do
cp jar.json /tmp
JAR=$(echo $req | awk '{print $4}')
sed -i "s#CLUSTERcluster#${CLUSTER}#g" /tmp/jar.json
title="容器扫描结果: "$CLUSTER"环境,jar版本要求:"$JAR" 需要调整的有:"
sed -i "s#TITLEtitle#${title}#g" /tmp/jar.json
judge $req
#judge ningxia-dev3 /usr/local/tomcat/webapps/ROOT/WEB-INF/lib bizcloud-framework-mongo-dao bizcloud-framework-mongo-dao-2.1.18-SNAPSHOT.jar
done
}
main $1
{
"cluster":"CLUSTERcluster",
"type": "image",
"title": "TITLEtitle",
"text": "result",
"desc": "DESCdesc"
}