0

我正在尝试在 ESX-i 服务器上配置 snmp。为此,我正在使用 VI Java api。为此,我正在使用最近的 vi jars。这是代码。

import java.net.URL;

import com.vmware.vim25.HostSnmpConfigSpec;
import com.vmware.vim25.HostSnmpDestination;
import com.vmware.vim25.mo.Folder;
import com.vmware.vim25.mo.HostSnmpSystem;
import com.vmware.vim25.mo.HostSystem;
import com.vmware.vim25.mo.InventoryNavigator;
import com.vmware.vim25.mo.ServiceInstance;

public class ConfigureSnmpSystem
{

    private static final String URL_VCENTER = "https://10.118.67.36/sdk";
    private static final String username = "Admin";
    private static final String password = "passwd";
    public static void main(String[] args) throws Exception {

    ServiceInstance si = new ServiceInstance(new URL(URL_VCENTER), username,
            password, true);

    String hostname = "10.108.30.12"; // this is the ip address of esx-i server
    Folder rootFolder = si.getRootFolder();
    HostSystem host = null;
    host = (HostSystem) new InventoryNavigator(rootFolder)
            .searchManagedEntity("HostSystem", hostname);

    if (host == null) {
        System.out.println("Cannot find the host:" + hostname);
        si.getServerConnection().logout();
        return;
    }

    HostSnmpSystem hss = host.getHostSnmpSystem();

    HostSnmpConfigSpec spec = new HostSnmpConfigSpec();
    spec.setEnabled(true);
    spec.setReadOnlyCommunities(new String[] { "visdk" });
    HostSnmpDestination dest = new HostSnmpDestination();
    dest.setCommunity("visdk");
    dest.setHostName("10.108.67.46");
    dest.setPort(162);
    spec.setTrapTargets(new HostSnmpDestination[] { dest });

    hss.reconfigureSnmpAgent(spec);
    si.getServerConnection().logout();
}
}

错误来HostSnmpSystem hss = host.getHostSnmpSystem(); 了 hss 出来为空

无法猜测错误。

4

1 回答 1

0

vCenter Server 尚不支持配置每个 ESX (hostSystem) snmp。我认为这应该最终在 5.5 IIRC 中可用。

另请注意,由于 ESX 5.1 现在支持 SNMPv3,尽管它使用 'esxcli system snmp set|get' cmds 进行配置,但 VIM API 仅支持 SNMPv1。

于 2013-10-30T04:45:45.373 回答