Ejemplo n.º 1
0
    if mode == 'discovery':
        output = []
        for mof, name in datastores.items():
            output.append('{"{#ID}":"%s", "{#NAME}":"%s"}' % (mof, name))
        print '{ "data":['
        for i, v in enumerate(output):
            if i < len(output) - 1:
                print v + ','
            else:
                print v
        print ' ]}'

    if mode == 'data':
        #<hostname> <key> <timestamp> <value>
        #vc-cloud vmware.ds.capacity[datastore-397] 1366194015 1610344300544
        #vc-cloud vmware.ds.free[datastore-397] 1366194015 246725738496
        timestamp = int(time.time())

        def printDS(ds, key, value):
            print '%s vmware.ds.%s[%s] %d %s' % (vcenter, key, ds, timestamp,
                                                 value)

        for ds in server._get_object_properties_bulk(
                datastores.keys(),
            {'Datastore': ['summary.capacity', 'summary.freeSpace']}):
            printDS(ds.Obj, 'capacity', ds.PropSet[0].Val)
            printDS(ds.Obj, 'free', ds.PropSet[1].Val)
finally:
    server.disconnect()
Ejemplo n.º 2
0
      output.append( '{"{#ID}":"%s", "{#NAME}":"%s"}' % (mof, name) )
      
    print '{ "data":['
    for i, v in enumerate( output ):
      if i < len(output)-1:
        print v+','
      else:
        print v
    print ' ]}'

  if mode == 'time':
    #output time difference in zabbix_sender format:
    #<hostname> <key> <timestamp> <value>
    #vcenter vmware.host.timediff[host-1249] 1373876039 -1
        
    for x in server._get_object_properties_bulk( hosts.keys(), {'HostSystem':['configManager.dateTimeSystem']} ) :
      try:
        host_id = x.Obj
        host_name = hosts[x.Obj]
        hostDateTimeSystem = x.PropSet[0].Val #can throw AttributeError

        ''' call vSphere SDK HostDateTimeSystem.QueryDateTime() method '''
        dtReqClass = VI.QueryDateTimeRequestMsg()
        dtReq = dtReqClass.new__this(hostDateTimeSystem)
        dtReq.set_attribute_type(hostDateTimeSystem.get_attribute_type())
        dtReqClass.set_element__this(dtReq)

        timestamp = int(time.time()) #save local time at SDK call to compare with remote host
        res2 = server._proxy.QueryDateTime(dtReqClass)
        res = res2._returnval #get remote ESXi host time as time.struct_time tuple in a local timezone