You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

print_config_title 'CHECK IPAM CONFIG'
# Get IPAM Token
RES_AUTHENT=$(${CURL} -k -X POST --user ${USER_IPAM}:${PASSWORD_IPAM} ${URL}/user/ 2>/dev/null)
CODE_RETOUR_RES_AUTHENT=$(echo ${RES_AUTHENT} | jq '.code')
TOKEN=$(echo ${RES_AUTHENT} | jq -r '.data.token')
# Check if IPAM API request succeded
# If IPAM API connection FAILED
if [ "${CODE_RETOUR_RES_AUTHENT}" -ne 200 ] || [ ! -n "${TOKEN}" ]; then
echo -e "${RED}Connection to IPAM API FAILED or empty TOKEN : check KO${NC}\n"
# If IPAM API connection SUCCEDED
else
# Get list of IP to check
# WARNING, if one of variable is empty, ALL IP may be checked (but we just want to check our public ranges and admin IPs)
IPS_TO_CHECK=$(ip addr show scope global | awk '/inet/ { sub(/\/.*$/, "", $2); print $2 }' | sort | uniq | grep -e "^${IPV4_ADMIN_NETWORK}" -e "^${IPV6_ADMIN_NETWORK}" -e "^${RANGE_IPV4_1_NETWORK}" -e "^${RANGE_IPV4_2_NETWORK}" -e "^${RANGE_IPV6_NETWORK}" )
# Return Code
RC=$?
# If no IP to check found
if [ $RC -ne 0 ]
then
IPAM_CONFIG_CHECK_FAILED="${IPAM_CONFIG_CHECK_FAILED} No IP to check in IPAM, check the IP configuration"
echo -e "${RED}NO IP to check in IPAM : check KO${NC}\n"
else
# Check if all found IP are recorded in IPAM
for ip_to_check in ${IPS_TO_CHECK}
do
echo -e "Check if ${BLUE}${ip_to_check}${NC} is recorded in IPAM"
# Request one IP
REQUEST_ONE_IP=$(curl -k --header "Content-type: application/x-www-form-urlencoded" --header "token: ${TOKEN}" -X GET "${URL}/addresses/search/fd00:1e02:40::1/" 2>/dev/null | jq -r .data[].ip &>/dev/null)
# Return Code
RC=$?
# If IP not found in IPAM
if [ $RC -ne 0 ]
then
IPAM_CONFIG_CHECK_FAILED="${IPAM_CONFIG_CHECK_FAILED} ${ip_to_check} NOT FOUND in IPAM or problem with API connection ;"
echo -e "${RED}${ip_to_check} NOT FOUND in IPAM or problem with API connection : check KO${NC}\n"
# If IP found in IPAM
else
echo -e "${GREEN}${ip_to_check}FOUND in IPAM : check OK${NC}\n"
fi
done
fi
fi