implementace zobrazeni logu ze serveru, prepracovaní nastaveni serveru do nove tab a dořešeno ukladání

verze3
Michal 2026-09-02 23:31:33 +02:00
parent 40f97ff189
commit bf01254a79
8 changed files with 144 additions and 60 deletions

View File

@ -133,8 +133,8 @@ public class Server {
// 🆕 SPUŠTĚNÍ traffic SNMP MONITORU
// ============================================================
// Spustíme SNMP monitoring s intervalem z configu (např. 30 sekund)
long snmpInterval = config.getLong("snmp.interval", 30000); // default 30s
long batchInterval = config.getLong("snmp.batchInterval", 2000);
int snmpInterval = config.getInt("traffic_interval", 30) * 1000; // default 30s
int batchInterval = config.getInt("traffic_batch_interval", 2) * 1000;
trafficMonitorService.start(snmpInterval, batchInterval);
// ============================================================
@ -142,7 +142,7 @@ public class Server {
snmpProbeManager = new NodeProbeManager();
// Vytvoření batch processoru s intervalem 5 sekund (lze z configu)
int batchSeconds = config.getInt("snmp.batchIntervalSec", 5);
int batchSeconds = config.getInt("probe_batch_interval", 5);
SnmpBatchProcessor batchProcessor = new SnmpBatchProcessor(batchSeconds);
batchProcessor.init(snmpProbeManager); // zaregistruje se a spustí scheduler

View File

@ -45,6 +45,9 @@ public class MessageRegister {
register.put(Message.USER_DELETE, new RegisterUserDelete());
register.put(Message.USER_PING_START, new RegisterUserPingStart());
register.put(Message.USER_PING_STOP, new RegisterUserPingStop());
register.put(Message.SERVER_LOG, new RegisterServerLog());
register.put(Message.SERVER_CONFIG_EDIT, new RegisterServerEdit());
}

View File

@ -44,14 +44,7 @@ public class RegisterClientAuth implements Register {
// odeslat vsem nový seznam pripojenych klientu
ServerHandler.sendAll(new Message(Message.ONLINE_CLIENTS, Server.onlineClients));
// odeslat nastaveni serveru
ServerConfig sc = new ServerConfig(
Server.config.getInt("ping_repeat"),
Server.config.getInt("ping_attempt"),
Server.config.getInt("ping_timeout"),
Server.config.getInt("instability_attempt"),
Server.config.getInt("instability_limit"),
Server.config.getBoolean("debug"));
ctx.writeAndFlush(new Message(Message.SERVER_CONFIG, sc));
ctx.writeAndFlush(new Message(Message.SERVER_CONFIG, getServerConfig()));
// odeslat seznam uzivatelu
ctx.writeAndFlush(new Message(Message.USER_LIST, Server.users));
// odeslat seznam icon
@ -75,4 +68,18 @@ public class RegisterClientAuth implements Register {
}
private ServerConfig getServerConfig() {
ServerConfig sc = new ServerConfig(
Server.config.getInt("ping_repeat"),
Server.config.getInt("ping_attempt"),
Server.config.getInt("ping_timeout"),
Server.config.getInt("instability_attempt"),
Server.config.getInt("instability_limit"),
Server.config.getInt("traffic_interval"),
Server.config.getInt("traffic_batch_interval"),
Server.config.getInt("probe_batch_interval"),
Server.config.getBoolean("debug"));
return sc;
}
}

View File

@ -0,0 +1,39 @@
package jnet.server.message;
import io.netty.channel.ChannelHandlerContext;
import jnet.lib.ApacheConfig;
import jnet.lib.LogFile;
import jnet.lib.Message;
import jnet.lib.object.ServerConfig;
import jnet.server.Server;
import org.apache.commons.configuration2.ex.ConfigurationException;
public class RegisterServerEdit implements Register {
public RegisterServerEdit() {
}
@Override
public void processing(ChannelHandlerContext ctx, Message msg) {
ServerConfig sc = (ServerConfig) msg.getMsg();
Server.config.setProperty("debug", sc.isDebug());
Server.config.setProperty("ping_repeat", sc.getPingRepeat());
Server.config.setProperty("ping_timeout", sc.getPingTimeout());
Server.config.setProperty("ping_attempt", sc.getPingAttempt());
Server.config.setProperty("instability_attempt", sc.getInstabilityAttempt());
Server.config.setProperty("instability_limit", sc.getInstabilityLimit());
Server.config.setProperty("traffic_interval", sc.getTrafficInterval());
Server.config.setProperty("traffic_batch_interval", sc.getTrafficBatchInterval());
Server.config.setProperty("probe_batch_interval", sc.getProbeBatchInterval());
try {
ApacheConfig.saveProperties(Server.config);
LogFile.printInfo("Nastavení uloženo.");
} catch (ConfigurationException ex) {
LogFile.printErr("Nastavení nebylo uloženo. " + ex.getMessage());
}
}
}

View File

@ -0,0 +1,34 @@
package jnet.server.message;
import io.netty.channel.ChannelHandlerContext;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import jnet.lib.Message;
import jnet.server.networkserver.ServerHandler;
public class RegisterServerLog implements Register{
public RegisterServerLog() {
}
@Override
public void processing(ChannelHandlerContext ctx, Message msg) {
try {
// Načtení všech řádků souboru do List<String>
List<String> lines = Files.readAllLines(Paths.get("log"));
// Převod na String[]
String[] logRecords = lines.toArray(new String[0]);
ctx.writeAndFlush(new Message(Message.SERVER_LOG_RESULT, logRecords));
} catch (IOException e) {
// Ošetření chyby – např. logování nebo zaslání chybové zprávy
e.printStackTrace();
// případně ctx.writeAndFlush(...)
}
}
}

View File

@ -17,27 +17,28 @@ public class RegisterSnmpNodeInfo implements Register {
@Override
public void processing(ChannelHandlerContext ctx, Message msg) {
try {
Object[] data = (Object[]) msg.getMsg();
String frame = (String) data[0];
Node node = (Node) data[1];
// zjistit snmp profile
SnmpProfile snmpProfile = Server.snmpProfile.stream()
.filter(profile -> profile.getId() == node.getSnmpProfile())
.findFirst()
.orElse(null);
if (snmpProfile != null) {
// odeslat pozadavek
SNMPDeviceInfo snmp = new SNMPDeviceInfo(node.getIp(), snmpProfile.getPort(), snmpProfile.getCommunityRead(), snmpProfile.getVersion());
DeviceInfo info = snmp.getDeviceInfo(); // spojení se automaticky uzavře
Object[] result = {frame, info};
ctx.writeAndFlush(new Message(Message.NODE_SNMP_INFO_RESULT, result));
new Thread(() -> {
try {
Object[] data = (Object[]) msg.getMsg();
String frame = (String) data[0];
Node node = (Node) data[1];
// zjistit snmp profile
SnmpProfile snmpProfile = Server.snmpProfile.stream()
.filter(profile -> profile.getId() == node.getSnmpProfile())
.findFirst()
.orElse(null);
if (snmpProfile != null) {
// odeslat pozadavek
SNMPDeviceInfo snmp = new SNMPDeviceInfo(node.getIp(), snmpProfile.getPort(), snmpProfile.getCommunityRead(), snmpProfile.getVersion());
DeviceInfo info = snmp.getDeviceInfo(); // spojení se automaticky uzavře
Object[] result = {frame, info};
ctx.writeAndFlush(new Message(Message.NODE_SNMP_INFO_RESULT, result));
}
} catch (IOException ex) {
LogFile.printErr("SNMP info error: " + ex.getMessage());
}
} catch (IOException ex) {
LogFile.printErr("SNMP info error: " + ex.getMessage());
}
}).start();
}
}

View File

@ -11,7 +11,6 @@ import jnet.lib.object.SnmpProfile;
import jnet.server.Server;
import jnet.server.snmp.SNMPInterfaceScanner;
public class RegisterSnmpNodeInterface implements Register {
public RegisterSnmpNodeInterface() {
@ -19,32 +18,34 @@ public class RegisterSnmpNodeInterface implements Register {
@Override
public void processing(ChannelHandlerContext ctx, Message msg) {
try {
Object[] data = (Object[]) msg.getMsg();
String frame = (String) data[0];
Node node = (Node) data[1];
// zjistit snmp profile
SnmpProfile snmpProfile = Server.snmpProfile.stream()
.filter(profile -> profile.getId() == node.getSnmpProfile())
.findFirst()
.orElse(null);
if (snmpProfile != null) {
// odeslat pozadavek
SNMPInterfaceScanner scanner = new SNMPInterfaceScanner(
node.getIp(),
snmpProfile.getPort(),
snmpProfile.getCommunityRead(),
snmpProfile.getVersion()
);
new Thread(() -> {
try {
Object[] data = (Object[]) msg.getMsg();
String frame = (String) data[0];
Node node = (Node) data[1];
// zjistit snmp profile
SnmpProfile snmpProfile = Server.snmpProfile.stream()
.filter(profile -> profile.getId() == node.getSnmpProfile())
.findFirst()
.orElse(null);
if (snmpProfile != null) {
// odeslat pozadavek
SNMPInterfaceScanner scanner = new SNMPInterfaceScanner(
node.getIp(),
snmpProfile.getPort(),
snmpProfile.getCommunityRead(),
snmpProfile.getVersion()
);
List<Interface> ifaces = scanner.scanInterfaces();
Object[] result = {frame, ifaces};
ctx.writeAndFlush(new Message(Message.NODE_SNMP_INTERFACE_RESULT, result));
List<Interface> ifaces = scanner.scanInterfaces();
Object[] result = {frame, ifaces};
ctx.writeAndFlush(new Message(Message.NODE_SNMP_INTERFACE_RESULT, result));
}
} catch (IOException ex) {
LogFile.printErr("SNMP interface scan error: " + ex.getMessage());
}
} catch (IOException ex) {
LogFile.printErr("SNMP interface scan error: " + ex.getMessage());
}
}).start();
}
}

View File

@ -1,7 +1,5 @@
mysql_server=192.168.122.245
mysql_port=3306
#mysql_server=10.2.4.141
#mysql_port=3360
mysql_user=jnet
mysql_password=Michal2407
mysql_database=jnet
@ -12,5 +10,6 @@ ping_timeout=2
ping_repeat=3
instability_attempt=2
instability_limit=1
snmp.interval=5000
snmp.batchInterval=2000
traffic_interval=5
traffic_batch_interval=2
probe_batch_interval=5