我正在尝试在 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 出来为空
无法猜测错误。