One annoying thing about AnthillPro is that you need to do a lot of things manually that should already be automatic, leaving you to sift through a sea of beanshell bullsh-t. That being said, when you have an environment that has more then one agent / host in it. You probably don’t want to start a deployment to that environment if one or more of those agents are offline. If you do, you won’t know it till your deployment gets to an action connected to that offline agent. The answer, is to use a beanshell script to check if all agents in this environment (EnvironmentLookup.getCurrent()) are offline. If they are, we stop the deployment immediately. Along with this script, you will need to select a precondition for it that catches some text from commandOutput.println.

import com.urbancode.anthill3.domain.agent.*;
 import com.urbancode.anthill3.services.agent.AgentManager;
 import com.urbancode.anthill3.domain.servergroup.*;
 
 AgentFactory agentFactory = AgentFactory.getInstance();
 // get project environment group and pass to 
 Agent[] agentArray = agentFactory.restoreAll();
 ServerGroup env = ServerGroupFactory.getInstance().restoreForName(EnvironmentLookup.getCurrent().getName()); 
 
 for (z : agentArray){
 	if(env.containsServer(z)){
 		status = AgentManager.getInstance().getAgentStatus(z);
 		if (status == null || !status.isOnline()){
 			commandOutput.println(z.getName() + " is offline");
 		}else{
 			commandOutput.println(z.getName() + " is online");
                }
        }
 }