SNMP
parent
a80d4198e2
commit
939e520f6a
Binary file not shown.
Binary file not shown.
|
|
@ -41,6 +41,8 @@ file.reference.apache-commons-logging-1.2.jar=lib\\apache-commons-logging-1.2.ja
|
|||
file.reference.apache-commons-text-1.10.0.jar=lib\\apache-commons-text-1.10.0.jar
|
||||
file.reference.mysql-connector-java-8.0.15.jar=lib\\mysql-connector-java-8.0.15.jar
|
||||
file.reference.netty-all-4.1.68.Final.jar=lib\\netty-all-4.1.68.Final.jar
|
||||
file.reference.snmp4j-3.8.2.jar=lib\\snmp4j-3.8.2.jar
|
||||
file.reference.spring-security-crypto-5.8.0.jar=lib\\spring-security-crypto-5.8.0.jar
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
|
|
@ -50,7 +52,9 @@ javac.classpath=\
|
|||
${file.reference.apache-commons-logging-1.2.jar}:\
|
||||
${file.reference.apache-commons-text-1.10.0.jar}:\
|
||||
${file.reference.mysql-connector-java-8.0.15.jar}:\
|
||||
${file.reference.netty-all-4.1.68.Final.jar}
|
||||
${file.reference.netty-all-4.1.68.Final.jar}:\
|
||||
${file.reference.spring-security-crypto-5.8.0.jar}:\
|
||||
${file.reference.snmp4j-3.8.2.jar}
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import jnet.lib.BuilddDate;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.LogWindow;
|
||||
|
|
@ -11,12 +13,12 @@ import jnet.lib.OSValidator;
|
|||
import jnet.lib.PropertiesManager;
|
||||
import jnet.lib.object.Event;
|
||||
import jnet.lib.object.Map;
|
||||
import jnet.lib.object.MapObject;
|
||||
import jnet.lib.object.ObjectType;
|
||||
import jnet.lib.object.OnlineClients;
|
||||
import jnet.lib.object.SnmpProbe;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.lib.object.User;
|
||||
import jnet.lib.snmp.SNMPTrafficMonitor;
|
||||
import jnet.server.network.NettyServer;
|
||||
import jnet.server.probe.NettyPing;
|
||||
|
||||
|
|
@ -28,10 +30,8 @@ public class Server {
|
|||
// minimální verze klienta
|
||||
public static final int MINIMAL_CLIENT_VERSION = 1;
|
||||
|
||||
|
||||
public static PropertiesManager config;
|
||||
public static List<Map> maps = new ArrayList<>();
|
||||
//public static ArrayList<MapObject> mapObject= new ArrayList<>();
|
||||
public static List<OnlineClients> onlineClients = new ArrayList<>();
|
||||
public static List<ObjectType> objectType = new ArrayList<>();
|
||||
public static List<SnmpProfile> snmpProfile = new ArrayList<>();
|
||||
|
|
@ -41,13 +41,27 @@ public class Server {
|
|||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// // Zde můžete zadat index rozhraní, které chcete monitorovat (např. 1 pro eth0)
|
||||
// int interfaceIndex = 1;
|
||||
//
|
||||
// // Vytvoření instance monitoru pro zadaný index rozhraní
|
||||
// try {
|
||||
// SNMPTrafficMonitor monitor = new SNMPTrafficMonitor("10.0.0.16", "161", "public", 0);
|
||||
// monitor.startMonitoring(interfaceIndex);
|
||||
//
|
||||
// // Po 60 sekundách zastavíme monitoring
|
||||
// Thread.sleep(60000); // Monitoring běží 60 sekund
|
||||
// monitor.stopMonitoring();
|
||||
// monitor.stop();
|
||||
// } catch (Exception ex) {
|
||||
// Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
|
||||
// pokud je hostitelsky system windows otevre logovaci okno
|
||||
if (OSValidator.isWindows()) {
|
||||
new LogWindow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
LogFile.clear();
|
||||
LogFile.setDebug(false);
|
||||
LogFile.printInfo("---------------------------------------------");
|
||||
|
|
@ -56,7 +70,6 @@ public class Server {
|
|||
LogFile.printInfo("---------------------------------------------");
|
||||
LogFile.printInfo("");
|
||||
|
||||
|
||||
///
|
||||
/// nahrani konfigurace
|
||||
///
|
||||
|
|
@ -71,8 +84,6 @@ public class Server {
|
|||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// debug rezim ?
|
||||
///
|
||||
|
|
@ -112,13 +123,10 @@ public class Server {
|
|||
// LogFile.printInfo("Loading SNMP template ...");
|
||||
// snmpProbe = Database.getSnmpProbe();
|
||||
// LogFile.printInfo(" load " + snmpProbe.size() + " template(s)");
|
||||
|
||||
LogFile.printInfo("Loading events ...");
|
||||
events = Database.getEvents();
|
||||
LogFile.printInfo(" load " + events.size() + " event(s)");
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// spusteni serveru
|
||||
///
|
||||
|
|
@ -137,7 +145,7 @@ public class Server {
|
|||
// p2.start();
|
||||
|
||||
NettyPing np = new NettyPing();
|
||||
np.start();
|
||||
np.start();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import io.netty.channel.Channel;
|
|||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.channel.group.DefaultChannelGroup;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.function.Consumer;
|
||||
import jnet.lib.LogFile;
|
||||
|
|
@ -20,6 +22,10 @@ import jnet.lib.object.OnlineClients;
|
|||
import jnet.lib.object.ServerConfig;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.lib.object.User;
|
||||
import jnet.lib.snmp.DeviceInfo;
|
||||
import jnet.lib.snmp.Interface;
|
||||
import jnet.lib.snmp.SNMPDeviceInfo;
|
||||
import jnet.lib.snmp.SNMPInterfaceScanner;
|
||||
|
||||
public class ServerMessageParser {
|
||||
|
||||
|
|
@ -50,6 +56,7 @@ public class ServerMessageParser {
|
|||
handlers.put(Message.USER_EDIT, this::handleUserEdit);
|
||||
handlers.put(Message.SERVER_CONFIG, this::handleServerConfig);
|
||||
handlers.put(Message.SNMP_OBJECT_INFO, this::handleSnmpObjectInfo);
|
||||
handlers.put(Message.SNMP_OBJECT_INTERFACE, this::handleSnmpObjectInterface);
|
||||
}
|
||||
|
||||
public void parse(Message msg) {
|
||||
|
|
@ -341,8 +348,52 @@ public class ServerMessageParser {
|
|||
private void handleSnmpObjectInfo(Message msg) {
|
||||
Object[] msg_object = (Object[]) msg.getMsg();
|
||||
String frameName = (String) msg_object[0];
|
||||
int objId = (int) msg_object[1];
|
||||
MapObject obj = (MapObject) msg_object[1];
|
||||
Thread t1 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (SnmpProfile snmpProfile : Server.snmpProfile) {
|
||||
if (snmpProfile.getId() == obj.getSnmpProfile()) {
|
||||
SNMPDeviceInfo snmp = new SNMPDeviceInfo(obj.getIp(), snmpProfile.getPort(), snmpProfile.getCommunityRead(), snmpProfile.getVersion());
|
||||
DeviceInfo di = snmp.getDeviceInfo();
|
||||
Object[] o = {frameName, di};
|
||||
send(Message.SNMP_OBJECT_INFO, o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
LogFile.printErr("SNMP error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
t1.start();
|
||||
}
|
||||
|
||||
private void handleSnmpObjectInterface(Message msg) {
|
||||
Object[] msg_object = (Object[]) msg.getMsg();
|
||||
String frameName = (String) msg_object[0];
|
||||
MapObject obj = (MapObject) msg_object[1];
|
||||
Thread t1 = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (SnmpProfile snmpProfile : Server.snmpProfile) {
|
||||
if (snmpProfile.getId() == obj.getSnmpProfile()) {
|
||||
SNMPInterfaceScanner snmp = new SNMPInterfaceScanner(obj.getIp(), snmpProfile.getPort(), snmpProfile.getCommunityRead(), snmpProfile.getVersion());
|
||||
List<Interface> list = snmp.scanInterfaces();
|
||||
Object[] o = {frameName, list};
|
||||
send(Message.SNMP_OBJECT_INTERFACE, o);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LogFile.printErr("SNMP error: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
t1.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -350,7 +401,6 @@ public class ServerMessageParser {
|
|||
*
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public void send(Message message) {
|
||||
currentClient.writeAndFlush(message);
|
||||
LogFile.printDebug("<- Message type: " + message.getType());
|
||||
|
|
|
|||
Loading…
Reference in New Issue