use of org.opennms.rancid.InventoryNode 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.InventoryNode 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.InventoryNode in project opennms by OpenNMS.
the class InventoryService method getRancidNode.
/*
* getRancidNode 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>getRancidNode</p>
*
* @param nodeid a int.
* @return a java$util$Map object.
*/
public Map<String, Object> getRancidNode(int nodeid) {
LOG.debug("getRancidNode start");
Map<String, Object> nodeModel = getRancidNodeBase(nodeid);
String rancidName = (String) nodeModel.get("id");
List<RancidNodeWrapper> ranlist = new ArrayList<RancidNodeWrapper>();
List<BucketItem> bucketlist = new ArrayList<BucketItem>();
// Group list
RWSResourceList groups;
try {
groups = RWSClientApi.getRWSResourceGroupsList(m_cp);
} catch (RancidApiException e) {
LOG.error(e.getLocalizedMessage());
nodeModel.put("RWSStatus", e.getLocalizedMessage());
return nodeModel;
}
List<String> grouplist = groups.getResource();
Iterator<String> iter1 = grouplist.iterator();
boolean first = true;
while (iter1.hasNext()) {
String groupname = iter1.next();
LOG.debug("getRancidNode: {} for group {}", nodeid, groupname);
try {
if (first) {
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("groupname", groupname);
first = false;
}
try {
RancidNode rn = RWSClientApi.getRWSRancidNodeInventory(m_cp, groupname, rancidName);
String vs = rn.getHeadRevision();
InventoryNode in = (InventoryNode) rn.getNodeVersions().get(vs);
RancidNodeWrapper rnw = new RancidNodeWrapper(rn.getDeviceName(), groupname, rn.getDeviceType(), rn.getComment(), rn.getHeadRevision(), rn.getTotalRevisions(), in.getCreationDate(), rn.getRootConfigurationUrl());
ranlist.add(rnw);
} catch (RancidApiException e) {
LOG.debug("No configuration found for nodeid:{} on Group: {} .Cause: {}", nodeid, groupname, e.getLocalizedMessage());
}
} catch (RancidApiException e) {
if (e.getRancidCode() == 2) {
LOG.debug("No device found in router.db for nodeid:{} on Group: {} .Cause: {}", nodeid, groupname, e.getLocalizedMessage());
} else {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
}
}
}
//Groups invariant
nodeModel.put("grouptable", ranlist);
try {
RWSBucket bucket = RWSClientApi.getBucket(m_cp, rancidName);
bucketlist.addAll(bucket.getBucketItem());
} catch (RancidApiException e) {
if (e.getRancidCode() == 2) {
LOG.debug("No entry in storage for nodeid:{} nodeLabel: {}", nodeid, rancidName);
} else {
nodeModel.put("RWSStatus", e.getLocalizedMessage());
LOG.error(e.getLocalizedMessage());
}
}
nodeModel.put("bucketitems", bucketlist);
return nodeModel;
}
use of org.opennms.rancid.InventoryNode in project opennms by OpenNMS.
the class InventoryReportCalculator method calculate.
/**
* <p>calculate</p>
*/
public void calculate() {
rnbi = new RwsNbinventoryreport();
rnbi.setUser(user);
rnbi.setReportRequestDate(StringUtils.toStringEfficiently(reportRequestDate));
boolean withKey = false;
if (theField.compareTo("") != 0) {
withKey = true;
rnbi.setTheField(theField);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d");
Date tmp_date = new Date();
try {
tmp_date = format.parse(theDate);
} catch (ParseException pe) {
tmp_date = Calendar.getInstance().getTime();
}
LOG.debug("calculate:report date[{}]", tmp_date.toString());
rnbi.setReportDate(tmp_date.toString());
int totalGroups = 0;
int groupsMatching = 0;
int groupWithoutNodes = 0;
int groupsWithNodesWithoutinventoryAtAll = 0;
int groupsWithNodesWithoutinventoryAtReportDate = 0;
for (String groupName : getGroups()) {
LOG.debug("calculate:report group [{}]", groupName);
totalGroups++;
GroupSet gs = new GroupSet();
gs.setGroupSetName(groupName);
int totalNodes = 0;
int nodeMatching = 0;
int nodesWithoutinventoryAtAll = 0;
int nodesWithoutinventoryAtReportDate = 0;
boolean groupHasDevices = false;
boolean groupHasNodesWithoutinventoryAtAll = false;
boolean groupHasNodesWithoutinventoryAtrequestDate = false;
for (String deviceName : getDeviceListOnGroup(groupName)) {
totalNodes++;
LOG.debug("calculate:report device [{}]", deviceName);
RancidNode rancidNode = getFullNode(groupName, deviceName);
if (rancidNode == null) {
groupHasNodesWithoutinventoryAtAll = true;
nodesWithoutinventoryAtAll++;
continue;
}
InventoryNode invNode = new InventoryNode(rancidNode);
boolean found = false;
for (String versionMatch : getVersionListOnDevice(deviceName, groupName)) {
invNode = (InventoryNode) rancidNode.getNodeVersions().get(versionMatch);
LOG.debug("calculate:report parsing InventoryNode version[{}] date [{}]", invNode.getVersionId(), invNode.getCreationDate());
if (tmp_date.compareTo(invNode.getCreationDate()) > 0) {
found = true;
LOG.debug("calculate:report Date found is [{}] version is [{}]", invNode.getCreationDate(), versionMatch);
break;
}
}
//end for on version
if (found == false) {
LOG.debug("calculate: device has no configuration at this date[{}]", deviceName);
groupHasNodesWithoutinventoryAtrequestDate = true;
nodesWithoutinventoryAtReportDate++;
continue;
}
//we have groupname devicename and version
NodeBaseInventory nodeBaseInv = getNodeBaseInventory(deviceName, groupName, invNode.getVersionId());
Nbisinglenode nbisn = new Nbisinglenode();
boolean includeNbisn = false;
nbisn.setConfigurationurl(nodeBaseInv.getConfigurationurl());
nbisn.setCreationdate(nodeBaseInv.getCreationdate());
nbisn.setDevicename(nodeBaseInv.getDevicename());
nbisn.setGroupname(nodeBaseInv.getGroupname());
nbisn.setStatus(nodeBaseInv.getStatus());
nbisn.setSwconfigurationurl(nodeBaseInv.getSwconfigurationurl());
nbisn.setVersion(nodeBaseInv.getVersion());
List<InventoryElement2RP> ie2rpList = new ArrayList<InventoryElement2RP>();
for (InventoryElement2 ie2 : nodeBaseInv.getIe()) {
InventoryElement2RP ie2rp = new InventoryElement2RP();
boolean addInventoryElement = false;
for (Tuple tuple : ie2.getTupleList()) {
if (withKey) {
if (Pattern.matches(theField, tuple.getDescription()) || Pattern.matches(theField, tuple.getName())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
if (tuple.getName().equalsIgnoreCase("name")) {
ie2rp.setName(tuple.getDescription());
} else {
TupleRP trp = new TupleRP();
trp.setName(tuple.getName());
trp.setDescription(tuple.getDescription());
ie2rp.addTupleRP(trp);
}
}
for (InventoryMemory im : ie2.getMemoryList()) {
if (withKey) {
if (Pattern.matches(theField, "Memory") || Pattern.matches(theField, im.getType())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
InventoryMemoryRP imrp = new InventoryMemoryRP();
imrp.setType(im.getType());
imrp.setSize(im.getSize());
ie2rp.addInventoryMemoryRP(imrp);
}
for (InventorySoftware is : ie2.getSoftwareList()) {
if (withKey) {
if (Pattern.matches(theField, "Software") || Pattern.matches(theField, is.getType()) || Pattern.matches(theField, is.getVersion())) {
includeNbisn = true;
addInventoryElement = true;
}
} else {
includeNbisn = true;
addInventoryElement = true;
}
InventorySoftwareRP isrp = new InventorySoftwareRP();
isrp.setType(is.getType());
isrp.setVersion(is.getVersion());
ie2rp.addInventorySoftwareRP(isrp);
}
if (addInventoryElement)
ie2rpList.add(ie2rp);
}
nbisn.setInventoryElement2RP(ie2rpList);
if (includeNbisn) {
nodeMatching++;
groupHasDevices = true;
gs.addNbisinglenode(nbisn);
}
}
gs.setTotalNodes(totalNodes);
gs.setNodesMatching(nodeMatching);
gs.setNodesWithoutinventoryAtReportDate(nodesWithoutinventoryAtReportDate);
gs.setNodesWithoutinventoryAtAll(nodesWithoutinventoryAtAll);
rnbi.addGroupSet(gs);
if (groupHasDevices)
groupsMatching++;
else
groupWithoutNodes++;
if (groupHasDevices && groupHasNodesWithoutinventoryAtAll)
groupsWithNodesWithoutinventoryAtAll++;
if (groupHasDevices && groupHasNodesWithoutinventoryAtrequestDate)
groupsWithNodesWithoutinventoryAtReportDate++;
}
//end for groups
rnbi.setTotalGroups(totalGroups);
rnbi.setGroupsMatching(groupsMatching);
rnbi.setGroupsWithNodesWithoutinventoryAtAll(groupsWithNodesWithoutinventoryAtAll);
rnbi.setGroupsWithNodesWithoutinventoryAtReportDate(groupsWithNodesWithoutinventoryAtReportDate);
rnbi.setGroupWithoutNodes(groupWithoutNodes);
}
use of org.opennms.rancid.InventoryNode in project opennms by OpenNMS.
the class ConfigurationReportCalculator method calculate.
/**
* <p>calculate</p>
*/
public void calculate() {
rlist = new RwsRancidlistreport();
rlist.setUser(user);
rlist.setReportRequestDate(StringUtils.toStringEfficiently(reportRequestDate));
//parse date
SimpleDateFormat format = new SimpleDateFormat("yyyy/M/d");
Date tmp_date = new Date();
try {
tmp_date = format.parse(theDate);
} catch (ParseException pe) {
tmp_date = Calendar.getInstance().getTime();
}
LOG.debug("calculate:report date[{}]", tmp_date.toString());
rlist.setReportDate(tmp_date.toString());
int totalGroups = 0;
int groupsMatching = 0;
int groupWithoutNodes = 0;
int groupsWithNodesWithoutconfigurationAtAll = 0;
int groupsWithNodesWithoutconfigurationAtReportDate = 0;
for (String groupName : getGroups()) {
LOG.debug("calculate:report group [{}]", groupName);
totalGroups++;
GroupXSet gs = new GroupXSet();
gs.setGroupXSetName(groupName);
int totalNodes = 0;
int nodeMatching = 0;
int nodesWithoutConfigurationAtAll = 0;
int nodesWithoutConfigurationAtReportDate = 0;
boolean groupHasDevices = false;
boolean groupHasNodesWithoutconfigurationAtAll = false;
boolean groupHasNodesWithoutconfigurationAtrequestDate = false;
for (String deviceName : getDeviceListOnGroup(groupName)) {
totalNodes++;
NodeSet ns = new NodeSet();
ns.setDevicename(deviceName);
ns.setGroupname(groupName);
LOG.debug("calculate:report device [{}]", deviceName);
RancidNode rancidNode = getFullNode(groupName, deviceName);
if (rancidNode == null) {
ns.setVersion("No Configurations found");
groupHasNodesWithoutconfigurationAtAll = true;
nodesWithoutConfigurationAtAll++;
gs.addNodeSet(ns);
continue;
}
InventoryNode invNode = new InventoryNode(rancidNode);
boolean found = false;
for (String versionMatch : getVersionListOnDevice(deviceName, groupName)) {
invNode = (InventoryNode) rancidNode.getNodeVersions().get(versionMatch);
LOG.debug("calculate:report parsing InventoryNode version[{}] date [{}]", invNode.getVersionId(), invNode.getCreationDate());
if (tmp_date.compareTo(invNode.getCreationDate()) > 0) {
found = true;
LOG.debug("calculate:report Date found is [{}] version is [{}]", invNode.getCreationDate(), versionMatch);
break;
}
}
//end for on version
if (found == false) {
// skip device
LOG.debug("calculate:report device has no inventory at this date[{}]", deviceName);
groupHasNodesWithoutconfigurationAtrequestDate = true;
nodesWithoutConfigurationAtReportDate++;
ns.setVersion("No configuration found at Report Date");
} else {
ns.setVersion(invNode.getVersionId());
ns.setConfigurationurl(invNode.getConfigurationUrl());
ns.setSwconfigurationurl(invNode.getSoftwareImageUrl());
ns.setStatus(rancidNode.getState());
ns.setCreationdate(invNode.getCreationDate().toString());
groupHasDevices = true;
nodeMatching++;
}
gs.addNodeSet(ns);
}
//end for on devices
gs.setTotalNodes(totalNodes);
gs.setNodesMatching(nodeMatching);
gs.setNodesWithoutconfigurationAtReportDate(nodesWithoutConfigurationAtReportDate);
gs.setNodesWithoutconfigurationAtAll(nodesWithoutConfigurationAtAll);
rlist.addGroupXSet(gs);
if (groupHasDevices)
groupsMatching++;
else
groupWithoutNodes++;
if (groupHasDevices && groupHasNodesWithoutconfigurationAtAll)
groupsWithNodesWithoutconfigurationAtAll++;
if (groupHasDevices && groupHasNodesWithoutconfigurationAtrequestDate)
groupsWithNodesWithoutconfigurationAtReportDate++;
}
//end for of groups
rlist.setTotalGroups(totalGroups);
rlist.setGroupWithoutNodes(groupWithoutNodes);
rlist.setGroupsMatching(groupsMatching);
rlist.setGroupsWithNodesWithoutconfigurationAtAll(groupsWithNodesWithoutconfigurationAtAll);
rlist.setGroupsWithNodesWithoutconfigurationAtReportDate(groupsWithNodesWithoutconfigurationAtReportDate);
}
Aggregations