Search in sources :

Example 6 with RancidNode

use of org.opennms.rancid.RancidNode 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;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RancidNodeAuthentication(org.opennms.rancid.RancidNodeAuthentication) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Example 7 with RancidNode

use of org.opennms.rancid.RancidNode in project opennms by OpenNMS.

the class InventoryService method deleteNodeOnRouterDb.

/**
 * <p>deleteNodeOnRouterDb</p>
 *
 * @param groupName a {@link java.lang.String} object.
 * @param deviceName a {@link java.lang.String} object.
 * @return a boolean.
 */
public boolean deleteNodeOnRouterDb(String groupName, String deviceName) {
    LOG.debug("InventoryService deleteNodeOnRouterDb: {}/{}", groupName, deviceName);
    try {
        RancidNode rn = RWSClientApi.getRWSRancidNodeTLO(m_cp, groupName, deviceName);
        RWSClientApi.deleteRWSRancidNode(m_cp, rn);
    } catch (Throwable e) {
        LOG.debug("deleteNodeOnRouterDb has given exception on node {}/{} {}", groupName, deviceName, e.getMessage());
        return false;
    }
    return true;
}
Also used : RancidNode(org.opennms.rancid.RancidNode)

Example 8 with RancidNode

use of org.opennms.rancid.RancidNode 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<>();
    List<BucketItem> bucketlist = new ArrayList<>();
    // 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;
}
Also used : ArrayList(java.util.ArrayList) InventoryNode(org.opennms.rancid.InventoryNode) RWSBucket(org.opennms.rancid.RWSBucket) RancidNode(org.opennms.rancid.RancidNode) BucketItem(org.opennms.rancid.RWSBucket.BucketItem) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Example 9 with RancidNode

use of org.opennms.rancid.RancidNode 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<>();
    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;
}
Also used : ArrayList(java.util.ArrayList) InventoryNode(org.opennms.rancid.InventoryNode) RancidNode(org.opennms.rancid.RancidNode) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Example 10 with RancidNode

use of org.opennms.rancid.RancidNode 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;
}
Also used : RancidNode(org.opennms.rancid.RancidNode) RWSResourceList(org.opennms.rancid.RWSResourceList) RancidApiException(org.opennms.rancid.RancidApiException)

Aggregations

RancidNode (org.opennms.rancid.RancidNode)21 RancidApiException (org.opennms.rancid.RancidApiException)9 InventoryNode (org.opennms.rancid.InventoryNode)7 RWSResourceList (org.opennms.rancid.RWSResourceList)6 ArrayList (java.util.ArrayList)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 RancidNodeAuthentication (org.opennms.rancid.RancidNodeAuthentication)3 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 InventoryElement2 (org.opennms.rancid.InventoryElement2)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 InventoryMemory (org.opennms.rancid.InventoryMemory)1 InventorySoftware (org.opennms.rancid.InventorySoftware)1 RWSBucket (org.opennms.rancid.RWSBucket)1 BucketItem (org.opennms.rancid.RWSBucket.BucketItem)1 Tuple (org.opennms.rancid.Tuple)1