test
This commit is contained in:
parent
05832e8df6
commit
803554f335
2
pom.xml
2
pom.xml
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.loafle.overflow</groupId>
|
<groupId>com.loafle.overflow</groupId>
|
||||||
<artifactId>crawler_java</artifactId>
|
<artifactId>crawler</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Maven: org.snmp4j:snmp4j:2.5.0" level="project" />
|
<orderEntry type="library" name="Maven: org.snmp4j:snmp4j:2.5.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
|
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler_java:1.0.0-SNAPSHOT" level="project" />
|
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler:1.0.0-SNAPSHOT" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class SNMPCrawler extends Crawler {
|
||||||
retObj = getByV3(config);
|
retObj = getByV3(config);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return retObj;
|
return retObj;
|
||||||
|
@ -49,8 +49,9 @@ public class SNMPCrawler extends Crawler {
|
||||||
String port = (String)config.get("port");
|
String port = (String)config.get("port");
|
||||||
String community = (String)config.get("community");
|
String community = (String)config.get("community");
|
||||||
String[] oids = (String[])config.get("oids");
|
String[] oids = (String[])config.get("oids");
|
||||||
|
String method = (String)config.get("method");
|
||||||
|
|
||||||
switch ((String)config.get("method")) {
|
switch (method) {
|
||||||
case "validate":
|
case "validate":
|
||||||
return snmpV2.validate(ip, port, community);
|
return snmpV2.validate(ip, port, community);
|
||||||
case "get":
|
case "get":
|
||||||
|
@ -58,12 +59,10 @@ public class SNMPCrawler extends Crawler {
|
||||||
case "walk":
|
case "walk":
|
||||||
return snmpV2.walk(ip, port, community, oids[0]);
|
return snmpV2.walk(ip, port, community, oids[0]);
|
||||||
default:
|
default:
|
||||||
return null;
|
new Exception("Unknown SNMP command : " + method).printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("An Exception happend as follows.");
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (snmp != null) {
|
if (snmp != null) {
|
||||||
|
@ -102,8 +101,9 @@ public class SNMPCrawler extends Crawler {
|
||||||
String privType = (String)config.get("privType");
|
String privType = (String)config.get("privType");
|
||||||
String privPass = (String)config.get("privPass");
|
String privPass = (String)config.get("privPass");
|
||||||
String[] oids = (String[])config.get("oids");
|
String[] oids = (String[])config.get("oids");
|
||||||
|
String method = (String)config.get("method");
|
||||||
|
|
||||||
switch ((String)config.get("method")) {
|
switch (method) {
|
||||||
case "validate":
|
case "validate":
|
||||||
return snmpV3.validate(ip, port, user, authType, authPass, privType, privPass);
|
return snmpV3.validate(ip, port, user, authType, authPass, privType, privPass);
|
||||||
case "get":
|
case "get":
|
||||||
|
@ -111,13 +111,11 @@ public class SNMPCrawler extends Crawler {
|
||||||
case "walk":
|
case "walk":
|
||||||
return snmpV3.walk(ip, port, user, authType, authPass, privType, privPass, oids[0]);
|
return snmpV3.walk(ip, port, user, authType, authPass, privType, privPass, oids[0]);
|
||||||
default:
|
default:
|
||||||
return null;
|
new Exception("Unknown SNMP command : " + method).printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("An Exception happend as follows.");
|
new Exception("An Exception happend : " + e.getMessage()).printStackTrace();
|
||||||
System.err.println(e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
} finally {
|
||||||
if (snmp != null) {
|
if (snmp != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -136,5 +134,4 @@ public class SNMPCrawler extends Crawler {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,13 +46,12 @@ public class AppTest {
|
||||||
config.put("method", "walk");
|
config.put("method", "walk");
|
||||||
config.put("oids", new String[]{"1.3.6.1.2.1.25.2.3.1.3"});
|
config.put("oids", new String[]{"1.3.6.1.2.1.25.2.3.1.3"});
|
||||||
|
|
||||||
Object res = c.getInternal(config);
|
Object result = c.getInternal(config);
|
||||||
|
|
||||||
if(res instanceof Boolean) {
|
if(result instanceof Boolean) {
|
||||||
System.out.println("validate : " + res);
|
System.out.println("validate : " + result);
|
||||||
assertEquals(res, true);
|
|
||||||
}else {
|
}else {
|
||||||
printResult((Map<String, String>)res);
|
printResult((Map<String, String>)result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user