Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/core/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class Scheduler extends AbstractCoreUnit {
private String site;
@Value("${cbackup.token}")
private String token;
@Value("${cbackup.discoverylen}")
private String discoverylen;


/**
Expand Down Expand Up @@ -769,6 +771,9 @@ private void init() throws Exception {

try {
this.settings = this.gson.fromJson(settingsJson, settingsType);
this.settings.put("discoverylen", this.discoverylen);


} catch (Exception e) {
this.logSystemException("ERROR", "SCHEDULER INIT", "Can't parse settings from json.", e);
throw new Exception("Can't parse settings from json.", e);
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/core/WorkerDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.snmp4j.util.DefaultPDUFactory;
import org.snmp4j.util.TreeEvent;
import org.snmp4j.util.TreeUtils;

import java.util.*;
import java.util.concurrent.Callable;

Expand All @@ -47,15 +46,16 @@
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;


/**
* Device SNMP discovery class
*/

public class WorkerDiscovery extends AbstractCoreUnit implements Callable<Boolean>
{

private Gson gson = new Gson();


private Integer snmpVer;
private Integer snmpPort;
private String snmpRead;
Expand Down Expand Up @@ -141,6 +141,7 @@ private static Map<String, String> createMap() {
*/
public Boolean call()
{

// parse snmpRetries, snmpTimeout
if(!this.extractSettings()) {
return false;
Expand All @@ -166,6 +167,7 @@ private Boolean extractSettings()
{
String retries = this.settings.get("snmpRetries");
String timeout = this.settings.get("snmpTimeout");


/*
* Set snmp retries
Expand Down Expand Up @@ -237,6 +239,7 @@ private Boolean getDiscovery() {
* SNMP object init
*/
try {


this.snmp = new Snmp(new DefaultUdpTransportMapping());
this.snmp.listen();
Expand Down Expand Up @@ -457,7 +460,7 @@ private Boolean sendWalk()
*/
private Boolean sendRequest()
{

PDU responsePDU;
ResponseEvent responseEvent;

Expand Down Expand Up @@ -525,7 +528,21 @@ private Boolean sendRequest()
try {
String sOid = vb.getOid().toString();
String sVar = vb.getVariable().toString();
this.result.put(discoveryOids.get(sOid), sVar);
Integer llen = Integer.parseInt(this.settings.get("discoverylen"));
if (discoveryOids.get(sOid) == "sys_description" && llen > 0) {

if (sVar.length() > llen) {
this.result.put(discoveryOids.get(sOid), sVar.substring(0,llen));
}
else{
this.result.put(discoveryOids.get(sOid), sVar);
}

}
else{
this.result.put(discoveryOids.get(sOid), sVar);
}

}
catch (Exception e) {
String responsePduVectorConvertMessage = "Task " + this.coordinates.get("taskName") +
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/snmp/GeneralSnmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected Boolean performJobs()
case 2:
return false;
}

/*
* Parsing job timeout to integer
*/
Expand All @@ -396,6 +396,17 @@ protected Boolean performJobs()
/*
* --------SNMP SET CASE----------
*/
varInjectResult = this.injectVariable(snmpSetValue);
switch(varInjectResult.getStatus()) {
case 0:
snmpSetValue = varInjectResult.getResult();
break;
case 1:
skipCommand = true;
break;
case 2:
return false;
}

// Case: empty SNMP set value
if(snmpSetValue == null || snmpSetValue.length() == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ssh/FactoryMethodSsh.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class FactoryMethodSsh {

private static final Map<String, Map<String, String>> models = new HashMap<String, Map<String, String>>() {{
put("Mikrotik", null);
put("Infinet", null);
//put("Extream", null); todo implement
}};

Expand Down
54 changes: 54 additions & 0 deletions src/main/java/ssh/_Infinet_Ssh.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of cBackup, network equipment configuration backup tool
* Copyright (C) 2017, Oļegs Čapligins, Imants Černovs, Dmitrijs Galočkins
*
* cBackup is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ssh;

import abstractions.DTOExpectSendPair;
import abstractions.DTOVariableConvertResult;
import java.util.Map;


/**
* Vendor Mikrotik general ssh class
* @noinspection unused
*/
public class _Infinet_Ssh extends GeneralSsh {

/**
* Constructor
*
* @param coordinates - schedule, task, node, etc..
* @param settings - app settings
* @param credentials - credentials
* @param jobs - sorted jobs
* @param variables - variable list
*/
public _Infinet_Ssh(Map<String, String> coordinates, Map<String, String> settings, Map<String, String> credentials, Map<String, Map<String, String>> jobs, Map<String, DTOVariableConvertResult> variables)
{
/*
* Parent constructor
*/
super(coordinates, settings, credentials, jobs, variables);
/*
* Set ENTER_CHARACTER
*/
ENTER_CHARACTER = "\r\n";
this.controlSeqences.put("%%SEQ(ENTER)%%", this.ENTER_CHARACTER);

}

}
4 changes: 3 additions & 1 deletion src/main/java/telnet/FactoryMethodTelnet.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class FactoryMethodTelnet {
private static final Map<String, Map<String, String>> models = new HashMap<String, Map<String, String>>() {{
put("Mikrotik", null);
put("Nortel", null);
put("BDCOM", null);
put("CDATA", null);
//put("Extream", null); todo implement
}};

Expand All @@ -68,7 +70,7 @@ public GeneralTelnet getProtocolObject(Map<String, String> coordinates, Map<Stri

String vendor = coordinates.get("nodeVendor").replaceAll("-", "__");
String model = coordinates.get("nodeModel").replaceAll("-", "__");

if(models.get(vendor) == null) {
if(models.containsKey(vendor)) {
className = "_" + vendor + "_Telnet";
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/telnet/_BDCOM_Telnet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package telnet;/*
* This file is part of cBackup, network equipment configuration backup tool
* Copyright (C) 2017, Oļegs Čapligins, Imants Černovs, Dmitrijs Galočkins
*
* cBackup is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import abstractions.DTOExpectSendPair;
import abstractions.DTOSendExpectPair;
import abstractions.DTOVariableConvertResult;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

/*
* Custom telnet init
*/
import expect4j.Expect4j;
import org.apache.commons.net.io.FromNetASCIIInputStream;
import org.apache.commons.net.io.ToNetASCIIOutputStream;
import org.apache.commons.net.telnet.EchoOptionHandler;
import org.apache.commons.net.telnet.SuppressGAOptionHandler;
import org.apache.commons.net.telnet.TelnetClient;
import org.apache.commons.net.telnet.TerminalTypeOptionHandler;

/**
* Vendor Nortel general telnet class
* @noinspection unused
*/
public class _BDCOM_Telnet extends GeneralTelnet {

/**
* Constructor
*
* @param coordinates - schedule, task, node, etc..
* @param settings - app settings
* @param jobs - sorted jobs
* @param credentials - credentials
* @param variables - variable list
*/
public _BDCOM_Telnet(Map<String, String> coordinates, Map<String, String> settings, Map<String, String> credentials, Map<String, Map<String, String>> jobs, Map<String, DTOVariableConvertResult> variables)
{
/*
* Parent constructor
*/
super(coordinates, settings, credentials, jobs, variables);

/*
* Set ENTER_CHARACTER
*/
this.ENTER_CHARACTER = "\r\n";
this.controlSeqences.put("%%SEQ(ENTER)%%", this.ENTER_CHARACTER);
}


/**
* Expect init
* Send credentials
* Get device prompt
* Send commands
*
* @return Boolean
* @noinspection Duplicates
*/
@Override
protected Boolean telnetAuth() {
for(DTOExpectSendPair currentPair : this.telnetAuthSequence) {
if(!this.executeAuth(currentPair)) {
return false;
}
}
try {
this.expect.expect("#");
} catch (Exception e) {
e.printStackTrace();
}
return true;
}

}
Loading