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,43 +13,55 @@ 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;
|
||||
|
||||
public class Server {
|
||||
|
||||
|
||||
// verze serveru
|
||||
public static final int SERVER_VERSION = 1;
|
||||
|
||||
// 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<>();
|
||||
public static List<SnmpProbe> snmpProbe = new ArrayList<>();
|
||||
public static List<User> users = new ArrayList<>();
|
||||
public static List<Event> events = new ArrayList<>();
|
||||
|
||||
|
||||
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("---------------------------------------------");
|
||||
|
|
@ -55,7 +69,6 @@ public class Server {
|
|||
LogFile.printInfo(" Version: " + SERVER_VERSION + " (" + BuilddDate.get() + ")");
|
||||
LogFile.printInfo("---------------------------------------------");
|
||||
LogFile.printInfo("");
|
||||
|
||||
|
||||
///
|
||||
/// nahrani konfigurace
|
||||
|
|
@ -70,9 +83,7 @@ public class Server {
|
|||
LogFile.printErr(" fail. " + ex.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// debug rezim ?
|
||||
///
|
||||
|
|
@ -80,7 +91,7 @@ public class Server {
|
|||
LogFile.setDebug(true);
|
||||
LogFile.printDebug("Debug mode on");
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// pripojeni k databazi
|
||||
///
|
||||
|
|
@ -89,42 +100,39 @@ public class Server {
|
|||
config.getString("mysql_database"),
|
||||
config.getString("mysql_user"),
|
||||
config.getString("mysql_password"));
|
||||
|
||||
|
||||
///
|
||||
/// konfigurace z databaze
|
||||
///
|
||||
LogFile.printInfo("Loading user list ...");
|
||||
users = Database.getUsers();
|
||||
LogFile.printInfo(" load " + users.size() + " user(s)");
|
||||
|
||||
|
||||
LogFile.printInfo("Loading map list ...");
|
||||
maps = Database.getMapList();
|
||||
LogFile.printInfo(" load " + maps.size() + " map(s)");
|
||||
|
||||
|
||||
LogFile.printInfo("Loading object type ...");
|
||||
objectType = Database.getObjectType();
|
||||
LogFile.printInfo(" load " + objectType.size() + " type(s)");
|
||||
|
||||
|
||||
LogFile.printInfo("Loading SNMP profile ...");
|
||||
snmpProfile = Database.getSnmpProfile();
|
||||
LogFile.printInfo(" load " + snmpProfile.size() + " profile(s)");
|
||||
|
||||
|
||||
// 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
|
||||
///
|
||||
NettyServer nettyserver = new NettyServer(config.getInt("server_port"));
|
||||
nettyserver.start();
|
||||
|
||||
|
||||
///
|
||||
/// spusteni ping probe
|
||||
///
|
||||
|
|
@ -137,10 +145,10 @@ public class Server {
|
|||
// p2.start();
|
||||
|
||||
NettyPing np = new NettyPing();
|
||||
np.start();
|
||||
np.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void restartServer() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -62,7 +69,7 @@ public class ServerMessageParser {
|
|||
LogFile.printErr("Neznamy typ zpravy");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void handleClientVersion(Message msg) {
|
||||
int client_version = (int) msg.getMsg();
|
||||
if (client_version < Server.MINIMAL_CLIENT_VERSION) {
|
||||
|
|
@ -337,20 +344,63 @@ public class ServerMessageParser {
|
|||
//odeslani vsem
|
||||
sendAll(Message.SERVER_CONFIG, sc);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param message
|
||||
*
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
|
||||
public void send(Message message) {
|
||||
currentClient.writeAndFlush(message);
|
||||
LogFile.printDebug("<- Message type: " + message.getType());
|
||||
|
|
|
|||
Loading…
Reference in New Issue