pridání, editace a smazani snmp profilu
parent
e69e307c09
commit
b3c2f0311a
|
|
@ -22,6 +22,8 @@ public final class Database {
|
|||
private static final ObjectTypeDao objectTypeDao = new ObjectTypeDao();
|
||||
private static final ConnectionDao connectionDao = new ConnectionDao();
|
||||
|
||||
|
||||
|
||||
|
||||
// Veřejný konstruktor pro případy, kdy je v kódu voláno new Database()
|
||||
public Database() {}
|
||||
|
|
@ -146,6 +148,18 @@ public final class Database {
|
|||
return snmpDao.getAllProfile();
|
||||
}
|
||||
|
||||
public static int addSnmpProfile(SnmpProfile profile) {
|
||||
return snmpDao.addSnmpProfile(profile);
|
||||
}
|
||||
|
||||
public static void editSnmpProfile(SnmpProfile profile) {
|
||||
snmpDao.editSnmpProfile(profile);
|
||||
}
|
||||
|
||||
public static void removeSnmpProfile(int id){
|
||||
snmpDao.removeSnmpProfile(id);
|
||||
}
|
||||
|
||||
public static List<SnmpTemplate> getSnmpTemplate(){
|
||||
return snmpDao.getSnmpTemplate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package jnet.server.dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import jnet.lib.LogFile;
|
||||
import jnet.lib.object.NodeProbe;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.lib.object.SnmpTemplate;
|
||||
|
|
@ -25,16 +27,16 @@ public class SnmpDao extends AbstractDao {
|
|||
String sql = "SELECT * FROM snmp_oid_template";
|
||||
return queryList(sql, rs -> {
|
||||
return new SnmpTemplate(
|
||||
rs.getInt("id"),
|
||||
rs.getInt("device_type"),
|
||||
rs.getString("name"),
|
||||
rs.getString("oid"),
|
||||
rs.getString("snmp_data_type"),
|
||||
rs.getString("conversion_type"),
|
||||
rs.getInt("id"),
|
||||
rs.getInt("device_type"),
|
||||
rs.getString("name"),
|
||||
rs.getString("oid"),
|
||||
rs.getString("snmp_data_type"),
|
||||
rs.getString("conversion_type"),
|
||||
rs.getDouble("conversion_value"),
|
||||
rs.getString("conversion_expression"),
|
||||
rs.getString("unit"),
|
||||
rs.getInt("value_map_id"),
|
||||
rs.getString("unit"),
|
||||
rs.getInt("value_map_id"),
|
||||
rs.getString("description")
|
||||
);
|
||||
});
|
||||
|
|
@ -58,15 +60,49 @@ public class SnmpDao extends AbstractDao {
|
|||
), id);
|
||||
}
|
||||
|
||||
public int addSnmpProfile(SnmpProfile profile) {
|
||||
String sql = "INSERT INTO snmpProfile (name, communityRead, port, version) VALUES (?, ?, ?, ?)";
|
||||
return insertAndGetId(
|
||||
sql,
|
||||
profile.getName(),
|
||||
profile.getCommunityRead(),
|
||||
profile.getPort(),
|
||||
profile.getVersion()
|
||||
);
|
||||
}
|
||||
|
||||
public void editSnmpProfile(SnmpProfile profile) {
|
||||
try {
|
||||
executeUpdate(
|
||||
"UPDATE snmpProfile SET name=?, communityRead=?, port=?, version=? WHERE id=?",
|
||||
profile.getName(),
|
||||
profile.getCommunityRead(),
|
||||
profile.getPort(),
|
||||
profile.getVersion(),
|
||||
profile.getId() // poslední parametr pro WHERE
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
LogFile.printErr("Chyba při aktualizaci SNMP profilu: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSnmpProfile(int id) {
|
||||
if (deleteById("snmpProfile", id)) {
|
||||
LogFile.printInfo("SNMP profile ID " + id + " removed from database");
|
||||
} else {
|
||||
LogFile.printErr("SNMP profile ID " + id + " not removed from database");
|
||||
}
|
||||
}
|
||||
|
||||
public int addNodeProbe(NodeProbe probe) {
|
||||
String sql = "INSERT INTO nodeProbe (name, node_id, oid, snmp_data_type, conversion_type, conversion_value, conversion_expression, value_map_id, unit, interval_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
return insertAndGetId(
|
||||
sql,
|
||||
probe.getName(),
|
||||
probe.getName(),
|
||||
probe.getNodeId(),
|
||||
probe.getOid(),
|
||||
probe.getOid(),
|
||||
probe.getDataType(),
|
||||
probe.getConversionType(),
|
||||
probe.getConversionType(),
|
||||
probe.getConversionValue(),
|
||||
probe.getConversionExpression(),
|
||||
probe.getValueMap(),
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ public class MessageRegister {
|
|||
register.put(Message.NODE_CONNECTION_SNMP_INTERFACE, new RegisterNodeConnectionSnmpInterface());
|
||||
register.put(Message.NODE_PROBE_NEW, new RegisterNodeProbeNew());
|
||||
register.put(Message.NODE_CONNECTION_DELETE, new RegisterNodeConnectionDelete());
|
||||
register.put(Message.SNMP_PROFILE_NEW, new RegisterSnmpProfileNew());
|
||||
register.put(Message.SNMP_PROFILE_EDIT, new RegisterSnmpProfileEdit());
|
||||
register.put(Message.SNMP_PROFILE_DELETE, new RegisterSnmpProfileDelete());
|
||||
}
|
||||
|
||||
public Register getRegister(int typ) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package jnet.server.message;
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.Site;
|
||||
import jnet.server.Database;
|
||||
import jnet.server.Server;
|
||||
import jnet.server.networkserver.ServerHandler;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package jnet.server.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
import jnet.server.Database;
|
||||
import jnet.server.Server;
|
||||
import jnet.server.networkserver.ServerHandler;
|
||||
|
||||
public class RegisterSnmpProfileDelete implements Register {
|
||||
|
||||
public RegisterSnmpProfileDelete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
int profileId = (int) msg.getMsg();
|
||||
|
||||
// odebere ze seznamu
|
||||
Server.snmpProfile.removeIf(snmpProfile -> snmpProfile.getId() == profileId);
|
||||
// odebere z databaze
|
||||
Database.removeSnmpProfile(profileId);
|
||||
// odesle informaci vsem
|
||||
ServerHandler.sendAll(Message.SNMP_PROFILE_DELETE_RESULT, profileId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package jnet.server.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.server.Database;
|
||||
import jnet.server.Server;
|
||||
import jnet.server.networkserver.ServerHandler;
|
||||
|
||||
public class RegisterSnmpProfileEdit implements Register {
|
||||
|
||||
public RegisterSnmpProfileEdit() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
SnmpProfile profile = (SnmpProfile) msg.getMsg();
|
||||
|
||||
// upravit v databazi
|
||||
Database.editSnmpProfile(profile);
|
||||
|
||||
// upravit v lokalnim seznamu
|
||||
for (int i = 0; i < Server.snmpProfile.size(); i++) {
|
||||
if (Server.snmpProfile.get(i).getId() == profile.getId()) {
|
||||
// nahradi node v seznamu
|
||||
Server.snmpProfile.set(i, profile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("jnet.server.message.RegisterSnmpProfileEdit.processing()");
|
||||
ServerHandler.sendAll(Message.SNMP_PROFILE_EDIT_RESULT, profile);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package jnet.server.message;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import jnet.lib.Message;
|
||||
import jnet.lib.object.SnmpProfile;
|
||||
import jnet.server.Database;
|
||||
import jnet.server.Server;
|
||||
import jnet.server.networkserver.ServerHandler;
|
||||
|
||||
|
||||
public class RegisterSnmpProfileNew implements Register {
|
||||
|
||||
public RegisterSnmpProfileNew() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processing(ChannelHandlerContext ctx, Message msg) {
|
||||
SnmpProfile profile = (SnmpProfile) msg.getMsg();
|
||||
|
||||
int id = Database.addSnmpProfile(profile);
|
||||
|
||||
profile.setId(id);
|
||||
|
||||
Server.snmpProfile.add(profile);
|
||||
|
||||
ServerHandler.sendAll(Message.SNMP_PROFILE_NEW_RESULT, profile);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue