Forum Discussion
Michael_Baker
Neophyte
3 years agoRound 2 this is much faster:
<?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>1641510208</version> <name>VMware_vCenter_Check_If_ISO_Mounted</name> <displayedas>VMWAre VM Check If ISO Mounted</displayedas> <description>Detect possible CVE</description> <collector>batchscript</collector> <hasMultiInstances>true</hasMultiInstances> <useWildValueAsUniqueIdentifier>false</useWildValueAsUniqueIdentifier> <schedule>120</schedule> <appliesTo>system.virtualization =~ "VMware ESX vcenter"</appliesTo> <wildcardauto>true</wildcardauto> <wildcardpersist>false</wildcardpersist> <wildcardlinuxscript>ad_script</wildcardlinuxscript> <wildcardlinuxcmdline>type="embeded" </wildcardlinuxcmdline> <wildcardwinscript>ad_script</wildcardwinscript> <wildcardwincmdline>type="embeded" </wildcardwincmdline> <wildcardgroovyscript>/******************************************************************************* * © 2007-2019 - LogicMonitor, Inc. All rights reserved. ******************************************************************************/ import com.vmware.vim25.*; import com.vmware.vim25.mo.*; import java.security.cert.*; import org.apache.http.auth.*; import org.apache.http.conn.ssl.*; import org.apache.http.impl.client.*; import org.apache.http.util.EntityUtils; import org.apache.http.client.methods.HttpGet; import com.santaba.agent.groovyapi.esx.ESX import groovy.json.JsonSlurper; def host = hostProps.get("system.hostname") def user = hostProps.get("esx.user"); def pass = hostProps.get("esx.pass"); def addr = hostProps.get("esx.url") ?: "https://${host}/sdk"; def keyNamespace = hostProps.get(hostProps.get("topo.namespace", ""), "") def keyBlacklist = hostProps.get("topo.blacklist", "").tokenize(",") // Open a connection to the vSphere API, get a service instance and root folder def svc = new ESX(); svc.open(addr, user, pass, 10 * 1000); // timeout in 10 seconds def si = svc.getServiceInstance(); def rootFolder = si.getRootFolder(); // Get VMs def vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); // Get ESX Hosts def hostsystems = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem") // iterate over vms vms.each { vm -> // Get AD info def wildvalue = vm.MOR.val; def wildalias = vm.name; def config = vm.config.hardware.device for(dev in config) { if(dev instanceof com.vmware.vim25.VirtualCdrom) { if(dev.backing instanceof com.vmware.vim25.VirtualCdromIsoBackingInfo) { if(dev.connectable.connected) { println "${wildvalue}##${wildalias}"; } } } } } return 0 </wildcardgroovyscript> <wildcardschedule>60</wildcardschedule> <wildcarddisable>false</wildcarddisable> <wildcarddeleteinactive>false</wildcarddeleteinactive> <agdmethod>none</agdmethod> <agdparams></agdparams> <group></group> <tags>application,vsphere,virtualization,vm,vmware</tags> <technology>:: replaces old ESX_VM_Status :: - define esx.user and esx.pass for authentication - optionally override vSphere API URL with esx.url property - optionally enable vSphere Tags -> instance level properties by setting esx.tags to "true" (vCenter only) - url-encode ILPs that are strings in AD script</technology> <adlist><![CDATA[{"agdmethod":"none","method":"ad_script","agdparams":"","id":0,"filters":[],"params":{"type":"embeded","groovyscript":"/*******************************************************************************\n * © 2007-2019 - LogicMonitor, Inc. All rights reserved.\n ******************************************************************************/\n\nimport com.vmware.vim25.*;\nimport com.vmware.vim25.mo.*;\nimport java.security.cert.*;\nimport org.apache.http.auth.*;\nimport org.apache.http.conn.ssl.*;\nimport org.apache.http.impl.client.*;\nimport org.apache.http.util.EntityUtils;\nimport org.apache.http.client.methods.HttpGet;\nimport com.santaba.agent.groovyapi.esx.ESX\nimport groovy.json.JsonSlurper;\n\ndef host = hostProps.get(\"system.hostname\")\ndef user = hostProps.get(\"esx.user\");\ndef pass = hostProps.get(\"esx.pass\");\ndef addr = hostProps.get(\"esx.url\") ?: \"https://${host}/sdk\";\ndef keyNamespace = hostProps.get(hostProps.get(\"topo.namespace\", \"\"), \"\")\ndef keyBlacklist = hostProps.get(\"topo.blacklist\", \"\").tokenize(\",\")\n\n// Open a connection to the vSphere API, get a service instance and root folder\n\ndef svc = new ESX();\nsvc.open(addr, user, pass, 10 * 1000); // timeout in 10 seconds\n\ndef si = svc.getServiceInstance();\ndef rootFolder = si.getRootFolder();\n\n// Get VMs\ndef vms = new InventoryNavigator(rootFolder).searchManagedEntities(\"VirtualMachine\");\n\n// Get ESX Hosts\ndef hostsystems = new InventoryNavigator(rootFolder).searchManagedEntities(\"HostSystem\")\n\n// iterate over vms\nvms.each { vm ->\n\n // Get AD info\n def wildvalue = vm.MOR.val;\n def wildalias = vm.name;\n def config = vm.config.hardware.device\n for(dev in config)\n {\n if(dev instanceof com.vmware.vim25.VirtualCdrom) {\n if(dev.backing instanceof com.vmware.vim25.VirtualCdromIsoBackingInfo) {\n if(dev.connectable.connected) {\n println \"${wildvalue}##${wildalias}\";\n }\n }\n }\n }\n}\n\nreturn 0\n"}}]]></adlist> <schemaVersion>2</schemaVersion> <dataSourceType>1</dataSourceType> <attributes> <attribute> <name>scripttype</name> <value>embed</value> <comment></comment> </attribute> <attribute> <name>scriptgroovy</name> <value>import com.vmware.vim25.mo.*; import com.santaba.agent.groovyapi.esx.ESX; def host = hostProps.get("system.hostname") def user = hostProps.get("esx.user"); def pass = hostProps.get("esx.pass"); def addr = hostProps.get("esx.url") ?: "https://${host}/sdk"; def svc = new ESX(); svc.open(addr, user, pass, 10 * 1000); // timeout in 10 seconds def si = svc.getServiceInstance(); def rootFolder = si.getRootFolder(); def vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); vms.each { vm -> def wildvalue = vm.MOR.val; def config = vm.config.hardware.device for(dev in config) { if(dev instanceof com.vmware.vim25.VirtualCdrom) { if(dev.backing instanceof com.vmware.vim25.VirtualCdromIsoBackingInfo) { if(dev.connectable.connected) { println "${wildvalue}.isoconnected=1"; } } } } } 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> <attribute> <name>eridetectioninterval</name> <value>60</value> <comment></comment> </attribute> <attribute> <name>eriscripttype</name> <value>embeded</value> <comment></comment> </attribute> <attribute> <name>eriscriptgroovy</name> <value>import com.santaba.agent.util.esx.EsxVcService import com.vmware.vim25.VirtualDisk import com.vmware.vim25.mo.Folder import com.vmware.vim25.mo.InventoryNavigator import com.vmware.vim25.mo.ManagedEntity import com.vmware.vim25.VirtualEthernetCard import com.vmware.vim25.VirtualDevice import groovy.json.JsonSlurper import org.apache.http.auth.AuthScope import org.apache.http.auth.UsernamePasswordCredentials import org.apache.http.client.methods.HttpGet import org.apache.http.conn.ssl.AllowAllHostnameVerifier import org.apache.http.conn.ssl.SSLContexts import org.apache.http.conn.ssl.TrustStrategy import org.apache.http.impl.client.BasicCredentialsProvider import org.apache.http.impl.client.HttpClients import org.apache.http.impl.client.LaxRedirectStrategy import org.apache.http.util.EntityUtils import java.security.cert.CertificateException import java.security.cert.X509Certificate def host = hostProps.get("system.hostname") def user = hostProps.get("esx.user"); def pass = hostProps.get("esx.pass"); def custom_url = hostProps.get("esx.url"); def vmMorVal = instanceProps.get("wildvalue"); def vmName = instanceProps.get("wildalias"); def eri = host+"--"+vmMorVal; def ExternalResourceIDs = [eri] // Open a connection to the vSphere API, get a service instance and root folder def url = custom_url ?: String.format("https://%s/sdk", host); def svc = EsxVcService.connect(url, user, pass, 10 * 1000); // timeout in 10 seconds def si = svc.getServiceInstance(); def rootFolder = si.getRootFolder(); ManagedEntity[] vms; // Get VMs vms = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); // iterate over vms vms.each { vm -> // Get AD info def aVMMorVal = vm.MOR.val def aVMName = vm.name if(aVMMorVal == vmMorVal) { for (VirtualDevice vd : vm.getConfig().getHardware().getDevice()) { try { if (vd instanceof VirtualEthernetCard) { VirtualEthernetCard vEth = (VirtualEthernetCard) vd; ExternalResourceIDs += vEth.macAddress; } } catch (Exception e) { } } } } println "predef.externalResourceID=" + ExternalResourceIDs.join(","); println "predef.externalResourceType=" + "VirtualMachine" return 0;</value> <comment></comment> </attribute> <attribute> <name>eriwinscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>erilinuxscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>eriwincmdline</name> <value></value> <comment></comment> </attribute> <attribute> <name>erilinuxcmdline</name> <value></value> <comment></comment> </attribute> </attributes> <datapoints> <datapoint> <name>isoconnected</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>isconnected</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <enableanomalyalertsuppression></enableanomalyalertsuppression> <adadvsettingenabled>false</adadvsettingenabled> <warnadadvsetting></warnadadvsetting> <erroradadvsetting></erroradadvsetting> <criticaladadvsetting></criticaladadvsetting> <description></description> <maxvalue>1</maxvalue> <minvalue>0</minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>0</alertTransitionIval> <alertClearTransitionIval>0</alertClearTransitionIval> </datapoint> </datapoints> <graphs> </graphs> <overviewgraphs> </overviewgraphs> <scripts> </scripts> </entry> </feed>
Related Content
- 7 months ago
- 7 months ago