vFoglight Purge Stale Objects (Groovy Script)

Using the script editor located in Administration > Tooling > Script Console. Best to go ahead and save these for running at a later date when you need them. On line "10" you can enter the number of days to go back to remove the script below will purge objects "30" days old. Also on line "17" you can show the items to purge instead of deleting them.

// Script Purpose: Remove Stale Objects from vFoglight Database
// Script Platform: Foglight Managment Servers running on Windows or Linux
// Script Created by: chris.walker@quest.com
// Script Last Updated: 10.13.2011 
// Script Version: 11.10.13
// Please see PDF documentation that should have come with this script for usage information
// Note: The script formating was compressed to save page space in the PDF. Sorry this does make it harder to read.

// Modify the line below to change the number of days
staleDays='30';// Exmple: Deleted object with stale data that is older than "30" days
// Set these to 1 if you want to delete the stale data in the respected topology type list
//   Set to 0 if you do not want to delete the data
VMWare=1; // VMWare Data
GPI=1; // Guest Process Investigation Data
OSTypes=1; // OS Topology Types Used by vFoglight - Physical Disk
// If you just want to view a list of object that should be purged change this flag to 0. Set to 1 to actually purge data
PurgeData=0;

// Following is a list of vFoglight Topology Objects that will be purged of stale data
VMwareList = ['VMWVirtualMachine', 'VMWVirtualMachineHostCPUs', 'VMWVirtualMachineMemory', 'VMWVirtualMachineHostNetwork', 'VMWVirtualMachineNetworkInterface', 'VMWVMDiskLayout', 'VMWVirtualCenter', 'VMWDatastore', 'VMWESXServer', 'VMWESXServerPhysicalDisk', 'VMWCluster', 'VMWDatacenter', 'VMWAgent', 'VMWVirtualMachineLogicalDisk', 'VMWVirtualMachineHostStorage', 'VMWSnapshot', 'VMWSnapshotDiskInfo', 'VMWSnapshotFolder', 'VMWResourcePool'];
// Following is a list of Guest Process Topology Objects that will be purged of stale data
GPIList=['GuestProcessModel', 'GuestProcessAgent', 'GuestProcessDefaultAgentConfig'];
// Following is a list of Physical Topology Objects that are used by vFoglight and will be purged of stale data
OSList=['Host', 'HostCPUs', 'HostNetwork', 'HostStorage', 'IPAddress', 'LogicalDisk', 'PhysicalDisk', 'Processor', 'NetworkInterface', 'Memory'];
// Function used to purge data
def purgeStale(TopoName, staleAge, Purge) {
  def dataSvc = server.get("DataService");
  def topSvc = server.get("TopologyService");
  def objects = server.get("QueryService").queryTopologyObjects(TopoName);
  def staleTime = System.currentTimeMillis() - (staleAge.toInteger() * 24 * 60 * 60 * 1000L);
  def staleObjects = [];
  objects.each({ if (it.lastUpdated.time < staleTime) staleObjects << it });
  // Print stale Oject List to Log
  print "Stale objects:";
  for (obj in staleObjects) {
   print obj.longName + " " + obj.lastUpdated;}
  // Delete the objects if PurgeData Flag is set
  if (Purge==1) {
    def batchSize = 100;
    def idx = 0;
    while (idx < staleObjects.size()) {
     def endPos = Math.min(idx + batchSize, staleObjects.size());
     def batch = staleObjects.subList(idx, endPos);
     topSvc.deleteObjects(new HashSet(batch));
     idx = endPos;}
    print "*** Successfully Purged: " + staleObjects.size() + " stale objects. ***";} 
  else {
    print "*** No objects Purged (use PurgeData flage in script to actually purge objects) ***";
    print "*** Number of Stale Objects Identified but not Purged: " + staleObjects.size() + " ***";}
}// End purgeStale Function
// Start of Code to loop through Topology Types
// Put info in the FMS Log File
print "** Start VFDelete-stale.groovy script v11.10.13 **";
// Purge Stale Data for Foglight VMWare Cartridge
if (VMWare==1) {
  print "* Processing VMware Topology Objects"
  // Loop through each of the Topology Types
  for (Topo in VMwareList) {
    print "Removing Stale Objects for Topology: " + Topo;
    purgeStale(Topo, staleDays, PurgeData);}
}
// Purge Stale Data for Foglight Guest Process Investigation (GPI) Cartridge
if (GPI==1) {
  print "* Processing GPI Topology Objects";
  // Loop through each of the Topology Types
  for (Topo in GPIList){
    print "Removing Stale Objects for Topology: " + Topo;
    purgeStale(Topo, staleDays, PurgeData);}
}
if (OSTypes==1){
  print "* Processing OS Topology Objects";
  // Loop through each of the Topology Types
  for (Topo in OSList){
    print "Removing Stale Objects for Topology: " + Topo;
    purgeStale(Topo, staleDays, PurgeData);}
}
print "** Finished Run of VFDelete-stale.groovy script v11.10.13 **";
return "Done...";

Comments

Popular posts from this blog

Brocade Zone Setup

OpenSolaris ZFS Setup

Console over SSH (ONTAP)