then
verification=false
echo "Configuration incomplète, merci de vérifier les paramètres."
-fi
-
-# CLEAN DES LOGS
-if [ -e "${log_file}" ]
-then
- rm "${log_file}"
-fi
-
-# TEST DE CONNEXION
-echo "Test d'accès de l'application sur ""${instance_fqdn_interne}""..."
-code=$(curl -s -w "%{http_code}" --max-time 5 "http://""${instance_fqdn_interne}""/api/rest/allo/version" --output /dev/null)
-
-if [ "${code}" == 200 ] || [ "${code}" == 301 ]
-then
- echo "Test OK, récupération des informations..."
-
- # REQUETE (en insecure pour le moment)
- curl --max-time 10 -k -X GET -H "${response_accept}" "http://""${instance_fqdn_interne}""/api/rest/allo/version/" --output "response.json" 2> /dev/null
-
- # LOG DE LA REPONSE
- #echo "$(cat response.json)" 2>&1 | tee -a $log_file
-
- # VALIDATION DU JSON (nécessite outil de validation json et paquet node)
- isJSONCorrupted="$(module/json -nq response.json)"
- #echo "${isJSONCorrupted}"
-
- # SI LA VARIABLE EST INITIALISEE MAIS VIDE => PAS D'ERREUR
- if [[ -z $isJSONCorrupted && ${isJSONCorrupted+x} ]]
- then
- echo "Envoi des information au serveur ALLO..."
-
- # RÉCUPÉRATION DES NOMS, UUIDS ET LABELS DES DISQUES
- disques=$(blkid /dev/sd* | sed 's/\"//g')
-
- # SYSTEME D'EXPLOITATION
- systeme=$(sed 's/\\n\ \\l//g' /etc/issue)
-
- # AJOUT DE LA REFERENCE PRODUIT (nécessite package jq)
- jq '. + { "reference": "'"${instance_reference}"'" }' response.json > tmp1.json
-
- # AJOUT DU TYPE D'USAGER
- jq '. + { "usager_type": "'"${usager_type}"'" }' tmp1.json > tmp2.json
-
- # AJOUT DES INFOS DISQUES
- jq '. + { "disques": "'"${disques}"'" }' tmp2.json > tmp3.json
-
- # AJOUT DES INFOS DISQUES
- jq '. + { "systeme": "'"${systeme}"'" }' tmp3.json > tmp4.json
-
- # AJOUT DU FQDN EXTERNE
- jq '. + { "fqdn_externe": "'"${instance_fqdn_externe}"'" }' tmp4.json > tmp5.json
-
- # AJOUT DU FQDN INTERNE
- jq '. + { "fqdn_interne": "'"${instance_fqdn_interne}"'" }' tmp5.json > tmp6.json
-
- # AJOUT DU TYPE DE L'INSTANCE
- jq '. + { "canal": "'"${instance_canal}"'" }' tmp6.json > request.json
-
- # ENVOI DE L'UPDATE AU SERVEUR
- curl --cert bma.pem --key bma.key -X POST -H "${request_type}" --data-binary "@request.json" "https://""${allo_serveur_url}""/?action=upload_info" --output "response_server" 2> /dev/null
- if [ -e ./response_server ]
- then
- echo "Réponse du serveur ALLO :"
- #tee response_server -a "$log_file"
- cat response_server 2>&1 | tee -a "$log_file"
- else
- echo "Aucune réponse du serveur !" 2>&1 | tee -a "$log_file"
- fi
- rm response*
- rm request.json
- rm tmp*.json
- else
- echo "Les données récupérées sont illisibles" 2>&1 | tee -a "$log_file"
- fi
else
- echo "L'application a renvoyé une erreur : " 2>&1 | tee -a "$log_file"
- case "${code}" in
- "500")
- echo "Erreur interne du serveur" 2>&1 | tee -a "$log_file"
- ;;
- "400" | "404")
- echo "Mauvaise requete" 2>&1 | tee -a "$log_file"
- ;;
- "403")
- echo "Accès refusé" 2>&1 | tee -a "$log_file"
+ # CLEAN DES LOGS
+ if [ -e "${log_file}" ]
+ then
+ rm "${log_file}"
+ fi
+
+ # TEST DE CONNEXION
+ echo "Test d'accès de l'application sur ""${instance_fqdn_interne}""..."
+ code=$(curl -s -w "%{http_code}" --max-time 5 "http://""${instance_fqdn_interne}""/api/rest/allo/version" --output /dev/null)
+
+ if [ "${code}" == 200 ] || [ "${code}" == 301 ]
+ then
+ echo "Test OK, récupération des informations..."
+
+ # REQUETE (en insecure pour le moment)
+ curl --max-time 10 -k -X GET -H "${response_accept}" "http://""${instance_fqdn_interne}""/api/rest/allo/version/" --output "response.json" 2> /dev/null
+
+ # LOG DE LA REPONSE
+ #echo "$(cat response.json)" 2>&1 | tee -a $log_file
+
+ # VALIDATION DU JSON (nécessite outil de validation json et paquet node)
+ isJSONCorrupted="$(module/json -nq response.json)"
+ #echo "${isJSONCorrupted}"
+
+ # SI LA VARIABLE EST INITIALISEE MAIS VIDE => PAS D'ERREUR
+ if [[ -z $isJSONCorrupted && ${isJSONCorrupted+x} ]]
+ then
+ echo "Envoi des information au serveur ALLO..."
+
+ # RÉCUPÉRATION DES NOMS, UUIDS ET LABELS DES DISQUES
+ disques=$(blkid /dev/sd* | sed 's/\"//g')
+
+ # SYSTEME D'EXPLOITATION
+ systeme=$(sed 's/\\n\ \\l//g' /etc/issue)
+
+ # AJOUT DE LA REFERENCE PRODUIT (nécessite package jq)
+ jq '. + { "reference": "'"${instance_reference}"'" }' response.json > tmp1.json
+
+ # AJOUT DU TYPE D'USAGER
+ jq '. + { "usager_type": "'"${usager_type}"'" }' tmp1.json > tmp2.json
+
+ # AJOUT DES INFOS DISQUES
+ jq '. + { "disques": "'"${disques}"'" }' tmp2.json > tmp3.json
+
+ # AJOUT DES INFOS DISQUES
+ jq '. + { "systeme": "'"${systeme}"'" }' tmp3.json > tmp4.json
+
+ # AJOUT DU FQDN EXTERNE
+ jq '. + { "fqdn_externe": "'"${instance_fqdn_externe}"'" }' tmp4.json > tmp5.json
+
+ # AJOUT DU FQDN INTERNE
+ jq '. + { "fqdn_interne": "'"${instance_fqdn_interne}"'" }' tmp5.json > tmp6.json
+
+ # AJOUT DU TYPE DE L'INSTANCE
+ jq '. + { "canal": "'"${instance_canal}"'" }' tmp6.json > request.json
+
+ # ENVOI DE L'UPDATE AU SERVEUR
+ curl --cert bma.pem --key bma.key -X POST -H "${request_type}" --data-binary "@request.json" "https://""${allo_serveur_url}""/?action=upload_info" --output "response_server" 2> /dev/null
+ if [ -e ./response_server ]
+ then
+ echo "Réponse du serveur ALLO :"
+ #tee response_server -a "$log_file"
+ cat response_server 2>&1 | tee -a "$log_file"
+ else
+ echo "Aucune réponse du serveur !" 2>&1 | tee -a "$log_file"
+ fi
+ rm response*
+ rm request.json
+ rm tmp*.json
+ else
+ echo "Les données récupérées sont illisibles" 2>&1 | tee -a "$log_file"
+ fi
+ else
+ echo "L'application a renvoyé une erreur : " 2>&1 | tee -a "$log_file"
+ case "${code}" in
+ "500")
+ echo "Erreur interne du serveur" 2>&1 | tee -a "$log_file"
+ ;;
+ "400" | "404")
+ echo "Mauvaise requete" 2>&1 | tee -a "$log_file"
+ ;;
+ "403")
+ echo "Accès refusé" 2>&1 | tee -a "$log_file"
+ ;;
+ *)
+ echo "Aucune réponse de l'application" 2>&1 | tee -a "$log_file"
;;
- *)
- echo "Aucune réponse de l'application" 2>&1 | tee -a "$log_file"
- ;;
- esac
+ esac
+ fi
fi
echo ""