a010cad61fabd54234ca5057f114c3a5c40486a7
1 package org
.netxms
.ui
.eclipse
.snmp
.views
.helpers
;
3 import java
.io
.IOException
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Arrays
;
8 import org
.netxms
.client
.NXCException
;
9 import org
.netxms
.client
.NXCSession
;
10 import org
.netxms
.client
.server
.ServerVariable
;
11 import org
.netxms
.client
.snmp
.SnmpUsmCredential
;
13 public class SnmpConfig
15 private List
<String
> communities
;
16 private List
<SnmpUsmCredential
> usmCredentials
;
17 private List
<String
> ports
;
27 * Load SNMP configuration from server. This method directly calls
28 * communication API, so it should not be called from UI thread.
30 * @param session communication session to use
31 * @return SNMP configuration
32 * @throws IOException if socket I/O error occurs
33 * @throws NXCException if NetXMS server returns an error or operation was timed out
35 public static SnmpConfig
load(NXCSession session
) throws NXCException
, IOException
37 SnmpConfig config
= new SnmpConfig();
39 config
.communities
= session
.getSnmpCommunities();
40 config
.usmCredentials
= session
.getSnmpUsmCredentials();
41 Map
<String
, ServerVariable
> variables
= session
.getServerVariables();
42 ServerVariable v
= variables
.get("SNMPPorts"); //$NON-NLS-1$
43 config
.ports
= parsePorts(v
!= null ? v
.getValue() : "" ); //$NON-NLS-1$
52 public static List
<String
> parsePorts(String portList
)
54 String
[] arr
= portList
.split(","); //$NON-NLS-1$
55 List
<String
> list
= new ArrayList
<String
>(Arrays
.asList(arr
));
59 public String
parsePorts()
61 StringBuilder str
= new StringBuilder();
62 for(int i
= 0; i
< ports
.size(); i
++)
64 str
.append(ports
.get(i
));
65 if(i
!= ports
.size() - 1)
67 str
.append(","); //$NON-NLS-1$
70 return str
.toString();
73 * Save SNMP configuration on server. This method calls communication
74 * API directly, so it should not be called from UI thread.
76 * @params session communication session to use
77 * @throws IOException if socket I/O error occurs
78 * @throws NXCException if NetXMS server returns an error or operation was timed out
80 public void save(NXCSession session
) throws NXCException
, IOException
82 session
.updateSnmpCommunities(communities
);
83 session
.updateSnmpUsmCredentials(usmCredentials
);
84 session
.setServerVariable("SNMPPorts", parsePorts()); //$NON-NLS-1$
88 * @return the communities
90 public List
<String
> getCommunities()
96 * @param communities the communities to set
98 public void setCommunities(List
<String
> communities
)
100 this.communities
= communities
;
106 public List
<String
> getPorts()
112 * @param communities the communities to set
114 public void setPorts(List
<String
> ports
)
120 * @return the usmCredentials
122 public List
<SnmpUsmCredential
> getUsmCredentials()
124 return usmCredentials
;
128 * @param usmCredentials the usmCredentials to set
130 public void setUsmCredentials(List
<SnmpUsmCredential
> usmCredentials
)
132 this.usmCredentials
= usmCredentials
;