use of org.opennms.rancid.RancidApiException in project opennms by OpenNMS.
the class InventoryReportCalculator method getNodeBaseInventory.
/**
* <p>getNodeBaseInventory</p>
*
* @param node a {@link java.lang.String} object.
* @param group a {@link java.lang.String} object.
* @param version a {@link java.lang.String} object.
* @return a {@link org.opennms.report.inventory.NodeBaseInventory} object.
*/
public NodeBaseInventory getNodeBaseInventory(String node, String group, String version) {
// get the latest version from the given date
LOG.debug("getNodeBaseInventory {} {} {}", node, group, version);
NodeBaseInventory nbi = new NodeBaseInventory();
RancidNode rn;
try {
rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, group, node);
} catch (RancidApiException e) {
LOG.debug("getNodeBaseInventory: inventory not found. Skipping");
return nbi;
}
InventoryNode in = (InventoryNode) rn.getNodeVersions().get(version);
nbi.setDevicename(node);
nbi.setGroupname(group);
nbi.setVersion(version);
nbi.setStatus(in.getParent().getState());
nbi.setCreationdate(in.getCreationDate());
nbi.setSwconfigurationurl(in.getSoftwareImageUrl());
nbi.setConfigurationurl(in.getConfigurationUrl());
try {
nbi.setIe(RWSClientApi.getRWSRancidNodeInventoryElement2(m_cp, rn, version));
} catch (RancidApiException e) {
LOG.debug("getNodeBaseInventory: inventory not found for version: {}. Skipping", version);
}
return nbi;
}
use of org.opennms.rancid.RancidApiException in project opennms by OpenNMS.
the class InventoryService method getRancidNodeWithCLogin.
/*
* getRancidNodeWithClogin will filter any exception, the page will show an empty table
* in case of node not in DB or device name not in RWS
*/
/**
* <p>getRancidNodeWithCLogin</p>
*
* @param nodeid a int.
* @param adminRole a boolean.
* @return a java$util$Map object.
*/
public Map<String, Object> getRancidNodeWithCLogin(int nodeid, boolean adminRole) {
LOG.debug("getRancidNodeWithClogin start");
Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
String rancidName = (String) nodeModel.get("id");
// Group list
RWSResourceList groups;
try {
groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
List<String> grouplist = groups.getResource();
nodeModel.put("grouplist", grouplist);
Iterator<String> iter1 = grouplist.iterator();
String groupname;
while (iter1.hasNext()) {
groupname = iter1.next();
nodeModel.put("groupname", groupname);
LOG.debug("getRancidNodeWithClogin {} group {}", rancidName, groupname);
try {
RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, groupname, rancidName);
nodeModel.put("devicename", rn.getDeviceName());
nodeModel.put("status", rn.getState());
nodeModel.put("devicetype", rn.getDeviceType());
nodeModel.put("comment", rn.getComment());
nodeModel.put("deviceexist", true);
break;
} catch (RancidApiException e) {
if (e.getRancidCode() == 2) {
nodeModel.put("deviceexist", false);
LOG.debug("No device found in router.db for:{}on Group: {}", rancidName, groupname);
} else {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
}
}
// DeviceType list
RWSResourceList devicetypes;
try {
devicetypes = RWSClientApi.getRWSResourceDeviceTypesPatternList(m_cp);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
List<String> devicetypelist = devicetypes.getResource();
nodeModel.put("devicetypelist", devicetypelist);
//CLOGIN
if (adminRole) {
LOG.debug("getRancidNode: getting clogin info for: {}", rancidName);
RancidNodeAuthentication rn5;
try {
rn5 = RWSClientApi.getRWSAuthNode(m_cp, rancidName);
nodeModel.put("isadmin", "true");
nodeModel.put("cloginuser", rn5.getUser());
nodeModel.put("cloginpassword", rn5.getPassword());
nodeModel.put("cloginconnmethod", rn5.getConnectionMethodString());
nodeModel.put("cloginenablepass", rn5.getEnablePass());
String autoen = "0";
if (rn5.isAutoEnable()) {
autoen = "1";
}
nodeModel.put("cloginautoenable", autoen);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error("getRancidNode: clogin get failed with reason: {}", e.getLocalizedMessage());
}
}
return nodeModel;
}
use of org.opennms.rancid.RancidApiException in project opennms by OpenNMS.
the class InventoryService method getRancidNodeList.
/**
* <p>getRancidNodeList</p>
*
* @param nodeid a int.
* @return a java$util$Map object.
*/
public Map<String, Object> getRancidNodeList(int nodeid) {
LOG.debug("getRancidNodelist start: nodeid: {}", nodeid);
Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
String rancidName = (String) nodeModel.get("id");
RWSResourceList groups;
try {
groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
List<InventoryWrapper> ranlist = new ArrayList<InventoryWrapper>();
List<String> grouplist = groups.getResource();
Iterator<String> iter2 = grouplist.iterator();
boolean first = true;
String groupname;
while (iter2.hasNext()) {
groupname = iter2.next();
RancidNode rn;
try {
rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, groupname, rancidName);
if (first) {
nodeModel.put("devicename", rn.getDeviceName());
first = false;
}
RWSResourceList versionList = RWSClientApi.getRWSResourceConfigList(m_cp, groupname, rancidName);
List<String> versionListStr = versionList.getResource();
Iterator<String> iter1 = versionListStr.iterator();
String vs;
while (iter1.hasNext()) {
vs = iter1.next();
InventoryNode in = (InventoryNode) rn.getNodeVersions().get(vs);
InventoryWrapper inwr = new InventoryWrapper(in.getVersionId(), in.getCreationDate(), groupname, in.getConfigurationUrl());
ranlist.add(inwr);
}
} catch (RancidApiException e) {
if (e.getRancidCode() == 2) {
LOG.debug("No Inventory found in CVS repository for nodeid:{} nodeLabel: {}", nodeid, rancidName);
} else {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
}
}
}
nodeModel.put("grouptable", ranlist);
return nodeModel;
}
use of org.opennms.rancid.RancidApiException in project opennms by OpenNMS.
the class InventoryService method checkRancidNode.
/**
* <p>checkRancidNode</p>
*
* @param deviceName a {@link java.lang.String} object.
* @return a boolean.
*/
public boolean checkRancidNode(String deviceName) {
LOG.debug("checkRancidNode start {}", deviceName);
// Group list
try {
RWSResourceList groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
List<String> grouplist = groups.getResource();
Iterator<String> iter1 = grouplist.iterator();
if (iter1.hasNext()) {
String groupname = iter1.next();
LOG.debug("checkRancidNode {} group {}", deviceName, groupname);
try {
RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, groupname, deviceName);
if (rn != null) {
return true;
} else {
return false;
}
} catch (RancidApiException e) {
LOG.debug("No inventory information associated to {}", deviceName);
return false;
}
}
} catch (Throwable e) {
return false;
}
return true;
}
use of org.opennms.rancid.RancidApiException in project opennms by OpenNMS.
the class InventoryService method getRancidNodeWithCLoginForGroup.
/**
* <p>getRancidNodeWithCLoginForGroup</p>
*
* @param nodeid a int.
* @param group a {@link java.lang.String} object.
* @param adminRole a boolean.
* @return a java$util$Map object.
*/
public Map<String, Object> getRancidNodeWithCLoginForGroup(int nodeid, String group, boolean adminRole) {
LOG.debug("getRancidNodeWithCloginFroGroup start: group: {}", group);
Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
String rancidName = (String) nodeModel.get("id");
// Group list
RWSResourceList groups;
try {
groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
List<String> grouplist = groups.getResource();
nodeModel.put("grouplist", grouplist);
// DeviceType list
RWSResourceList devicetypes;
try {
devicetypes = RWSClientApi.getRWSResourceDeviceTypesPatternList(m_cp);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
List<String> devicetypelist = devicetypes.getResource();
nodeModel.put("devicetypelist", devicetypelist);
nodeModel.put("groupname", group);
try {
RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, group, rancidName);
nodeModel.put("devicename", rn.getDeviceName());
nodeModel.put("status", rn.getState());
nodeModel.put("devicetype", rn.getDeviceType());
nodeModel.put("comment", rn.getComment());
nodeModel.put("deviceexist", true);
} catch (RancidApiException e) {
if (e.getRancidCode() == 2) {
nodeModel.put("deviceexist", false);
LOG.debug("No device found in router.db for:{}on Group: {}", rancidName, group);
} else {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
return nodeModel;
}
}
if (adminRole) {
LOG.debug("getRancidNode: getting clogin info for: {}", rancidName);
RancidNodeAuthentication rn5;
try {
rn5 = RWSClientApi.getRWSAuthNode(m_cp, rancidName);
nodeModel.put("isadmin", "true");
nodeModel.put("cloginuser", rn5.getUser());
nodeModel.put("cloginpassword", rn5.getPassword());
nodeModel.put("cloginconnmethod", rn5.getConnectionMethodString());
nodeModel.put("cloginenablepass", rn5.getEnablePass());
String autoen = "0";
if (rn5.isAutoEnable()) {
autoen = "1";
}
nodeModel.put("cloginautoenable", autoen);
} catch (RancidApiException e) {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error("getRancidNode: clogin get failed with reason: {}", e.getLocalizedMessage());
}
}
return nodeModel;
}
Aggregations