Currently Being Moderated
In case this might help others, The following are two groovey scripts I hacked together to solve my problem of deleting all of the monitored resources that appear to be 'down' because they were moved to a different server or they no longer exist. I took the approach of saying anything that is listed as being down for a week is most likely no longer a valid resource to monitor.
Here is my script to return the numbers of Resouces based on how long they have been down.
<code>
import org.hyperic.hq.measurement.server.session.AvailabilityManagerEJBImpl as AvailabilityManager
import org.hyperic.hq.appdef.shared.AppdefEntityID
import org.hyperic.hq.authz.server.session.AuthzSubject
// get the availability manager and a list of unavailable resources.
def availManager = AvailabilityManager.one;
def unavailEntities = availManager.getUnavailEntities(null);
// get all the resources that have been down for 30 days worth of milliseconds (2592000000 )
def entitiesToDelByMonth = unavailEntities.findAll { it.getDuration() > 2592000000 };
// get all the resources that have been down for 2 weeks worth of milliseconds (1209600000)
def entitiesToDelByTwoWeeks = unavailEntities.findAll { it.getDuration() > 1209600000};
// get all the resources that have been down for 1 week worth of milliseconds (604800000)
def entitiesToDelByOneWeek = unavailEntities.findAll { it.getDuration() > 604800000};
return "Total Unavailable Resources:" + unavailEntities.size() +
", Resources down for the past month:" + entitiesToDelByMonth .size() +
", Resources down for the past two weeks:" + entitiesToDelByTwoWeeks .size() +
", Resources down for the past week:" + entitiesToDelByOneWeek.size();
"/code>
Here is my script to actually delete the Resources.
<code>
import org.hyperic.hq.hqu.rendit.util.HQUtil
import org.hyperic.hq.measurement.server.session.AvailabilityManagerEJBImpl as AvailabilityManager
import org.hyperic.hq.authz.server.session.ResourceManagerEJBImpl as ResMan
import org.hyperic.hq.appdef.shared.AppdefEntityID
import org.hyperic.hq.authz.server.session.AuthzSubject
// get the root user.
def overlord = HQUtil.overlord;
// get the services we are invoking.
def availManager = AvailabilityManager.one;
def resMan = ResMan.one;
// Get a list of all the unavailable resource measurements.
def unavailEntities = availManager.getUnavailEntities(null);
// create a list of entities that are down for at least 2 weeks, 1209600000 is 2 weeks of milliseconds.
def entitiesToDel = unavailEntities.findAll { it.getDuration() > 1209600000};
// convert this list to a list of entitiy Ids.
def idsToDel = entitiesToDel.collect{ it.getEntityId() };
// break the entitiy ids into 1000 groups. (change this based on total number of entities // being deleted. About 5 entries per group seems to be the sweet spot.
int counter = 0;
def groupsOfIdsToDel = idsToDel.groupBy { counter++ % 1000};
// delete each group.
groupsOfIdsToDel.values().each
{
AppdefEntityID[] toRemove = new AppdefEntityID[it.size()];
for(def i=0; i<it.size(); i++){
toRemove[ i ] = it[i];
}
resMan.removeResources(overlord,toRemove);
};
</code>
Mirrko if you think there belong on the wiki or if they are a bad idea / bad practice please let me know. I basically learned groovey to write these so I am sure they aren't the 'best' way to do things but they work (ever so slowly).