#!/usr/bin/env groovy import groovy.json.JsonSlurper /** * Displays the status of registered Spring Boot URL's. * To register URL's, create a file called healthcheck.txt in the following format * * , * * Eg: healthcheck.txt: * Grails Backend, http://localhost:9090/health * Spring Boot Backend, http://localhost:8080/health **/ def configuration = args ? new File(args[0]) : new File("healthcheck.txt") def RED='\u001B[31m' def GREEN='\u001B[32m' def YELLOW='\u001B[33m' def NC='\u001B[0m' // No Color configuration.eachLine { line -> def (name, url) = line.split(",") print "${YELLOW}${name.trim()}${NC}".padRight(30) print "- ${url.trim()} ".padRight(35) try { def text = new URL(url).text def json = new JsonSlurper().parseText(text) if(json.status == 'UP') { println "${GREEN}OK${NC}" } else { println "${RED}ERROR${NC}" } } catch(e) { println "${RED}ERROR${NC}" } }