cteni SNMPT informaci o objektu a jejich rozhranich
parent
c28c2dfe19
commit
4b7d0e3e8f
|
|
@ -43,55 +43,54 @@ public class Client {
|
||||||
|
|
||||||
|
|
||||||
LogFile.clear();
|
LogFile.clear();
|
||||||
LogFile.printInfo("---------------------------------------------");
|
LogFile.printInfo("---------------------------------------------");
|
||||||
LogFile.printInfo(" jNet Client ");
|
LogFile.printInfo(" jNet Client ");
|
||||||
LogFile.printInfo(" Version: " + CLIENT_VERSION + " (" + BuilddDate.get() + ")");
|
LogFile.printInfo(" Version: " + CLIENT_VERSION + " (" + BuilddDate.get() + ")");
|
||||||
LogFile.printInfo("---------------------------------------------");
|
LogFile.printInfo("---------------------------------------------");
|
||||||
LogFile.printInfo("");
|
LogFile.printInfo("");
|
||||||
|
|
||||||
///
|
///
|
||||||
/// load config
|
/// load config
|
||||||
///
|
///
|
||||||
LogFile.printInfo("Loading config ...");
|
LogFile.printInfo("Loading config ...");
|
||||||
try {
|
try {
|
||||||
// Načtení existující konfigurace, pokud soubor existuje
|
// Načtení existující konfigurace, pokud soubor existuje
|
||||||
config = new PropertiesManager("config.properties");
|
config = new PropertiesManager("config.properties");
|
||||||
config.load();
|
config.load();
|
||||||
LogFile.printInfo(" successfully");
|
LogFile.printInfo(" successfully");
|
||||||
} catch (PropertiesManager.FileException | PropertiesManager.ConfigException ex) {
|
} catch (PropertiesManager.FileException | PropertiesManager.ConfigException ex) {
|
||||||
LogFile.printErr(" fail. " + ex.getMessage());
|
LogFile.printErr(" fail. " + ex.getMessage());
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// debug rezim ?
|
/// debug rezim ?
|
||||||
///
|
///
|
||||||
if (config.getBoolean("debug")) {
|
if (config.getBoolean("debug")) {
|
||||||
LogFile.setDebug(true);
|
LogFile.setDebug(true);
|
||||||
LogFile.printDebug("Debug mode on");
|
LogFile.printDebug("Debug mode on");
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// okno
|
/// tray icon
|
||||||
///
|
///
|
||||||
///
|
new Tray().createAndShowTray();
|
||||||
/// tray icon
|
|
||||||
///
|
///
|
||||||
new Tray().createAndShowTray();
|
/// spustit minimalozovane ?
|
||||||
|
///
|
||||||
|
if (config.getBoolean("start_minimalized")) {
|
||||||
|
okno.setVisible(false);
|
||||||
|
} else {
|
||||||
|
okno.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spuštění klienta v novém vlákně
|
||||||
|
NettyClient client = new NettyClient(config.getString("server"), config.getInt("port"));
|
||||||
|
clientThread = new Thread(client);
|
||||||
|
clientThread.start();
|
||||||
|
|
||||||
///
|
|
||||||
/// spustit minimalozovane ?
|
|
||||||
///
|
|
||||||
if (config.getBoolean("start_minimalized")) {
|
|
||||||
okno.setVisible(false);
|
|
||||||
} else {
|
|
||||||
okno.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spuštění klienta v novém vlákně
|
|
||||||
NettyClient client = new NettyClient(config.getString("server"), config.getInt("port"));
|
|
||||||
clientThread = new Thread(client);
|
|
||||||
clientThread.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package jnet.client;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import jnet.client.gui.UIUpdater;
|
import jnet.client.gui.UIUpdater;
|
||||||
|
|
@ -16,6 +17,8 @@ import jnet.lib.object.OnlineClients;
|
||||||
import jnet.lib.object.ServerConfig;
|
import jnet.lib.object.ServerConfig;
|
||||||
import jnet.lib.object.SnmpProfile;
|
import jnet.lib.object.SnmpProfile;
|
||||||
import jnet.lib.object.User;
|
import jnet.lib.object.User;
|
||||||
|
import jnet.lib.snmp.DeviceInfo;
|
||||||
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
||||||
public class ClientMessageParser {
|
public class ClientMessageParser {
|
||||||
|
|
||||||
|
|
@ -45,6 +48,8 @@ public class ClientMessageParser {
|
||||||
handlers.put(Message.USER_EDIT, ClientMessageParser::handleUserEdit);
|
handlers.put(Message.USER_EDIT, ClientMessageParser::handleUserEdit);
|
||||||
handlers.put(Message.DELETE_LOG, ClientMessageParser::handleDeleteLog);
|
handlers.put(Message.DELETE_LOG, ClientMessageParser::handleDeleteLog);
|
||||||
handlers.put(Message.SERVER_CONFIG, ClientMessageParser::handleServerConfig);
|
handlers.put(Message.SERVER_CONFIG, ClientMessageParser::handleServerConfig);
|
||||||
|
handlers.put(Message.SNMP_OBJECT_INFO, ClientMessageParser::handleSnmpObjectInfo);
|
||||||
|
handlers.put(Message.SNMP_OBJECT_INTERFACE, ClientMessageParser:: handleSnmpObjectInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parse(Message msg) {
|
public static void parse(Message msg) {
|
||||||
|
|
@ -210,4 +215,17 @@ public class ClientMessageParser {
|
||||||
Client.serverConfig = (ServerConfig) msg.getMsg();
|
Client.serverConfig = (ServerConfig) msg.getMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleSnmpObjectInfo(Message msg) {
|
||||||
|
Object[] msg_obj = (Object[]) msg.getMsg();
|
||||||
|
String frame = (String) msg_obj[0];
|
||||||
|
DeviceInfo di = (DeviceInfo) msg_obj[1];
|
||||||
|
UIUpdater.updateObjectInfo(frame, di);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleSnmpObjectInterface(Message msg) {
|
||||||
|
Object[] msg_obj = (Object[]) msg.getMsg();
|
||||||
|
String frame = (String) msg_obj[0];
|
||||||
|
List<Interface> iface = (List<Interface>) msg_obj[1];
|
||||||
|
UIUpdater.updateObjectInterface(frame, iface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
package jnet.client.gui;
|
package jnet.client.gui;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.*;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.util.List;
|
||||||
|
import jnet.client.gui.dialog.object.ObjectDialog;
|
||||||
|
import jnet.lib.snmp.DeviceInfo;
|
||||||
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
||||||
public class UIUpdater {
|
public class UIUpdater {
|
||||||
|
|
||||||
|
|
@ -30,4 +34,26 @@ public class UIUpdater {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateObjectInfo(String frameName, DeviceInfo di) {
|
||||||
|
for (Window w : JFrame.getWindows()) {
|
||||||
|
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
((ObjectDialog) w).setDeviceInfo(di);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateObjectInterface(String frameName, List<Interface> iface) {
|
||||||
|
for (Window w : JFrame.getWindows()) {
|
||||||
|
if (w instanceof JFrame && frameName.equals(w.getName())) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
((ObjectDialog) w).setDeviceInterface(iface);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,16 @@ public class Window extends JFrame {
|
||||||
public Window() {
|
public Window() {
|
||||||
super(Client.APP_NAME); //titulek okna
|
super(Client.APP_NAME); //titulek okna
|
||||||
|
|
||||||
|
//identifikator okna
|
||||||
|
this.setName("mainWindow");
|
||||||
|
|
||||||
Dimension d = new Dimension(1024, 800);
|
Dimension d = new Dimension(1024, 800);
|
||||||
this.setPreferredSize(d);
|
this.setPreferredSize(d);
|
||||||
this.setSize(d);
|
this.setSize(d);
|
||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.setIconImage(ImageIO.read(new File("img/app.png")));
|
this.setIconImage(ImageIO.read(getClass().getResourceAsStream("/img/app.png")));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LogFile.printErr("APP icon exception");
|
LogFile.printErr("APP icon exception");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ package jnet.client.gui.dialog.object;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.regex.Matcher;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
@ -14,7 +13,8 @@ import jnet.client.network.NettyClient;
|
||||||
import jnet.lib.Message;
|
import jnet.lib.Message;
|
||||||
import jnet.lib.Status;
|
import jnet.lib.Status;
|
||||||
import jnet.lib.object.MapObject;
|
import jnet.lib.object.MapObject;
|
||||||
|
import jnet.lib.snmp.DeviceInfo;
|
||||||
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
||||||
public class ObjectDialog extends JFrame {
|
public class ObjectDialog extends JFrame {
|
||||||
|
|
||||||
|
|
@ -22,10 +22,18 @@ public class ObjectDialog extends JFrame {
|
||||||
private int mapId;
|
private int mapId;
|
||||||
private Boolean newObject;
|
private Boolean newObject;
|
||||||
|
|
||||||
|
private TabInfo tabInfo;
|
||||||
|
private TabSettings tabSettings;
|
||||||
|
private TabServices tabServices;
|
||||||
|
private TabEvents tabEvents;
|
||||||
|
|
||||||
public ObjectDialog(MapObject obj) {
|
public ObjectDialog(MapObject obj) {
|
||||||
this.obj = obj;
|
this.obj = obj;
|
||||||
this.mapId = obj.getMap();
|
this.mapId = obj.getMap();
|
||||||
this.newObject = false;
|
this.newObject = false;
|
||||||
|
|
||||||
|
// identifikator okna
|
||||||
|
this.setName("object_detail_" + obj.getId());
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,132 +45,135 @@ public class ObjectDialog extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
if (newObject) {
|
|
||||||
setTitle("Nový objekt");
|
|
||||||
} else {
|
|
||||||
setTitle(obj.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
setSize(600, 520);
|
if (newObject) {
|
||||||
setLocationRelativeTo(null);
|
setTitle("Nový objekt");
|
||||||
setVisible(true);
|
} else {
|
||||||
setAlwaysOnTop(false);
|
setTitle(obj.getName());
|
||||||
setResizable(false);
|
}
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setSize(600, 520);
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
setVisible(true);
|
||||||
|
setAlwaysOnTop(false);
|
||||||
|
setResizable(false);
|
||||||
|
|
||||||
JTabbedPane tabbedPane = new JTabbedPane();
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JTabbedPane tabbedPane = new JTabbedPane();
|
||||||
|
|
||||||
// JScrollPane tabNastaveni = new JScrollPane(tabNastaveni(),
|
// JScrollPane tabNastaveni = new JScrollPane(tabNastaveni(),
|
||||||
// JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
// JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
|
tabInfo = new TabInfo(this.getName(), obj);
|
||||||
|
tabSettings = new TabSettings(obj, newObject);
|
||||||
|
tabServices = new TabServices(obj, newObject);
|
||||||
|
tabEvents = new TabEvents(obj);
|
||||||
|
|
||||||
TabInfo tabInfo = new TabInfo();
|
tabbedPane.addTab("Informace", tabInfo);
|
||||||
TabSettings tabSettings = new TabSettings(obj, newObject);
|
tabbedPane.addTab("Nastaveni", tabSettings);
|
||||||
TabServices tabServices = new TabServices(obj, newObject);
|
tabbedPane.addTab("Služby", tabServices);
|
||||||
TabEvents tabEvents = new TabEvents(obj);
|
tabbedPane.addTab("Události", tabEvents);
|
||||||
|
//tabbedPane.addTab("Sondy", tabSondy());
|
||||||
|
|
||||||
tabbedPane.addTab("Informace", tabInfo);
|
// pokud se jedna o novy objekt
|
||||||
tabbedPane.addTab("Nastaveni", tabSettings);
|
if (newObject) {
|
||||||
tabbedPane.addTab("Služby", tabServices);
|
tabbedPane.setSelectedIndex(1); // prepne na kartu nastaveni
|
||||||
tabbedPane.addTab("Události", tabEvents);
|
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
||||||
//tabbedPane.addTab("Sondy", tabSondy());
|
tabbedPane.setEnabledAt(3, false); // vypne kartu udalosti
|
||||||
|
}
|
||||||
|
|
||||||
// pokud se jedna o novy objekt
|
add(tabbedPane, BorderLayout.CENTER);
|
||||||
if (newObject) {
|
|
||||||
tabbedPane.setSelectedIndex(1); // prepne na kartu nastaveni
|
|
||||||
tabbedPane.setEnabledAt(0, false); // vypne kartu informace
|
|
||||||
tabbedPane.setEnabledAt(3, false); // vypne kartu udalosti
|
|
||||||
}
|
|
||||||
|
|
||||||
add(tabbedPane, BorderLayout.CENTER);
|
JPanel pane = new JPanel();
|
||||||
|
JButton save = new JButton("Ulozit");
|
||||||
|
save.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// kontrola chyb
|
||||||
|
String nazev = tabSettings.getName();
|
||||||
|
if (nazev == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String ip = tabSettings.getIp();
|
||||||
|
if (ip == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// ulozeni do objektu
|
||||||
|
obj.setMap(mapId);
|
||||||
|
obj.setName(nazev);
|
||||||
|
obj.setIp(ip);
|
||||||
|
obj.setUser(tabSettings.getUser());
|
||||||
|
obj.setPassword(new String(tabSettings.getPassword()));
|
||||||
|
obj.setObjectType(Client.objectType.get(tabSettings.getObjType()).getId());
|
||||||
|
obj.setSnmpProfile(Client.snmpProfile.get(tabSettings.getSnmpProfile()).getId());
|
||||||
|
obj.setActive(tabSettings.isActive());
|
||||||
|
obj.setDescription(tabSettings.getDesc());
|
||||||
|
obj.setLocation(tabSettings.getLoc());
|
||||||
|
|
||||||
JPanel pane = new JPanel();
|
obj.setWinbox(tabServices.isWinbox());
|
||||||
JButton save = new JButton("Ulozit");
|
String winboxPort = tabServices.getWinboxPort();
|
||||||
save.addActionListener(new ActionListener() {
|
if (winboxPort == null) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
return;
|
||||||
// kontrola chyb
|
}
|
||||||
String nazev = tabSettings.getName();
|
obj.setWinboxPort(winboxPort);
|
||||||
if (nazev == null) {
|
obj.setSsh(tabServices.isSsh());
|
||||||
return;
|
String sshPort = tabServices.getSshPort();
|
||||||
}
|
if (sshPort == null) {
|
||||||
String ip = tabSettings.getIp();
|
return;
|
||||||
if (ip == null) {
|
}
|
||||||
return;
|
obj.setSshPort(sshPort);
|
||||||
}
|
obj.setWeb(tabServices.isWeb());
|
||||||
// ulozeni do objektu
|
String webPort = tabServices.getWebPort();
|
||||||
obj.setMap(mapId);
|
if (webPort == null) {
|
||||||
obj.setName(nazev);
|
return;
|
||||||
obj.setIp(ip);
|
}
|
||||||
obj.setUser(tabSettings.getUser());
|
obj.setWebPort(webPort);
|
||||||
obj.setPassword(new String(tabSettings.getPassword()));
|
obj.setWebVerze(tabServices.getWebVersion());
|
||||||
obj.setObjectType(Client.objectType.get(tabSettings.getObjType()).getId());
|
obj.setTelnet(tabServices.isTelnet());
|
||||||
obj.setSnmpProfile(Client.snmpProfile.get(tabSettings.getSnmpProfile()).getId());
|
String telnetPort = tabServices.getTelnetPort();
|
||||||
obj.setActive(tabSettings.isActive());
|
if (telnetPort == null) {
|
||||||
obj.setDescription(tabSettings.getDesc());
|
return;
|
||||||
obj.setLocation(tabSettings.getLoc());
|
}
|
||||||
// TODO validaci portu
|
obj.setTelnetPort(telnetPort);
|
||||||
obj.setWinbox(tabServices.isWinbox());
|
obj.setSms(tabServices.isSms());
|
||||||
obj.setWinboxPort(tabServices.getWinboxPort());
|
String smsPort = tabServices.getSmsPort();
|
||||||
obj.setSsh(tabServices.isSsh());
|
if (smsPort == null) {
|
||||||
obj.setSshPort(tabServices.getSshPort());
|
return;
|
||||||
obj.setWeb(tabServices.isWeb());
|
}
|
||||||
obj.setWebPort(tabServices.getWebPort());
|
obj.setSmsPort(smsPort);
|
||||||
obj.setWebVerze(tabServices.getWebVersion());
|
obj.setSmsVerze(tabServices.getSmsVersion());
|
||||||
obj.setTelnet(tabServices.isTelnet());
|
|
||||||
obj.setTelnetPort(tabServices.getTelnetPort());
|
|
||||||
obj.setSms(tabServices.isSms());
|
|
||||||
obj.setSmsPort(tabServices.getSmsPort());
|
|
||||||
obj.setSmsVerze(tabServices.getSmsVersion());
|
|
||||||
|
|
||||||
if (!obj.isActive() || newObject) {
|
if (!obj.isActive() || newObject) {
|
||||||
obj.setStatus(Status.NA);
|
obj.setStatus(Status.NA);
|
||||||
}
|
}
|
||||||
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
// ArrayList<SnmpProbe> probe = new ArrayList<>();
|
||||||
// if (!newObject) {
|
// if (!newObject) {
|
||||||
// probe.addAll(obj.getSnmpProbe());
|
// probe.addAll(obj.getSnmpProbe());
|
||||||
// }
|
// }
|
||||||
// obj.setSnmpProbe(probe);
|
// obj.setSnmpProbe(probe);
|
||||||
|
|
||||||
if (newObject) {
|
if (newObject) {
|
||||||
NettyClient.send(Message.ADD_OBJECT, obj);
|
NettyClient.send(Message.ADD_OBJECT, obj);
|
||||||
} else {
|
} else {
|
||||||
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
NettyClient.send(Message.UPDATE_OBJECT, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// zavreni dialogu
|
||||||
|
dispose();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
pane.add(save);
|
||||||
|
|
||||||
// zavreni dialogu
|
JButton cancel = new JButton("Zrusit");
|
||||||
dispose();
|
cancel.addActionListener(new ActionListener() {
|
||||||
}
|
public void actionPerformed(ActionEvent e) {
|
||||||
});
|
dispose();
|
||||||
pane.add(save);
|
}
|
||||||
|
});
|
||||||
JButton cancel = new JButton("Zrusit");
|
pane.add(cancel);
|
||||||
cancel.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pane.add(cancel);
|
|
||||||
|
|
||||||
add(pane, BorderLayout.PAGE_END);
|
|
||||||
|
|
||||||
|
add(pane, BorderLayout.PAGE_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean validatePort(String port) {
|
|
||||||
try {
|
|
||||||
int pNum = Integer.parseInt(port);
|
|
||||||
if ((pNum > 0) && (pNum < 65536)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String getStatus(int status) {
|
private String getStatus(int status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Status.OK: // online
|
case Status.OK: // online
|
||||||
|
|
@ -176,7 +187,15 @@ public class ObjectDialog extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDeviceInfo(DeviceInfo di){
|
||||||
|
this.tabInfo.setName(di.getSysName());
|
||||||
|
this.tabInfo.setDesc(di.getSysDescr());
|
||||||
|
this.tabInfo.setUptime(di.getSysUptime());
|
||||||
|
this.tabInfo.setVendor(di.getSysObjectID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceInterface(List<Interface> iface){
|
||||||
|
this.tabInfo.setInterface(iface);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,132 @@
|
||||||
package jnet.client.gui.dialog.object;
|
package jnet.client.gui.dialog.object;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import jnet.client.network.NettyClient;
|
||||||
|
import jnet.lib.Message;
|
||||||
|
import jnet.lib.object.MapObject;
|
||||||
|
import jnet.lib.snmp.Interface;
|
||||||
|
|
||||||
|
public class TabInfo extends JPanel {
|
||||||
|
|
||||||
public class TabInfo extends JPanel{
|
private String frameName;
|
||||||
|
private MapObject obj;
|
||||||
|
private JLabel uptime = new JLabel();
|
||||||
|
private JLabel name = new JLabel();
|
||||||
|
private JLabel description = new JLabel();
|
||||||
|
private JLabel vendor = new JLabel();
|
||||||
|
private DefaultTableModel tableModel;
|
||||||
|
private JTable ifaceTable;
|
||||||
|
|
||||||
public TabInfo() {
|
public TabInfo(String frameName, MapObject obj) {
|
||||||
|
this.obj = obj;
|
||||||
|
this.frameName = frameName;
|
||||||
|
init();
|
||||||
|
|
||||||
|
// odeslani SNMP dotazu na server
|
||||||
|
snmpRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
|
||||||
|
this.setLayout(null);
|
||||||
|
this.setBounds(0, 0, 600, 520);
|
||||||
|
|
||||||
|
int x1 = 20;
|
||||||
|
int x2 = 100;
|
||||||
|
int y = 30;
|
||||||
|
|
||||||
|
JLabel labelName = new JLabel("Název:");
|
||||||
|
labelName.setBounds(x1, y, 90, 30);
|
||||||
|
this.add(labelName);
|
||||||
|
name.setBounds(x2, y, 300, 30);
|
||||||
|
this.add(name);
|
||||||
|
y = y + 30;
|
||||||
|
|
||||||
|
JLabel labelDesc = new JLabel("Popis:");
|
||||||
|
labelDesc.setBounds(x1, y, 90, 30);
|
||||||
|
this.add(labelDesc);
|
||||||
|
description.setBounds(x2, y, 300, 30);
|
||||||
|
this.add(description);
|
||||||
|
y = y + 30;
|
||||||
|
|
||||||
|
JLabel labelVendor = new JLabel("Výrobce:");
|
||||||
|
labelVendor.setBounds(x1, y, 90, 30);
|
||||||
|
this.add(labelVendor);
|
||||||
|
vendor.setBounds(x2, y, 300, 30);
|
||||||
|
this.add(vendor);
|
||||||
|
y = y + 30;
|
||||||
|
|
||||||
|
JLabel labelUptime = new JLabel("Uptime:");
|
||||||
|
labelUptime.setBounds(x1, y, 90, 30);
|
||||||
|
this.add(labelUptime);
|
||||||
|
uptime.setBounds(x2, y, 300, 30);
|
||||||
|
this.add(uptime);
|
||||||
|
y = y + 30;
|
||||||
|
|
||||||
|
String column[] = {"Název", "Stav", "Admin", "Rychlost", "Typ", "Poslední změna"};
|
||||||
|
tableModel = new DefaultTableModel(column, 0) {
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int row, int column) {
|
||||||
|
//all cells false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ifaceTable = new JTable(tableModel);
|
||||||
|
ifaceTable.getTableHeader().setReorderingAllowed(false); // Zakáže přeskupování sloupců
|
||||||
|
ifaceTable.getTableHeader().setResizingAllowed(false); // Zakáže změnu velikosti sloupců
|
||||||
|
ifaceTable.getColumnModel().getColumn(0).setPreferredWidth(150); // Sloupec 0 bude mít šířku 100 px
|
||||||
|
ifaceTable.getColumnModel().getColumn(1).setPreferredWidth(40); // Sloupec 1 bude mít šířku 100 px
|
||||||
|
ifaceTable.getColumnModel().getColumn(2).setPreferredWidth(40); // Sloupec 2 bude mít šířku 100 px
|
||||||
|
ifaceTable.getColumnModel().getColumn(3).setPreferredWidth(50); // Sloupec 3 bude mít šířku 100 px
|
||||||
|
ifaceTable.getColumnModel().getColumn(4).setPreferredWidth(60); // Sloupec 4 bude mít šířku 100 px
|
||||||
|
//ifaceTable.getColumnModel().getColumn(5).setPreferredWidth(100); // Sloupec 5 bude mít šířku 100 px
|
||||||
|
|
||||||
|
JScrollPane tableScroll = new JScrollPane(ifaceTable);
|
||||||
|
tableScroll.setBounds(x1, y, (this.getWidth() - x1 * 3), 200);
|
||||||
|
this.add(tableScroll);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void snmpRequest() {
|
||||||
|
Object[] data = {frameName, this.obj};
|
||||||
|
NettyClient.send(Message.SNMP_OBJECT_INFO, data);
|
||||||
|
NettyClient.send(Message.SNMP_OBJECT_INTERFACE, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name.setText(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.description.setText(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUptime(String uptime) {
|
||||||
|
this.uptime.setText(uptime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVendor(String vendor) {
|
||||||
|
this.vendor.setText(vendor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInterface(List<Interface> iface) {
|
||||||
|
for (Interface i : iface) {
|
||||||
|
Object[] d = {
|
||||||
|
i.getDescription(),
|
||||||
|
i.getOperStatus(),
|
||||||
|
i.getAdminStatus(),
|
||||||
|
i.getSpeed(),
|
||||||
|
i.getType(),
|
||||||
|
i.getLastChangeTime()};
|
||||||
|
tableModel.addRow(d);
|
||||||
|
}
|
||||||
|
ifaceTable.revalidate();
|
||||||
|
ifaceTable.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,10 @@ class TabServices extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWinboxPort() {
|
public String getWinboxPort() {
|
||||||
return portWinbox.getText();
|
if (validatePort(portWinbox.getText())) {
|
||||||
|
return portWinbox.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSsh() {
|
public boolean isSsh() {
|
||||||
|
|
@ -128,7 +131,10 @@ class TabServices extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSshPort() {
|
public String getSshPort() {
|
||||||
return portSsh.getText();
|
if (validatePort(portSsh.getText())) {
|
||||||
|
return portSsh.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWeb() {
|
public boolean isWeb() {
|
||||||
|
|
@ -136,7 +142,10 @@ class TabServices extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWebPort() {
|
public String getWebPort() {
|
||||||
return portWww.getText();
|
if (validatePort(portWww.getText())) {
|
||||||
|
return portWww.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWebVersion() {
|
public int getWebVersion() {
|
||||||
|
|
@ -148,7 +157,10 @@ class TabServices extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTelnetPort() {
|
public String getTelnetPort() {
|
||||||
return portTelnet.getText();
|
if (validatePort(portTelnet.getText())) {
|
||||||
|
return portTelnet.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSms() {
|
public boolean isSms() {
|
||||||
|
|
@ -156,10 +168,24 @@ class TabServices extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSmsPort() {
|
public String getSmsPort() {
|
||||||
return portSms.getText();
|
if (validatePort(portSms.getText())) {
|
||||||
|
return portSms.getText();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSmsVersion() {
|
public int getSmsVersion() {
|
||||||
return smsVerzeComboBox.getSelectedIndex();
|
return smsVerzeComboBox.getSelectedIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validatePort(String port) {
|
||||||
|
try {
|
||||||
|
int pNum = Integer.parseInt(port);
|
||||||
|
if ((pNum > 0) && (pNum < 65536)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue