Skip to content

Commit

Permalink
Merge pull request #1096 from OpenNMS/HZN-925
Browse files Browse the repository at this point in the history
HZN-925: Add location to Configure SNMP page
  • Loading branch information
j-white committed Nov 2, 2016
2 parents d43507d + af4e035 commit cd66696
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,11 @@ public abstract class EventConstants {
*/
public static final String PARM_SNMP_WRITE_COMMUNITY_STRING = "writeCommunityString";

/**
* The SNMP write community string when sent as an event parm.
*/
public static final String PARM_SNMP_LOCATION = "location";

/**
* Service monitor qualifier when sent as an event parm
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public SnmpEventInfo(Event event) {
setFirstIPAddress(parmContent);
} else if (parmName.equals(EventConstants.PARM_LAST_IP_ADDRESS)) {
setLastIPAddress(parmContent);
} else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING) || parmName.equals(EventConstants.PARM_SNMP_READ_COMMUNITY_STRING)) {
} else if (parmName.equals(EventConstants.PARM_SNMP_LOCATION)) {
setLocation(parmContent);
} else if (parmName.equals(EventConstants.PARM_COMMUNITY_STRING)
|| parmName.equals(EventConstants.PARM_SNMP_READ_COMMUNITY_STRING)) {
setReadCommunityString(parmContent);
} else if (parmName.equals(EventConstants.PARM_SNMP_WRITE_COMMUNITY_STRING)) {
setWriteCommunityString(parmContent);
Expand Down Expand Up @@ -526,6 +529,7 @@ public Event createEvent(final String source) {
if (getTimeout() != 0) bldr.addParam(EventConstants.PARM_TIMEOUT, Integer.toString(getTimeout()));
if (!StringUtils.isEmpty(getVersion())) bldr.addParam(EventConstants.PARM_VERSION, getVersion());
if (!StringUtils.isEmpty(getWriteCommunityString())) bldr.addParam(EventConstants.PARM_SNMP_WRITE_COMMUNITY_STRING, getWriteCommunityString());
if (!StringUtils.isEmpty(getLocation())) bldr.addParam(EventConstants.PARM_SNMP_LOCATION, getLocation());

return bldr.getEvent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class SnmpInfo {
private Integer m_maxRequestSize;
private String m_writeCommunity;
private String m_proxyHost;
private String m_location;

/**
* <p>
Expand Down Expand Up @@ -99,7 +100,6 @@ public SnmpInfo(SnmpAgentConfig config) {
if (config.getMaxRepetitions() >= 1) m_maxRepetitions = config.getMaxRepetitions();
if (config.getMaxVarsPerPdu() >= 1) m_maxVarsPerPdu = config.getMaxVarsPerPdu();
if (config.getMaxRequestSize() >= 1) m_maxRequestSize = Integer.valueOf(config.getMaxRequestSize());

// handle a possible proxy host setting
if (config.getProxyFor() != null) { // switch proxy and address
m_proxyHost = InetAddressUtils.str(config.getAddress());
Expand Down Expand Up @@ -234,7 +234,22 @@ public void setTimeout(Integer timeout) {
m_timeout = timeout;
}

public String getSecurityName() {
/**
* @return the m_location
*/
public String getLocation() {
return m_location;
}

/**
* @param location the m_location to set
*/
public void setLocation(String location) {
this.m_location = location;
}


public String getSecurityName() {
return m_securityName;
}

Expand Down Expand Up @@ -429,6 +444,7 @@ public SnmpEventInfo createEventInfo(String firstIpAddress, String lastIpAddress
eventInfo.setPrivProtocol(m_privProtocol);
eventInfo.setSecurityName(m_securityName);
eventInfo.setProxyHost(m_proxyHost);
eventInfo.setLocation(m_location);
if (m_port != null) eventInfo.setPort(m_port.intValue());
if (m_retries != null) eventInfo.setRetryCount(m_retries.intValue());
if (m_timeout != null) eventInfo.setTimeout(m_timeout.intValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private void process(HttpServletRequest request, HttpServletResponse response) t
String firstIPAddress = request.getParameter("firstIPAddress");
String lastIPAddress = request.getParameter("lastIPAddress");
String ipAddress = request.getParameter("ipAddress");
String location = request.getParameter("location");
LOG.debug("doPost: snmpInfo:{}, firstIpAddress:{}, lastIpAddress:{}", snmpInfo.toString(), firstIPAddress, lastIPAddress);

final SnmpConfigServletAction action = determineAction(request);
Expand All @@ -113,8 +114,9 @@ private void process(HttpServletRequest request, HttpServletResponse response) t
case GetConfigForIp:
request.setAttribute("snmpConfigForIp",
new SnmpInfo(
SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(ipAddress))));
SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(ipAddress), location)));
request.setAttribute("firstIPAddress", ipAddress);
request.setAttribute("location", location);
break;
case Save:
boolean success = false;
Expand Down Expand Up @@ -179,6 +181,7 @@ private SnmpInfo createFromRequest(HttpServletRequest request) {
String maxVarsPerPdu = request.getParameter("maxVarsPerPdu");
String maxRepetitions = request.getParameter("maxRepetitions");
String proxyHost = request.getParameter("proxyHost");
String location = request.getParameter("location");

// v1/v2c specifics
String readCommunityString = request.getParameter("readCommunityString");
Expand Down Expand Up @@ -217,6 +220,7 @@ private SnmpInfo createFromRequest(HttpServletRequest request) {
if (!Strings.isNullOrEmpty(timeout)) snmpInfo.setTimeout(Integer.parseInt(timeout));
if (!Strings.isNullOrEmpty(version)) snmpInfo.setVersion(version);
if (!Strings.isNullOrEmpty(writeCommunityString)) snmpInfo.setWriteCommunity(writeCommunityString);
if (!Strings.isNullOrEmpty(location)) snmpInfo.setLocation(location);

return snmpInfo;
}
Expand Down
24 changes: 21 additions & 3 deletions opennms-webapp/src/main/webapp/admin/snmpConfig.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
String contextEngineId = getValue(snmpInfo.getContextEngineId());
String contextName = getValue(snmpInfo.getContextName());
String enterpriseId = getValue(snmpInfo.getEnterpriseId());
String location = getValue(request.getAttribute("location"));
%>


Expand Down Expand Up @@ -249,6 +250,14 @@ if (request.getAttribute("success") != null) {
<input type="text" class="form-control" name="ipAddress" id="lookup_ipAddress"/>
</div>
</div>
<div class="form-group">
<label for="lookup_location" class="control-label col-sm-3" data-toggle="tooltip" data-placement="right" title="Specify the location for which you want to lookup the SNMP configuration.">
Location
</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="location" id="lookup_location"/>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-2">
<button type="submit" class="btn btn-default" name="getConfig">Look up</button>
Expand All @@ -267,9 +276,9 @@ if (request.getAttribute("success") != null) {
<div class="panel-body">
<p>
<b>SNMP Config Lookup:</b> You can look up the actual SNMP
configuration for a specific IP. To do so enter the IP Address in the
SNMP Config Lookup box and press "Look up". The configuration will
then be shown in the "Updateing SNMP Community Names" area.
configuration for a specific IP and location. To do so enter the IP Address
and location in the SNMP Config Lookup box and press "Look up".
The configuration will then be shown in the "Updateing SNMP Community Names" area.
</p>

<p>
Expand Down Expand Up @@ -338,6 +347,15 @@ if (request.getAttribute("success") != null) {
</div>
</div>

<div class="form-group">
<label for="location" class="col-sm-3 control-label" data-toggle="tooltip" data-placement="right" title="Specify the location at which SNMP Config needs to be updated">
Location:
</label>
<div class="col-sm-9">
<input id="location" name="location" class="form-control" value="<%=location%>">
</div>
</div>

<div class="form-group">
<label for="timeout" class="col-sm-3 control-label" data-toggle="tooltip" data-placement="right" title="The amount of time, in milliseconds, that OpenNMS will wait for a response from the agent.">
Timeout:
Expand Down

0 comments on commit cd66696

Please sign in to comment.