9 years ago
VMware_vCenter_ObjectCount datasource modification
There's a datasource in the LM repository for VMware_vCenter_ObjectCount. It just pulled the static number of VMs (and other things) but it's useful to know how many are powered off vs powered on.
Attaching to help the community :)/emoticons/smile@2x.png 2x" title=":)" width="20">
<?xml version="1.0" encoding="UTF-8" ?> <feed version="1.0" hasPendingRequests="false" > <company></company> <status>200</status> <errmsg>OK</errmsg> <interval>0</interval> <entry type="predatasource"> <version>1457715177</version> <name>VMware_vCenter_ObjectCount</name> <displayedas>vCenter Object Count</displayedas> <description>number of VMs/Hosts/Datacenters/Networks servers attached to vCenter</description> <collector>script</collector> <hasMultiInstances>false</hasMultiInstances> <schedule>600</schedule> <appliesTo>system.virtualization =~ "VMware ESX vcenter"</appliesTo> <wildcardauto>false</wildcardauto> <wildcardpersist>false</wildcardpersist> <wildcardlinuxscript></wildcardlinuxscript> <wildcardlinuxcmdline></wildcardlinuxcmdline> <wildcardwinscript></wildcardwinscript> <wildcardwincmdline></wildcardwincmdline> <wildcardgroovyscript></wildcardgroovyscript> <wildcardschedule>1440</wildcardschedule> <wildcarddisable>false</wildcarddisable> <agdmethod>none</agdmethod> <agdparams></agdparams> <group></group> <tags></tags> <icon></icon> <technology></technology> <adlist><![CDATA[{"id":0,"agdmethod":"none","params":{},"agdparams":"","filters":[]}]]></adlist> <attributes> <attribute> <name>scripttype</name> <value>embed</value> <comment></comment> </attribute> <attribute> <name>scriptgroovy</name> <value>import java.util.*; import java.net.URL; import com.vmware.vim25.*; import com.vmware.vim25.mo.*; import com.santaba.agent.util.esx.EsxVcService; host = hostProps.get("system.hostname"); user = hostProps.get("esx.user"); pass = hostProps.get("esx.pass"); url = String.format("https://%s/sdk", host); svc = EsxVcService.connect(url, user, pass, 10 * 1000); // timeout in 10 seconds si = svc.getServiceInstance(); rootFolder = si.getRootFolder(); navigator = new InventoryNavigator(rootFolder); ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities(true); ManagedEntity[] ves = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); hostCount = 0; dcCount = 0; netCount = 0; vmCount = 0; dsCount = 0; vmOnCount = 0; vmOffCount = 0; ves.each { powerstate = it.getRuntime().getPowerState(); if (powerstate.toString().startsWith("poweredOn")) { vmOnCount++;} if (powerstate.toString().startsWith("poweredOff")) { vmOffCount++;} } for ( int i = 0; i < mes.length; i++) { if (mes.toString().startsWith("HostSystem:")) { hostCount++; } else if (mes.toString().startsWith("Datacenter:")) { dcCount++; } else if (mes.toString().startsWith("VirtualMachine:")) { vmCount++; } else if (mes.toString().startsWith("Datastore:")) { dsCount++; } else if (mes.toString().startsWith("Network:")) { netCount++; } } println "hosts: " + hostCount; println "vms: " + vmCount; println "datacenters: " + dcCount; println "datastores: " + dsCount; println "networks: " + netCount; println "vmsOn: " + vmOnCount; println "vmsOff: " + vmOffCount; return(0);</value> <comment></comment> </attribute> <attribute> <name>windowsscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>windowscmdline</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxcmdline</name> <value></value> <comment></comment> </attribute> </attributes> <datapoints> <datapoint> <name>esxHostCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>hosts</postprocessorparam> <usevalue>output</usevalue> <alertexpr>delta|> 0</alertexpr> <alertmissing>1</alertmissing> <alertsubject>##hostname## has had a change in connected ESXi hosts</alertsubject> <alertbody>The datapoint ##DATAPOINT##/##DATASOURCE## of ##INSTANCE## on ##HOST## is reporting ##LEVEL## as of ##START## The number of ESXi hosts managed by the vCenter server ##HOST## has changed to ##VALUE##, which is a change from its last polled value. Remediation Steps: - Check for corresponding "no data" alerts from the ESXi host that disconnected. - Check vCenter (##HOSTNAME##) for disconnected hosts. Note, this alert will clear fairly quickly, however this does not mean that the problem is resolved. This is due to this being a delta alert. The corresponding "no data" alert will clear only once the host has come back into service in vCenter.</alertbody> <description>number of ESX/vSphere hosts managed by this vCenter</description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>5</alertClearTransitionIval> </datapoint> <datapoint> <name>esxDatastoreCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>datastores</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody>The number of datastores managed by vCenter server ##HOST## has changed to ##VALUE##, which is a change from its last polled value. Consider investigating vSphere server health if this wasn't an anticipated change. This started at ##START## -- or ##DURATION## ago.</alertbody> <description>number of datastores managed by this vCenter</description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> <datapoint> <name>esxNetCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>networks</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody>The number of virtual networks managed by vCenter server ##HOST## has changed to ##VALUE##, which is a change from its last polled value. Consider investigating vSphere server health if this wasn't an anticipated change. This started at ##START## -- or ##DURATION## ago.</alertbody> <description>number of networks managed by this vCenter</description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> <datapoint> <name>esxVmCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>vms</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody>The number of VMs managed by vCenter server ##HOST## has changed to ##VALUE##, which is a change from its last polled value. Consider investigating vSphere server health if this wasn't an anticipated change. This started at ##START## -- or ##DURATION## ago.</alertbody> <description>number of VMs managed by this vCenter</description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> <datapoint> <name>esxVmOffCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>vmsOff</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <description></description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> <datapoint> <name>esxVmOnCount</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>vmsOn</postprocessorparam> <usevalue>output</usevalue> <alertexpr>delta|> 0</alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody>The number of powered on virtual machines managed by this vCenter server ##HOST## has changed to ##VALUE##, which is a change from its last polled value. This started at ##START##.</alertbody> <description></description> <maxvalue></maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>1</alertClearTransitionIval> </datapoint> </datapoints> <graphs> <graph> <name>Object Count</name> <title>Object Count</title> <verticallabel>#</verticallabel> <rigid>true</rigid> <maxvalue>NaN</maxvalue> <minvalue>0.0</minvalue> <displayprio>1</displayprio> <timescale>1day</timescale> <base1024>false</base1024> <graphdatapoints> <graphdatapoint> <name>esxDatastoreCount</name> <datapointname>esxDatastoreCount</datapointname> <cf>1</cf> </graphdatapoint> <graphdatapoint> <name>esxHostCount</name> <datapointname>esxHostCount</datapointname> <cf>1</cf> </graphdatapoint> <graphdatapoint> <name>esxNetCount</name> <datapointname>esxNetCount</datapointname> <cf>1</cf> </graphdatapoint> <graphdatapoint> <name>esxVmCount</name> <datapointname>esxVmCount</datapointname> <cf>1</cf> </graphdatapoint> </graphdatapoints> <graphvirtualdatapoints> </graphvirtualdatapoints> <graphdatas> <graphdata> <type>1</type> <legend>Hosts</legend> <color>blue</color> <datapointname>esxHostCount</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>Datastores</legend> <color>orange</color> <datapointname>esxDatastoreCount</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>Virtual Networks</legend> <color>purple</color> <datapointname>esxNetCount</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>VMs</legend> <color>green</color> <datapointname>esxVmCount</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> </graphdatas> </graph> </graphs> <overviewgraphs> </overviewgraphs> </entry> </feed>