vRO automated REST endpoint check

Use vRO action to check all configured REST endpoints in a automated fashion and receive a health state.
– gathering information of configured REST endpoints of vRO
– checking connectivity by telnet of each REST endpoint
– report state by eMail based on return value of check
– schedule Workflow for daily automated check and report

var systems = new Array();
var hosts = RESTHostManager.getHosts()
for(var hostId in hosts){   
    var system = {};
    var restHost = RESTHostManager.getHost(hosts[hostId]);
    var url = restHost.url.split("//")[1];
    system.name = restHost.name;
    system.url = url.split(":")[0];
    if(url.split(":")[1]!=null){
        system.port = url.split(":")[1];
    }else{
        if(restHost.url.split("://")[0]=="https"){
            system.port = "443";
        }
        if(restHost.url.split("://")[0]=="http"){
            system.port = "80";
        }
    }
    System.debug("Adding REST Host to check: "+system.name+", fqdn/ip: "+system.url+", port: "+system.port);
    systems.push(system);
} 

for each (var system in systems){
    System.debug("============== Checking System: "+system.name+" ==============");
    system.status = checkPort(system.name, system.url, system.port);
}

System.log(" ************** Status **************");
var generalCheckPassed = true;
for each (var system in systems){
    System.log("System: "+system.name+", CheckPassed: "+system.status);
    if(system.status == false){
        generalCheckPassed = false;
    }
}
return generalCheckPassed;


function checkPort(systemname, systemurl, systemport){
    try {
        // testing for port connectivity on target host
        System.debug("System: "+systemname+" - Trying to connect to port " + systemport + " on host  " + systemurl);
        var telnet = new TelnetClient("vt100") ;
        if(systemport != "undefined"){
            telnet.connect(systemurl, systemport);
        }else{
            telnet.connect(systemurl, "443");
        }
        connectionSuccess = telnet.isConnected();
        System.debug("System: "+systemname+" - Connectivity to target host " + systemurl + ":"+systemport+" is successful");
        return true;
    } catch (e) {
        connectionSuccess = telnet.isConnected();
        System.debug("Connection failed to "+systemname+": " + e);
        System.error("Failed to connect to System: "+systemname+", URL: "+systemurl+", Port: "+systemport);
        return false;
    } finally {
        telnet.disconnect()
    }
}