Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

159682

August 29th, 2013 07:00

Create custom report per cluster

Hello,

We are using custom attributes on our vms for setting customer tag. I need to create a report with all clusters,the need is to know what is using by customer.

for example :

Cluster list
Cluster 1 total memory number cpu
customer 1 total memory for this customer total cpu for this customer
customer 2 total memory for this customer total cpu for this customer
Cluster 2 total memory number cpu
customer 1 total memory for this customer total cpu for this customer
customer 2 total memory for this customer total cpu for this customer

i know, ill need lots of request

I have the request get vm list for customer.

I'm working for the row table but i dont know how to handle the view ?

if someone have someting like that or can help, it will be a pleasure.

Thx

Davy,

171 Posts

September 12th, 2013 17:00

Here is the code, just change the attribute name to what your CA is and it will make the services for you and add VMs as they show up.  I run it once a month/week just to create new services if you add a new 'Business Unit' or 'Customer' etc...  From there, since it is a service it would be a lot easier to aggregate memory/cpu etc...

attributeName = "Business Unit";

ts = server.get("TopologyService");

def createOrUpdateObject(typeName, propertyValues) {

          def type = ts.getType(typeName);

          objShell = ts.getObjectShell(type);

          propertyValues.each ({propertyName, propertyValue ->

                    def prop = type.getProperty(propertyName);

                    if (!prop.isMany()) {

                              objShell.set(prop, propertyValue);

                    }

                    else if (propertyValue instanceof Collection) {

                              objShell.getList(prop).addAll(propertyValue);

                    }

                    else {

                              objShell.getList(prop).add(propertyValue);

                    }

          });

          return ts.mergeData(objShell);

}

// Find all attribute X values

values = [] as Set;

vmType = ts.getType("VMWVirtualMachine");

vms = ts.getObjectsOfType(vmType);

vms.each { vm ->

def custAtts = vm.get("customAttributes");

custAtts.each { ca->

          caName = ca.get("name");

          if(caName == attributeName)

          {

                    caValue = ca.get("value").trim();

                    if(caValue.length()>0)

                    {

                              values.add(caValue);

                    }

          }

}

}

// Create Services named value Y,Z,... attaching a DMC to each

valSvcs = [];

values.each { val->

// Create the service

valSvc = createOrUpdateObject("FSMService", [name:attributeName + " "+val]);

// Create the DMC

dmc = createOrUpdateObject("FSMDynamicManagedComponent",

                    [name:val+" container", container:valSvc,

                    componentQuery:"VMWVirtualMachine where customAttributes.name = '"+attributeName+"' and customAttributes.value = '"+val+"'",

                    queryConditions:"customAttributes.name = '"+attributeName+"' and customAttributes.value = '"+val+"'",

                    baseQuery:"/modules[fqId='system:virtualvmw']/queries[fqId='system:virtualvmw.581']"]);

//           Add the dynamic managed component to the service

valSvc = createOrUpdateObject("FSMService", [name:attributeName + " "+val, definition:[dmc]]);

valSvcs.add(valSvc);

}

// Create Service named attribute X

fsmAttService = createOrUpdateObject("FSMService", [name:(attributeName), definition:valSvcs]);

// Create Category

fsmCategory = createOrUpdateObject("FSMCategory", [name:"Attributes", definition:[fsmAttService]]);


171 Posts

August 29th, 2013 13:00

What would probably be the easiest way off the top of my head is to build a function/query that will grab all of the VMs and then count the custom attributes(CA) for each type (which is customer name in this case) and then from that list/count of VMs to get your resources utilizations or core/memory allocated counts. 

The alternative to that would be to build an array/map file that goes and does all of the work once and then use that to generate the table.  I'd say it's half a day of PSO or so either way.

August 29th, 2013 14:00

Thank you Bryant, i already have my request for vm list per CA

i have to continue.

If i can't do it ill look for PSO.

vfog.png

171 Posts

August 30th, 2013 01:00

How many VMs do you have in this environment and do you want this to be more of a report or a dashboard?  The reason I ask is if there are a lot of VMs it could take awhile to query this and we might be best served with a batch query to get what we need in one chunk and/or use a hash map.

August 30th, 2013 08:00

There is 1600 for 12 clusters, maybe ill dev the view by cluster.

September 12th, 2013 13:00

Do you know how can i get the custom attribute list per cluster ?

171 Posts

September 12th, 2013 15:00

It would take a bit of coding, but what might be easier is I have a script that will take all the custom attributes for a type (Say a CA called 'Customer Name) and then build a services from that list.  You could then take that and build your views from services.

September 12th, 2013 17:00

Thank you Bryant, i try it tomorrow at work.

I'll tell you the result

September 12th, 2013 17:00

thank you, your idea sounds cool, i can try your idea.

i did not learn how to script with groovy and vfog for the moment, i think it's the good moment

No Events found!

Top