Compare commits
No commits in common. "main" and "verze3" have entirely different histories.
|
|
@ -1 +0,0 @@
|
|||
*.log
|
||||
73
build.xml
73
build.xml
|
|
@ -1,73 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="jNetLib" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project jNetLib.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="jNetLib-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -1,8 +0,0 @@
|
|||
build.xml.data.CRC32=237f5361
|
||||
build.xml.script.CRC32=83758712
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.113.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=237f5361
|
||||
nbproject/build-impl.xml.script.CRC32=30659ce6
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.113.0.48
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=jNetLib
|
||||
application.vendor=cucky
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.modulepath=\
|
||||
${run.modulepath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
debug.test.modulepath=\
|
||||
${run.test.modulepath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/jNetLib.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/jNetLib
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
file.reference.apache-commons-configuration2-2.9.0.jar=lib\\apache-commons-configuration2-2.9.0.jar
|
||||
file.reference.apache-commons-lang3-3.12.0.jar=lib\\apache-commons-lang3-3.12.0.jar
|
||||
file.reference.apache-commons-logging-1.2.jar=lib\\apache-commons-logging-1.2.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=\
|
||||
${file.reference.apache-commons-configuration2-2.9.0.jar}:\
|
||||
${file.reference.apache-commons-lang3-3.12.0.jar}:\
|
||||
${file.reference.apache-commons-logging-1.2.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
|
||||
javac.external.vm=true
|
||||
javac.modulepath=
|
||||
javac.processormodulepath=
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=23
|
||||
javac.target=23
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.modulepath=\
|
||||
${javac.modulepath}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.html5=false
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
# The jlink additional root modules to resolve
|
||||
jlink.additionalmodules=
|
||||
# The jlink additional command line parameters
|
||||
jlink.additionalparam=
|
||||
jlink.launcher=true
|
||||
jlink.launcher.name=jNetLib
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=true
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.modulepath=\
|
||||
${javac.modulepath}
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
run.test.modulepath=\
|
||||
${javac.test.modulepath}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>jNetLib</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>jnet</groupId>
|
||||
<artifactId>jNetLib</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<exec.mainClass>jnet.lib.JNetLib</exec.mainClass>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-configuration2</artifactId>
|
||||
<version>2.15.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-crypto</artifactId>
|
||||
<version>6.2.8</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.snmp4j</groupId>
|
||||
<artifactId>snmp4j</artifactId>
|
||||
<version>3.13.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import jnet.lib.object.Event;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class EventManager {
|
||||
|
||||
|
||||
private ArrayList<Event> events;
|
||||
|
||||
public static Event startPingEvent(ArrayList<Event> events, int object) {
|
||||
Instant now = Instant.now();
|
||||
long time = now.toEpochMilli();
|
||||
Event event = new Event(object,
|
||||
time,
|
||||
"Offline",
|
||||
Event.TYPE_PING);
|
||||
events.add(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
|
||||
public class LogWindow {
|
||||
|
||||
private JFrame frame = new JFrame("Log aplikace");
|
||||
private static JTextArea logTextArea = new JTextArea();
|
||||
|
||||
public LogWindow() {
|
||||
// Vytvoření hlavního okna
|
||||
|
||||
frame.setSize(1000, 600);
|
||||
|
||||
// Nastavení, že okno bude spuštěno minimalizované
|
||||
frame.setExtendedState(JFrame.ICONIFIED); // Minimalizované okno
|
||||
|
||||
// Přidání vlastního chování při zavření okna
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// Můžete přidat vlastní logiku (např. skrytí okna místo jeho zavření)
|
||||
//frame.setVisible(false); // Skrytí okna místo zavření
|
||||
}
|
||||
});
|
||||
|
||||
// Hlavní panel
|
||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||
|
||||
// Textová oblast pro logy
|
||||
|
||||
logTextArea.setEditable(false); // Zamezení úprav uživatelem
|
||||
logTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12)); // Monospace font pro logy
|
||||
|
||||
// Posuvník pro textovou oblast
|
||||
JScrollPane scrollPane = new JScrollPane(logTextArea);
|
||||
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
// Přidání scrollovacího panelu do hlavního panelu
|
||||
mainPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
// Přidání hlavního panelu do okna
|
||||
frame.add(mainPanel);
|
||||
|
||||
// Zobrazení okna
|
||||
frame.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
public static void addRow(String msg){
|
||||
logTextArea.append(msg + "\n");
|
||||
|
||||
// Automatické posunutí na konec
|
||||
logTextArea.setCaretPosition(logTextArea.getDocument().getLength());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import jnet.lib.object.Map;
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
public class MapComparator implements Comparator<Map> {
|
||||
|
||||
@Override
|
||||
public int compare(Map obj1, Map obj2) {
|
||||
return obj1.getName().compareTo(obj2.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author cucky
|
||||
*/
|
||||
public class Message implements Serializable {
|
||||
|
||||
// S->C: dotaz na verzi klient
|
||||
// C->S: odeslána verze klienta
|
||||
public static final int CLIENT_VERSION = 1;
|
||||
|
||||
// S->C: server odesila klientovi pokyn k updatu
|
||||
public static final int UPDATE = 2;
|
||||
|
||||
// S->C: server posila pozadavek na autorizaci klienta
|
||||
public static final int AUTH_REQUEST = 3;
|
||||
|
||||
// C->S: klient odesila autorizacni udaje
|
||||
public static final int AUTH = 4;
|
||||
|
||||
// S->C: server odesila informaci o uspesnem prihlaseni klienta
|
||||
public static final int AUTH_SUCEFULL = 5;
|
||||
|
||||
// S->C: server odesila informaci o neuspesnem prihlaseni klienta
|
||||
public static final int AUTH_FAIL = 6;
|
||||
|
||||
// S->C: server odesila seznam pripojenych klientu
|
||||
public static final int ONLINE_CLIENTS = 7;
|
||||
|
||||
// S->C: server posila typ objektu
|
||||
public static final int OBJECT_TYPE = 8;
|
||||
|
||||
// S->C server odesila informace o prihlasenem uzivateli
|
||||
public static final int USER_INFO = 9;
|
||||
|
||||
// C->S: klient odesíla novy typ objektu
|
||||
public static final int NEW_OBJECT_TYPE = 10;
|
||||
|
||||
// S->C: odesila uzivatele
|
||||
// C->S: klient pridává ukživatele
|
||||
public static final int USER = 11;
|
||||
|
||||
// C->S: klietn posila udaje upraveneho uzivatele
|
||||
public static final int USER_EDIT = 12;
|
||||
|
||||
// S->C: server posila nastaveni serveru
|
||||
// C->S: klient odesila upravu serveru
|
||||
public static final int SERVER_CONFIG = 13;
|
||||
|
||||
// C->S: klient posila požadavek na restart serveru
|
||||
public static final int RESTART = 15;
|
||||
|
||||
// C->S: klient se dotazuje na uptime server
|
||||
// S->C: server odesila uptim serveru
|
||||
public static final int UPTIME = 16;
|
||||
|
||||
|
||||
|
||||
// S->C: server posila mapu
|
||||
public static final int MAP = 100;
|
||||
|
||||
// S->C: server posila aktualizace statusu
|
||||
public static final int STATUS_UPDATE = 101;
|
||||
|
||||
// C->S: klient posila nove souradnice objektu
|
||||
public static final int OBJECT_MOVE = 102;
|
||||
|
||||
// C->S: klient posila zmenu zamku mapy
|
||||
public static final int SET_MAP_LOCK = 103;
|
||||
|
||||
// C->S: klient posila informaci o smazání objektu
|
||||
// S->C: server předává informaci o odebrání objektu
|
||||
public static final int REMOVE_OBJECT = 104;
|
||||
|
||||
// C->S: klient odesílá nově přidaný objekt
|
||||
// S->C: server odesila klientum nově přidany objekt
|
||||
public static final int ADD_OBJECT = 105;
|
||||
|
||||
// C->S: klient odesíla upravený objekt
|
||||
public static final int UPDATE_OBJECT = 106;
|
||||
|
||||
// S->C: server odesila SNMP profil
|
||||
public static final int SNMP_PROFILE = 107;
|
||||
|
||||
// S->C: server odesila novy event
|
||||
public static final int EVENT_NEW = 108;
|
||||
|
||||
// S->C: server odesila aktualizaci eventu
|
||||
public static final int EVENT_UPDATE = 109;
|
||||
|
||||
// S->C server odesilam seznam udalosti
|
||||
public static final int EVENT_LIST = 110;
|
||||
|
||||
// C->S: klient odebira mapu
|
||||
// S->C: server předává informaci o odebrani mapy
|
||||
public static final int MAP_REMOVE = 111;
|
||||
|
||||
// C->S: klient pridava mapu
|
||||
public static final int MAP_ADD = 112;
|
||||
|
||||
// C->S: klient posila požadavek na smazaní udalostí
|
||||
public static final int DELETE_LOG = 113;
|
||||
|
||||
// C->S: klient si vyžádal SNMP informace o bojektu
|
||||
public static final int SNMP_OBJECT_INFO = 114;
|
||||
|
||||
// C->S: klient si vyžádal SNMP informace o interface objektu
|
||||
public static final int SNMP_OBJECT_INTERFACE = 115;
|
||||
|
||||
// C->S: klient testuje snmp nastavení
|
||||
// S->C: server odesila vysledek testu
|
||||
public static final int SNMP_TEST = 116;
|
||||
|
||||
// C->S: klient si vyzadal SNMP seznam rozhrani objektu
|
||||
// S->C: klient odpovida seznam interfacu
|
||||
public static final int SNMP_CONNECTION_INTERFACE = 117;
|
||||
|
||||
// C->S: klient zasila na server informaci o novem spojeni
|
||||
// S->C: server rozesila nove spojeni
|
||||
public static final int CONNECTION_NEW = 118;
|
||||
|
||||
// S->C: server posila klientu trafic informaci
|
||||
public static final int TRAFFIC = 119;
|
||||
|
||||
// C->S: klient posila upravene spoení
|
||||
// S->C: server posila upravene spojeni
|
||||
public static final int CONNECTION_UPDATE = 120;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private int type;
|
||||
private Object msg;
|
||||
|
||||
public Message(int type, Object msg) {
|
||||
this.type = type;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Object getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(Object msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
public class OSValidator {
|
||||
|
||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
public static boolean isWindows() {
|
||||
|
||||
return (OS.indexOf("win") >= 0);
|
||||
|
||||
}
|
||||
|
||||
public static boolean isMac() {
|
||||
|
||||
return (OS.indexOf("mac") >= 0);
|
||||
|
||||
}
|
||||
|
||||
public static boolean isUnix() {
|
||||
|
||||
return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 );
|
||||
|
||||
}
|
||||
|
||||
public static boolean isSolaris() {
|
||||
|
||||
return (OS.indexOf("sunos") >= 0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class PropertiesManager {
|
||||
|
||||
private PropertiesConfiguration config;
|
||||
private String file;
|
||||
|
||||
// Konstruktor pro inicializaci s cestou k souboru
|
||||
public PropertiesManager(String file) {
|
||||
this.file = file;
|
||||
this.config = new PropertiesConfiguration();
|
||||
}
|
||||
|
||||
public void load() throws FileException, ConfigException {
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(file)) {
|
||||
if (input == null) {
|
||||
throw new FileException("Soubor config.properties nebyl nalezen.");
|
||||
}
|
||||
config.read(new InputStreamReader(input, StandardCharsets.UTF_8));
|
||||
} catch (ConfigurationException ex) {
|
||||
throw new ConfigException("Chyba konfigurace");
|
||||
} catch (IOException ex) {
|
||||
throw new FileException("Chybný soubor");
|
||||
}
|
||||
}
|
||||
|
||||
// Metoda pro čtení hodnoty podle klíče
|
||||
private String getProperty(String key) {
|
||||
return config.getString(key, null); // Vrací null pokud klíč neexistuje
|
||||
}
|
||||
|
||||
// Metoda pro nastavení hodnoty podle klíče
|
||||
private void setProperty(String key, String value) {
|
||||
config.setProperty(key, value);
|
||||
}
|
||||
|
||||
// Metoda pro uložení konfigurace do souboru
|
||||
public void save() {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
// Použití FileWriter pro zápis do souboru
|
||||
config.write(writer);
|
||||
LogFile.printInfo("Konfigurace byla uspesne ulozena.");
|
||||
} catch (IOException | ConfigurationException e) {
|
||||
LogFile.printErr("Chyba pri ukladani konfigurace. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Metoda pro výpis všech klíčů a hodnot v konfiguraci
|
||||
// public void printAllProperties() {
|
||||
// Iterator<String> keys = config.getKeys();
|
||||
// while (keys.hasNext()) {
|
||||
// String key = keys.next();
|
||||
// System.out.println(key + " = " + config.getString(key));
|
||||
// }
|
||||
// }
|
||||
public boolean getBoolean(String key) {
|
||||
return Boolean.valueOf(getProperty(key));
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return getProperty(key);
|
||||
}
|
||||
|
||||
public int getInt(String key) {
|
||||
return Integer.parseInt(getProperty(key));
|
||||
}
|
||||
|
||||
public void setBoolean(String key, Boolean value) {
|
||||
setProperty(key, value.toString());
|
||||
}
|
||||
|
||||
public void setInt(String key, int value) {
|
||||
setProperty(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setString(String key, String value) {
|
||||
setProperty(key, value);
|
||||
}
|
||||
|
||||
public class FileException extends Exception {
|
||||
|
||||
public FileException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfigException extends Exception {
|
||||
|
||||
public ConfigException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class Status implements Serializable {
|
||||
|
||||
public static final int NA = 0;
|
||||
public static final int OK = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int OFFLINE = 3;
|
||||
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Connection implements Serializable {
|
||||
|
||||
public static final int TYPE_OTHER = 0;
|
||||
public static final int TYPE_GE = 1;
|
||||
public static final int TYPE_FE = 2;
|
||||
public static final int TYPE_E = 3;
|
||||
public static final int TYPE_10GE = 4;
|
||||
public static final int TYPE_100M_FIBER = 5;
|
||||
public static final int TYPE_1G_FIBER = 6;
|
||||
public static final int TYPE_10G_FIBER = 7;
|
||||
public static final int TYPE_WIRELESS = 8;
|
||||
public static final int TYPE_TUNEL = 9;
|
||||
public static final int TYPE_VLAN = 10;
|
||||
|
||||
private int id;
|
||||
private int sourceObj;
|
||||
private int destinationObj;
|
||||
private int type;
|
||||
private int map;
|
||||
private boolean readTraffic;
|
||||
private int trafficObject;
|
||||
private int trafficIface;
|
||||
private long rx;
|
||||
private long tx;
|
||||
|
||||
public Connection(int id, int sourceObj, int destinationObj, int type, int map, boolean readTraffic, int trafficObject, int trafficIface) {
|
||||
this.id = id;
|
||||
this.sourceObj = sourceObj;
|
||||
this.destinationObj = destinationObj;
|
||||
this.type = type;
|
||||
this.map = map;
|
||||
this.readTraffic = readTraffic;
|
||||
this.trafficObject = trafficObject;
|
||||
this.trafficIface = trafficIface;
|
||||
this.rx = 0;
|
||||
this.tx = 0;
|
||||
}
|
||||
|
||||
public Connection(int sourceObj, int destinationObj, int type, int map, boolean readTraffic, int trafficObject, int trafficIface) {
|
||||
this.sourceObj = sourceObj;
|
||||
this.destinationObj = destinationObj;
|
||||
this.type = type;
|
||||
this.map = map;
|
||||
this.readTraffic = readTraffic;
|
||||
this.trafficObject = trafficObject;
|
||||
this.trafficIface = trafficIface;
|
||||
this.rx = 0;
|
||||
this.tx = 0;
|
||||
}
|
||||
|
||||
public Connection() {
|
||||
this.rx = 0;
|
||||
this.tx = 0;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getSourceObj() {
|
||||
return sourceObj;
|
||||
}
|
||||
|
||||
public void setSourceObj(int sourceObj) {
|
||||
this.sourceObj = sourceObj;
|
||||
}
|
||||
|
||||
public int getDestinationObj() {
|
||||
return destinationObj;
|
||||
}
|
||||
|
||||
public void setDestinationObj(int destinationObj) {
|
||||
this.destinationObj = destinationObj;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(int map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public boolean isReadTraffic() {
|
||||
return readTraffic;
|
||||
}
|
||||
|
||||
public void setReadTraffic(boolean readTraffic) {
|
||||
this.readTraffic = readTraffic;
|
||||
}
|
||||
|
||||
public int getTrafficObject() {
|
||||
return trafficObject;
|
||||
}
|
||||
|
||||
public void setTrafficObject(int trafficObject) {
|
||||
this.trafficObject = trafficObject;
|
||||
}
|
||||
|
||||
public int getTrafficIface() {
|
||||
return trafficIface;
|
||||
}
|
||||
|
||||
public void setTrafficIface(int trafficIface) {
|
||||
this.trafficIface = trafficIface;
|
||||
}
|
||||
|
||||
public String getRx() {
|
||||
return convertBps(rx);
|
||||
}
|
||||
|
||||
public void setRx(long rx) {
|
||||
this.rx = rx;
|
||||
}
|
||||
|
||||
public String getTx() {
|
||||
return convertBps(tx);
|
||||
}
|
||||
|
||||
public void setTx(long tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
public static String convertBps(long Bps) {
|
||||
double bitsPerSec = Bps * 8.0; // Převod na bity za sekundu jako double pro přesnost
|
||||
if (bitsPerSec >= 1_000_000_000) {
|
||||
return String.format("%.2f Gbps", bitsPerSec / 1_000_000_000.0);
|
||||
} else if (bitsPerSec >= 1_000_000) {
|
||||
return String.format("%.2f Mbps", bitsPerSec / 1_000_000.0);
|
||||
} else if (bitsPerSec >= 1_000) {
|
||||
return String.format("%.2f Kbps", bitsPerSec / 1_000.0);
|
||||
} else {
|
||||
return String.format("%.0f bps", bitsPerSec); // Zobrazení bez desetinných míst pro malé hodnoty
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class Event implements Serializable{
|
||||
|
||||
private int id;
|
||||
private int object;
|
||||
private long start;
|
||||
private long end;
|
||||
private String description;
|
||||
private int type;
|
||||
|
||||
public static final int TYPE_PING = 1;
|
||||
public static final int TYPE_SNMP = 2;
|
||||
public static final int TYPE_INFO = 3;
|
||||
public static final int TYPE_PING_OFF = 4;
|
||||
public static final int TYPE_PING_ON = 5;
|
||||
|
||||
public Event(int id, int object, long start, long end, String description, int type) {
|
||||
this.id = id;
|
||||
this.object = object;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Event(int object, long start, String description, int type) {
|
||||
this.object = object;
|
||||
this.start = start;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(int object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(long start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public long getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(long end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import jnet.lib.Status;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Map implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private boolean lock;
|
||||
private ArrayList<MapObject> objects;
|
||||
private ArrayList<Connection> connection;
|
||||
private int status;
|
||||
|
||||
public Map(int id, String name, boolean lock, ArrayList<MapObject> objects, ArrayList<Connection> connection) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lock = lock;
|
||||
this.status = Status.NA;
|
||||
this.objects = objects;
|
||||
this.connection = connection;
|
||||
|
||||
}
|
||||
|
||||
public Map(String name) {
|
||||
this.name = name;
|
||||
this.lock = false;
|
||||
this.status = Status.NA;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
public ArrayList<MapObject> getObjects() {
|
||||
return objects;
|
||||
}
|
||||
|
||||
public void setObjects(ArrayList<MapObject> objects) {
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
public ArrayList<Connection> getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(ArrayList<Connection> connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getStatus() {
|
||||
if (getObjects().isEmpty()) {
|
||||
return Status.NA;
|
||||
}
|
||||
|
||||
int status = Status.OK;
|
||||
|
||||
for (MapObject object : getObjects()) {
|
||||
int objectStatus = object.getStatus();
|
||||
|
||||
if (objectStatus == Status.OFFLINE) {
|
||||
return Status.OFFLINE; // Okamžitě vrátíme OFFLINE
|
||||
} else if (objectStatus == Status.WARNING) {
|
||||
status = Status.WARNING; // Možný downgrade na WARNING
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
package jnet.lib.snmp;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Interface implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String description;
|
||||
private String operStatus;
|
||||
private String speed;
|
||||
private String type;
|
||||
private String macAddress;
|
||||
private String adminStatus;
|
||||
private String lastChangeTime;
|
||||
|
||||
public Interface(int id, String description, String operStatus, String speed, String type, String macAddress, String adminStatus, String lastChangeTime) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.operStatus = operStatus;
|
||||
this.speed = speed;
|
||||
this.type = type;
|
||||
this.macAddress = macAddress;
|
||||
this.adminStatus = adminStatus;
|
||||
this.lastChangeTime = lastChangeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Interface ID: " + id + "\n"
|
||||
+ "Description: " + description + "\n"
|
||||
+ "Operational Status: " + operStatus + "\n"
|
||||
+ "Speed: " + speed + "\n"
|
||||
+ "Type: " + type + "\n"
|
||||
+ "MAC Address: " + macAddress + "\n"
|
||||
+ "Administrative Status: " + adminStatus + "\n"
|
||||
+ "Last Link Change: " + lastChangeTime + "\n";
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getOperStatus() {
|
||||
return operStatus;
|
||||
}
|
||||
|
||||
public void setOperStatus(String operStatus) {
|
||||
this.operStatus = operStatus;
|
||||
}
|
||||
|
||||
public String getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(String speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public void setMacAddress(String macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
}
|
||||
|
||||
public String getAdminStatus() {
|
||||
return adminStatus;
|
||||
}
|
||||
|
||||
public void setAdminStatus(String adminStatus) {
|
||||
this.adminStatus = adminStatus;
|
||||
}
|
||||
|
||||
public String getLastChangeTime() {
|
||||
return lastChangeTime;
|
||||
}
|
||||
|
||||
public void setLastChangeTime(String lastChangeTime) {
|
||||
this.lastChangeTime = lastChangeTime;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
package jnet.lib.snmp;
|
||||
|
||||
import org.snmp4j.*;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.smi.*;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SNMPDeviceInfo {
|
||||
|
||||
private Snmp snmp;
|
||||
private String address;
|
||||
private String community;
|
||||
private int version;
|
||||
|
||||
// SNMP OID pro základní informace
|
||||
private static final OID SYS_NAME_OID = new OID("1.3.6.1.2.1.1.5.0");
|
||||
private static final OID SYS_DESCR_OID = new OID("1.3.6.1.2.1.1.1.0");
|
||||
private static final OID SYS_UPTIME_OID = new OID("1.3.6.1.2.1.1.3.0");
|
||||
private static final OID SYS_CONTACT_OID = new OID("1.3.6.1.2.1.1.4.0");
|
||||
private static final OID SYS_LOCATION_OID = new OID("1.3.6.1.2.1.1.6.0");
|
||||
private static final OID SYS_OBJECT_ID_OID = new OID("1.3.6.1.2.1.1.2.0");
|
||||
|
||||
// OID databáze vyrobcu
|
||||
private static final Map<String, String> DEVICE_OID_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.9", "Cisco");
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.11", "Hewlett-Packard (HP)");
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.14988", "Mikrotik");
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.41112.1.3.1", "Ubiquiti Networks");
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.259.10.1.43.101", "EdgeCore");
|
||||
DEVICE_OID_MAP.put("1.3.6.1.4.1.11863.5.1048577", "TP-Link");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.43", "Lexmark");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.311", "Microsoft");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.3224", "Fortinet");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.8072", "Net-SNMP");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.2021", "Linux Host");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.171", "D-Link");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.12148", "MikroTik");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.2636", "Juniper Networks");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.674", "Dell");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.2352", "Allied Telesis");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.807", "IBM");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.562", "Alcatel");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.14988", "Ubiquiti Networks");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.22610", "Ruckus Wireless");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.318", "APC (Schneider Electric)");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.2011", "Huawei");
|
||||
// DEVICE_OID_MAP.put("1.3.6.1.4.1.4826", "Opengear");
|
||||
}
|
||||
|
||||
public SNMPDeviceInfo(String ip, String port, String community, int version) throws IOException {
|
||||
this.address = ip + "/" + port; // Přidání SNMP portu
|
||||
this.community = community;
|
||||
this.version = version;
|
||||
|
||||
TransportMapping<UdpAddress> transport = new DefaultUdpTransportMapping();
|
||||
snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Získání základních informací o zařízení.
|
||||
*/
|
||||
public DeviceInfo getDeviceInfo() throws IOException {
|
||||
DeviceInfo di = new DeviceInfo(
|
||||
getAsString(SYS_NAME_OID),
|
||||
getAsString(SYS_DESCR_OID),
|
||||
getAsString(SYS_UPTIME_OID),
|
||||
getAsString(SYS_CONTACT_OID),
|
||||
getAsString(SYS_LOCATION_OID),
|
||||
getDeviceVendor()
|
||||
);
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
/**
|
||||
* Získá sysObjectID a přeloží na výrobce
|
||||
*
|
||||
* @return Výrobce nebo "Neznámý" + OID
|
||||
* @throws IOException
|
||||
*/
|
||||
public String getDeviceVendor() throws IOException {
|
||||
String sysObjectID = getAsString(SYS_OBJECT_ID_OID);
|
||||
|
||||
// Překlad OID na výrobce
|
||||
for (String oidPrefix : DEVICE_OID_MAP.keySet()) {
|
||||
if (sysObjectID.startsWith(oidPrefix)) {
|
||||
return DEVICE_OID_MAP.get(oidPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
return "Neznámý výrobce (" + sysObjectID + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Získání hodnoty SNMP OID jako String.
|
||||
*/
|
||||
private String getAsString(OID oid) throws IOException {
|
||||
CommunityTarget target = createTarget();
|
||||
PDU pdu = new PDU();
|
||||
pdu.add(new VariableBinding(oid));
|
||||
pdu.setType(PDU.GET);
|
||||
|
||||
ResponseEvent event = snmp.get(pdu, target);
|
||||
if (event != null && event.getResponse() != null) {
|
||||
return event.getResponse().get(0).getVariable().toString();
|
||||
} else {
|
||||
return "No response";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Převede SNMP sysUpTime (setiny sekundy) na čitelný formát D HH:MM:SS
|
||||
*
|
||||
* @param sysUpTime setiny sekundy (centiseconds)
|
||||
* @return čitelný uptime
|
||||
*/
|
||||
private static String formatUptime(String sysUpTime) {
|
||||
System.out.println("jnet.lib.snmp.SNMPDeviceInfo.formatUptime() " +sysUpTime);
|
||||
try {
|
||||
long centiseconds = Long.parseLong(sysUpTime);
|
||||
long totalSeconds = centiseconds / 100;
|
||||
long days = totalSeconds / 86400;
|
||||
long hours = (totalSeconds % 86400) / 3600;
|
||||
long minutes = (totalSeconds % 3600) / 60;
|
||||
long seconds = totalSeconds % 60;
|
||||
|
||||
return String.format("%d dní, %02d:%02d:%02d", days, hours, minutes, seconds);
|
||||
} catch (NumberFormatException e) {
|
||||
return "Neplatný uptime";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vytvoření SNMP cíle (target).
|
||||
*/
|
||||
private CommunityTarget createTarget() {
|
||||
CommunityTarget target = new CommunityTarget();
|
||||
target.setCommunity(new OctetString(this.community));
|
||||
target.setAddress(new UdpAddress(this.address));
|
||||
target.setVersion(this.version);
|
||||
target.setRetries(2);
|
||||
target.setTimeout(1500);
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,280 +0,0 @@
|
|||
package jnet.lib.snmp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.snmp4j.CommunityTarget;
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.TransportMapping;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.smi.OID;
|
||||
import org.snmp4j.smi.OctetString;
|
||||
import org.snmp4j.smi.UdpAddress;
|
||||
import org.snmp4j.smi.VariableBinding;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
|
||||
public class SNMPInterfaceScanner {
|
||||
|
||||
private Snmp snmp;
|
||||
private String address;
|
||||
private String community;
|
||||
private int version;
|
||||
|
||||
// OID pro rozhraní v IF-MIB
|
||||
private static final String IF_INDEX_OID = "1.3.6.1.2.1.2.2.1.1"; // ifIndex
|
||||
private static final String IF_DESCR_OID = "1.3.6.1.2.1.2.2.1.2"; // ifDescr
|
||||
private static final String IF_SPEED_OID = "1.3.6.1.2.1.2.2.1.5"; // speed
|
||||
private static final String IF_TYPE_OID = "1.3.6.1.2.1.2.2.1.3"; // ifType
|
||||
private static final String IF_MAC_OID = "1.3.6.1.2.1.2.2.1.3"; // mac
|
||||
private static final String IF_STATUS_OID = "1.3.6.1.2.1.2.2.1.8"; // ifOperStatus
|
||||
private static final String IF_STATUS_ADM_OID = "1.3.6.1.2.1.2.2.1.7"; // adminStatus
|
||||
private static final String IF_LAST_CHANGE_OID = "1.3.6.1.2.1.2.2.1.9"; // lastchange
|
||||
|
||||
public SNMPInterfaceScanner(String address, String port, String community, int version) throws IOException {
|
||||
this.address = address + "/" + port;
|
||||
this.community = community;
|
||||
this.version = version;
|
||||
|
||||
TransportMapping<UdpAddress> transport = new DefaultUdpTransportMapping();
|
||||
snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
}
|
||||
|
||||
/**
|
||||
* Získání detailních informací o všech interfaces
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public List<Interface> scanInterfaces() throws IOException {
|
||||
List<Interface> list = new ArrayList<>();
|
||||
|
||||
CommunityTarget target = createTarget();
|
||||
|
||||
OID oid = new OID(IF_INDEX_OID); // Start na ifIndex
|
||||
boolean finished = false;
|
||||
|
||||
while (!finished) {
|
||||
PDU pdu = new PDU();
|
||||
pdu.add(new VariableBinding(oid));
|
||||
pdu.setType(PDU.GETNEXT);
|
||||
|
||||
ResponseEvent response = snmp.send(pdu, target);
|
||||
if (response == null || response.getResponse() == null) {
|
||||
System.out.println("Žádná odpověď od SNMP agenta.");
|
||||
break;
|
||||
}
|
||||
|
||||
VariableBinding vb = response.getResponse().get(0);
|
||||
OID nextOid = vb.getOid();
|
||||
|
||||
// Pokud jsme mimo tabulku, ukončit cyklus
|
||||
if (!nextOid.startsWith(new OID(IF_INDEX_OID))) {
|
||||
finished = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
int ifIndex = vb.getVariable().toInt();
|
||||
String ifDescr = getSnmpValue(IF_DESCR_OID + "." + ifIndex, target);
|
||||
String ifType = getSnmpValue(IF_TYPE_OID + "." + ifIndex, target);
|
||||
String ifStatus = getSnmpValue(IF_STATUS_OID + "." + ifIndex, target);
|
||||
String ifSpeed = getSnmpValue(IF_SPEED_OID + "." + ifIndex, target);
|
||||
String ifMac = getSnmpValue(IF_MAC_OID + "." + ifIndex, target);
|
||||
String ifStatusAdm = getSnmpValue(IF_STATUS_ADM_OID + "." + ifIndex, target);
|
||||
String ifLastChange = getSnmpValue(IF_LAST_CHANGE_OID + "." + ifIndex, target);
|
||||
|
||||
list.add(new Interface(
|
||||
ifIndex, // index
|
||||
ifDescr, // description
|
||||
getInterfaceStatus(ifStatus), // operStatus
|
||||
formatIfSpeed(Long.parseLong(ifSpeed)), // speed
|
||||
getInterfaceType(ifType), // type
|
||||
ifMac, //mac
|
||||
convertIfAdminStatus(ifStatusAdm), //adminStatus
|
||||
ifLastChange // lastChange
|
||||
));
|
||||
|
||||
// Posuneme OID na další položku
|
||||
oid = nextOid;
|
||||
}
|
||||
snmp.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pomocná metoda pro vytvoření SNMP cíle (target)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private CommunityTarget createTarget() {
|
||||
CommunityTarget target = new CommunityTarget();
|
||||
target.setCommunity(new OctetString(community));
|
||||
target.setAddress(new UdpAddress(address));
|
||||
target.setVersion(SnmpConstants.version2c);
|
||||
target.setRetries(2);
|
||||
target.setTimeout(1500);
|
||||
return target;
|
||||
}
|
||||
|
||||
private String getSnmpValue(String oid, CommunityTarget target) throws IOException {
|
||||
PDU pdu = new PDU();
|
||||
pdu.add(new VariableBinding(new OID(oid)));
|
||||
pdu.setType(PDU.GET);
|
||||
|
||||
ResponseEvent response = snmp.send(pdu, target);
|
||||
if (response != null && response.getResponse() != null) {
|
||||
return response.getResponse().get(0).getVariable().toString();
|
||||
}
|
||||
return "Neznámé";
|
||||
}
|
||||
|
||||
/**
|
||||
* prevadi ciselne oznaceni typu rozhrani na nazev
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private String getInterfaceType(String type) {
|
||||
switch (type) {
|
||||
case "1":
|
||||
return "Jiné";
|
||||
case "6":
|
||||
return "Ethernet";
|
||||
case "7":
|
||||
return "ISO 8802-3";
|
||||
case "9":
|
||||
return "Token Ring";
|
||||
case "15":
|
||||
return "FDDI";
|
||||
case "23":
|
||||
return "PPP";
|
||||
case "24":
|
||||
return "Loopback";
|
||||
case "28":
|
||||
return "ATM";
|
||||
case "32":
|
||||
return "Frame Relay";
|
||||
case "37":
|
||||
return "IP-over-ATM";
|
||||
case "53":
|
||||
return "Fibre Channel";
|
||||
case "62":
|
||||
return "Fast Ethernet (100 Mbps)";
|
||||
case "69":
|
||||
return "Gigabit Ethernet (1 Gbps)";
|
||||
case "71":
|
||||
return "WiFi (802.11)";
|
||||
case "94":
|
||||
return "ATM Subinterface";
|
||||
case "117":
|
||||
return "Gigabit Ethernet (1 Gbps)";
|
||||
case "131":
|
||||
return "Tunnel";
|
||||
case "135":
|
||||
return "VLAN";
|
||||
case "136":
|
||||
return "LACP (Link Aggregation)";
|
||||
case "161":
|
||||
return "ISDN";
|
||||
case "169":
|
||||
return "DSL";
|
||||
case "175":
|
||||
return "DOCSIS (kabelový modem)";
|
||||
case "181":
|
||||
return "ATM (PON)";
|
||||
case "182":
|
||||
return "Ethernet (PON)";
|
||||
case "209":
|
||||
return "Bridge";
|
||||
case "237":
|
||||
return "LTE";
|
||||
case "243":
|
||||
return "5G";
|
||||
default:
|
||||
return "(" + type + ") Neznámé ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prevadi ciselne oznaceni statusu rozhrani na nazev
|
||||
*
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
private String getInterfaceStatus(String status) {
|
||||
switch (status) {
|
||||
case "1":
|
||||
return "Up"; // up(1)
|
||||
case "2":
|
||||
return "Down"; // down(2)
|
||||
case "3":
|
||||
return "Testing"; // testing(3)
|
||||
case "4":
|
||||
return "Unknown"; // unknown(4)
|
||||
case "5":
|
||||
return "Dormant"; // dormant(5)
|
||||
case "6":
|
||||
return "No present"; // notPresent(6)
|
||||
case "7":
|
||||
return "Lower Layer Down"; // lowerLayerDown(7)
|
||||
default:
|
||||
return "Neznámé (" + status + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pomocná metoda pro rmátování času z Unixového formátu na čitelný
|
||||
*
|
||||
* @param unixTimestamp
|
||||
* @return
|
||||
*/
|
||||
private String formatTimestamp(String unixTimestamp) {
|
||||
try {
|
||||
long timestamp = Long.parseLong(unixTimestamp);
|
||||
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(timestamp * 1000));
|
||||
} catch (NumberFormatException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* funkce převede rychlost do citelnejsi podoby
|
||||
* @param ifSpeed
|
||||
* @return
|
||||
*/
|
||||
private static String formatIfSpeed(long ifSpeed) {
|
||||
String[] UNITS = {"bps", "kbps", "Mbps", "Gbps", "Tbps"};
|
||||
|
||||
if (ifSpeed <= 0) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
int unitIndex = 0;
|
||||
double speed = ifSpeed;
|
||||
|
||||
while (speed >= 1000 && unitIndex < UNITS.length - 1) {
|
||||
speed /= 1000;
|
||||
unitIndex++;
|
||||
}
|
||||
|
||||
long roundedSpeed = Math.round(speed); // Zaokrouhlení na celé číslo
|
||||
DecimalFormat df = new DecimalFormat("#,###"); // Oddělování tisíců
|
||||
|
||||
return df.format(roundedSpeed) + " " + UNITS[unitIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* prevede adm status na text
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
private static String convertIfAdminStatus(String status) {
|
||||
return switch (status) {
|
||||
case "1" -> "Up";
|
||||
case "2" -> "Down";
|
||||
case "3" -> "Testing";
|
||||
default -> "Unknown";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package jnet.lib.snmp;
|
||||
|
||||
|
||||
import org.snmp4j.*;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.smi.*;
|
||||
import org.snmp4j.transport.*;
|
||||
|
||||
public class SNMPTester {
|
||||
|
||||
private String address;
|
||||
private String community;
|
||||
private int version;
|
||||
|
||||
public SNMPTester(String address, String port, String community, int version) {
|
||||
this.address = address+"/"+port;
|
||||
this.community = community;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean testSnmp() {
|
||||
try {
|
||||
// Nastavení SNMP agenta
|
||||
TransportMapping transport = new DefaultUdpTransportMapping();
|
||||
Snmp snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
|
||||
// Cílový hostitel a community string
|
||||
Target target = new CommunityTarget();
|
||||
((CommunityTarget) target).setCommunity(new OctetString(this.community));
|
||||
target.setVersion(this.version);
|
||||
target.setAddress(new UdpAddress(this.address));
|
||||
target.setRetries(3); // Počet pokusů
|
||||
target.setTimeout(5000); // Timeout v milisekundách
|
||||
|
||||
// Odeslání SNMP požadavku na systémovou OID (sysDescr)
|
||||
PDU request = new PDU();
|
||||
request.add(new VariableBinding(SnmpConstants.sysDescr)); // OID pro systémový popis
|
||||
request.setType(PDU.GET);
|
||||
|
||||
// Odeslání požadavku
|
||||
ResponseEvent response = snmp.get(request, target);
|
||||
snmp.close(); // Ukončení SNMP komunikace
|
||||
|
||||
// Zpracování odpovědi
|
||||
if (response != null && response.getResponse() != null) {
|
||||
PDU pdu = response.getResponse();
|
||||
return true; // Funkční SNMP
|
||||
} else {
|
||||
return false; // Nefunkční SNMP
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false; // Chyba komunikace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,136 +0,0 @@
|
|||
package jnet.lib.snmp;
|
||||
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.TransportMapping;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.event.ResponseListener;
|
||||
import org.snmp4j.smi.*;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import org.snmp4j.CommunityTarget;
|
||||
|
||||
public class SNMPTrafficMonitor {
|
||||
|
||||
private String address;
|
||||
private String port;
|
||||
private String community;
|
||||
private int version;
|
||||
private int interfaceIndex;
|
||||
|
||||
private final List<TrafficListener> listeners = new ArrayList<>();
|
||||
private Snmp snmp;
|
||||
private Timer timer;
|
||||
|
||||
private long prevInOctets = -1;
|
||||
private long prevOutOctets = -1;
|
||||
private long prevTimestamp = -1;
|
||||
|
||||
// OIDy pro SNMP dotaz na traffic
|
||||
private static final String IF_IN_OCTETS = "1.3.6.1.2.1.2.2.1.10"; // Inbound traffic
|
||||
private static final String IF_OUT_OCTETS = "1.3.6.1.2.1.2.2.1.16"; // Outbound traffic
|
||||
|
||||
public SNMPTrafficMonitor(String targetAddress, String port, String community, int version, int interfaceIndex) {
|
||||
|
||||
this.address = targetAddress;
|
||||
this.port = port;
|
||||
this.community = community;
|
||||
this.version = version;
|
||||
this.interfaceIndex = interfaceIndex;
|
||||
}
|
||||
|
||||
public void addTrafficListener(TrafficListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void startMonitoring(long intervalMs) throws IOException {
|
||||
TransportMapping<UdpAddress> transport = new DefaultUdpTransportMapping();
|
||||
snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
|
||||
timer = new Timer(true);
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
queryTraffic();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 0, intervalMs);
|
||||
}
|
||||
|
||||
public void stopMonitoring() throws IOException {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
if (snmp != null) {
|
||||
snmp.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void queryTraffic() throws IOException {
|
||||
PDU pdu = new PDU();
|
||||
pdu.add(new VariableBinding(new OID(IF_IN_OCTETS + "." + interfaceIndex)));
|
||||
pdu.add(new VariableBinding(new OID(IF_OUT_OCTETS + "." + interfaceIndex)));
|
||||
pdu.setType(PDU.GET);
|
||||
|
||||
|
||||
CommunityTarget target = createTarget();
|
||||
|
||||
snmp.send(pdu, target, null, new ResponseListener() {
|
||||
@Override
|
||||
public void onResponse(ResponseEvent event) {
|
||||
PDU response = event.getResponse();
|
||||
if (response != null) {
|
||||
long inOctets = response.get(0).getVariable().toLong();
|
||||
long outOctets = response.get(1).getVariable().toLong();
|
||||
long currentTimestamp = System.currentTimeMillis();
|
||||
|
||||
if (prevInOctets != -1 && prevOutOctets != -1) {
|
||||
double elapsedSeconds = (currentTimestamp - prevTimestamp) / 1000.0;
|
||||
|
||||
long inBps = (long) ((inOctets - prevInOctets) / elapsedSeconds);
|
||||
long outBps = (long) ((outOctets - prevOutOctets) / elapsedSeconds);
|
||||
|
||||
// Zavoláme listener s hodnotami v Bps (Byte per Second)
|
||||
notifyListeners(inBps, outBps);
|
||||
}
|
||||
|
||||
prevInOctets = inOctets;
|
||||
prevOutOctets = outOctets;
|
||||
prevTimestamp = currentTimestamp;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyListeners(long inBps, long outBps) {
|
||||
for (TrafficListener listener : listeners) {
|
||||
listener.onTrafficUpdate(inBps, outBps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vytvoření SNMP cíle (target).
|
||||
*/
|
||||
private CommunityTarget createTarget() {
|
||||
CommunityTarget target = new CommunityTarget();
|
||||
target.setCommunity(new OctetString(this.community));
|
||||
target.setAddress(new UdpAddress(this.address+"/"+this.port));
|
||||
target.setVersion(this.version);
|
||||
target.setRetries(2);
|
||||
target.setTimeout(1500);
|
||||
return target;
|
||||
}
|
||||
|
||||
public interface TrafficListener {
|
||||
void onTrafficUpdate(long inBps, long outBps);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package jnet.lib;
|
||||
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
import org.apache.commons.configuration2.io.FileHandler;
|
||||
import java.io.File;
|
||||
import org.apache.commons.configuration2.io.FileBased;
|
||||
|
||||
public class ApacheConfig {
|
||||
|
||||
public static PropertiesConfiguration loadProperties() throws ConfigurationException {
|
||||
Configurations configs = new Configurations();
|
||||
File configFile = ResourceLoader.getFile("config.properties");
|
||||
return configs.properties(configFile);
|
||||
}
|
||||
|
||||
// Původní metoda pro FileBased (zachováváme pro přímé použití)
|
||||
public static void saveProperties(FileBased config) throws ConfigurationException {
|
||||
File configFile = ResourceLoader.getFile("config.properties");
|
||||
FileHandler handler = new FileHandler(config);
|
||||
handler.save(configFile);
|
||||
}
|
||||
|
||||
// NOVÁ metoda, která přijímá Configuration a zkontroluje, zda je FileBased
|
||||
public static void saveProperties(Configuration config) throws ConfigurationException {
|
||||
if (!(config instanceof FileBased)) {
|
||||
throw new ConfigurationException("Konfigurace nepodporuje ukládání do souboru.");
|
||||
}
|
||||
File configFile = ResourceLoader.getFile("config.properties");
|
||||
FileHandler handler = new FileHandler((FileBased) config);
|
||||
handler.save(configFile);
|
||||
}
|
||||
|
||||
// Druhá přetížená metoda pro FileBased se zadaným souborem
|
||||
public static void saveProperties(FileBased config, File file) throws ConfigurationException {
|
||||
FileHandler handler = new FileHandler(config);
|
||||
handler.save(file);
|
||||
}
|
||||
|
||||
// A přidej i verzi pro Configuration se souborem
|
||||
public static void saveProperties(Configuration config, File file) throws ConfigurationException {
|
||||
if (!(config instanceof FileBased)) {
|
||||
throw new ConfigurationException("Konfigurace nepodporuje ukládání do souboru.");
|
||||
}
|
||||
FileHandler handler = new FileHandler((FileBased) config);
|
||||
handler.save(file);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,32 +8,31 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class LogFile {
|
||||
|
||||
// nazev souboru
|
||||
private static final String outFile = "log.log";
|
||||
private static final String outFile = "log";
|
||||
// zapisovat i log do console
|
||||
private static boolean consoleLog = true;
|
||||
// format datumu a casu
|
||||
private static String dateFormat = "dd.MM.YY HH:m:ss";
|
||||
// debug rezim
|
||||
private static boolean debug = false;
|
||||
|
||||
|
||||
private static File out = new File(outFile);
|
||||
|
||||
|
||||
private static final DateFormat df = new SimpleDateFormat(dateFormat);
|
||||
|
||||
|
||||
private static void write(Object text, boolean line) {
|
||||
|
||||
String date = df.format(new Date());
|
||||
|
||||
try {
|
||||
if (!out.exists()) {
|
||||
out.createNewFile();
|
||||
}
|
||||
PrintWriter pwOut = new PrintWriter(new FileOutputStream(out, true), true);
|
||||
pwOut.print(date);
|
||||
pwOut.print(df.format(new Date()));
|
||||
pwOut.write("\t");
|
||||
if (line) {
|
||||
pwOut.println(text);
|
||||
|
|
@ -41,39 +40,40 @@ public class LogFile {
|
|||
pwOut.print(text);
|
||||
}
|
||||
pwOut.close();
|
||||
|
||||
LogWindow.addRow(date + "\t" + text.toString());
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void printErr(String line) {
|
||||
write("E\t" + line, true);
|
||||
String l = StringUtils.stripAccents(line);
|
||||
write("E\t" + l, true);
|
||||
if (consoleLog) {
|
||||
System.err.println(line);
|
||||
System.err.println(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void printInfo(String line) {
|
||||
write("I\t" + line, true);
|
||||
String l = StringUtils.stripAccents(line);
|
||||
write("I\t" + l, true);
|
||||
if (consoleLog) {
|
||||
System.out.println(line);
|
||||
System.out.println(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void printDebug(String line) {
|
||||
write("D\t" + line, true);
|
||||
String l = StringUtils.stripAccents(line);
|
||||
write("D\t" + l, true);
|
||||
if (debug) {
|
||||
if (consoleLog) {
|
||||
System.out.println(line);
|
||||
System.out.println(l);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void clear() {
|
||||
try {
|
||||
out.delete();
|
||||
|
|
@ -81,9 +81,9 @@ public class LogFile {
|
|||
Logger.getLogger(LogFile.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void setDebug(boolean b) {
|
||||
debug = b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.util.Comparator;
|
||||
import jnet.lib.object.Site;
|
||||
|
||||
|
||||
public class MapComparator implements Comparator<Site> {
|
||||
|
||||
@Override
|
||||
public int compare(Site obj1, Site obj2) {
|
||||
return obj1.getName().compareTo(obj2.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Message implements Serializable {
|
||||
|
||||
// S->C pozadavak na aktualizaci klienta
|
||||
public static final int CLIENT_UPDATE = 101;
|
||||
// S->C pozadavek na autorizaci
|
||||
public static final int AUTH_REQUEST = 102;
|
||||
// S->C autorizace uspesna
|
||||
public static final int AUTH_OK = 103;
|
||||
// S->C autorizace selhala
|
||||
public static final int AUTH_FAIL = 104;
|
||||
// S->C server odesila novy seznam pripojenych klientu
|
||||
public static final int ONLINE_CLIENTS = 105;
|
||||
// S->C odesila seznam vsech site
|
||||
public static final int SITE_LIST = 106;
|
||||
// S->C nová mapa
|
||||
public static int SITE_NEW = 107;
|
||||
// S->C zmena online stavu node
|
||||
public static int NODE_STATUS_CHANGE = 108;
|
||||
// S->C nastaveni serveru
|
||||
public static int SERVER_CONFIG = 109;
|
||||
// S->C server uptime
|
||||
public static int SERVER_UPTIME_RESULT = 110;
|
||||
// S->C informace o prihlasenem uzivateli
|
||||
public static final int USER_INFO = 111;
|
||||
// S->C seznam object type
|
||||
public static final int NODE_ICON_LIST = 112;
|
||||
// S->C seznam uzivatelu
|
||||
public static final int USER_LIST = 113;
|
||||
// S->C novy uzivatel - pokyn k aktualizaci tabulky
|
||||
public static int USER_REFRESH = 114;
|
||||
// S->C nova ikona - pokyn k aktualizaci tabulky
|
||||
public static final int NODE_ICON_REFRESH = 115;
|
||||
// S->C seznam udalost
|
||||
public static final int EVENT_LIST = 116;
|
||||
// S->C nova udalost
|
||||
public static final int EVENT_NEW = 117;
|
||||
// S->C aktualizace udalost
|
||||
public static final int EVENT_UPDATE = 118;
|
||||
// S->C aktualizace pozice
|
||||
public static final int NODE_CHANGE_POSITION = 119;
|
||||
// S->C novy node
|
||||
public static final int NODE_NEW = 120;
|
||||
// S->C nastaveni zamku mapy
|
||||
public static final int SITE_LOCK = 121;
|
||||
// S->C odebrani node
|
||||
public static final int NODE_REMOVE = 122;
|
||||
// S->C node update
|
||||
public static final int NODE_UPDATE = 123;
|
||||
// S->C seznam snmp profilu
|
||||
public static final int SNMP_PROFILE_LIST = 124;
|
||||
// S->C snmp test
|
||||
public static final int SNMP_TEST_RESULT = 125;
|
||||
// S->C SNMP dotaz info zarizeni
|
||||
public static final int NODE_SNMP_INFO_RESULT = 126;
|
||||
// S->C SNMP dotaz interface zarizeni
|
||||
public static final int NODE_SNMP_INTERFACE_RESULT = 127;
|
||||
// S->C nove spojeni objektu
|
||||
public static final int NODE_CONNECTION_ADD = 128;
|
||||
// S->C uprava node connection
|
||||
public static final int NODE_CONNECTION_CHANGE = 129;
|
||||
// S->C dotaz z dialogu connection na interface node
|
||||
public static final int NODE_CONNECTION_SNMP_INTERFACE_RESULT = 130;
|
||||
// S->C seznam snmp sablon
|
||||
public static final int SNMP_TEMPLATE_LIST = 131;
|
||||
// S->C seznam snmp value map
|
||||
public static final int SNMP_TEMPLATE_VALUE_MAP_LIST = 132;
|
||||
// S->C snmp probe hodnota
|
||||
public static final int SNMP_PROBE_VALUE = 133;
|
||||
// S->C data z traffic monitoru
|
||||
public static final int NODE_CONNECTION_TRAFFIC = 134;
|
||||
// S->C informace o smazenem connection
|
||||
public static final int NODE_CONNECTION_REMOVE = 135;
|
||||
// S->C novy snmp profile
|
||||
public static final int SNMP_PROFILE_NEW_RESULT = 136;
|
||||
// S->C upraveny snmp profile
|
||||
public static final int SNMP_PROFILE_EDIT_RESULT = 137;
|
||||
// S->C odstraneni snmp profilu
|
||||
public static final int SNMP_PROFILE_DELETE_RESULT = 138;
|
||||
// S->C editace node probe
|
||||
public static final int NODE_PROBE_EDIT_RESULT = 139;
|
||||
// S->C smazani node probe
|
||||
public static final int NODE_PROBE_DELETE_RESULT = 140;
|
||||
// S->C nova node probe
|
||||
public static final int NODE_PROBE_NEW_RESULT = 141;
|
||||
// S->C pridani snmp template
|
||||
public static final int SNMP_TEMPLATE_NEW_RESULT = 142;
|
||||
// S->C editace snmp template
|
||||
public static final int SNMP_TEMPLATE_EDIT_RESULT = 143;
|
||||
// S->C smazani snmp template
|
||||
public static final int SNMP_TEMPLATE_DELETE_RESULT = 144;
|
||||
// C->S smazani device type
|
||||
public static final int DEVICE_TYPE_DELETE_RESULT = 145;
|
||||
// S->C smazani uzovatele
|
||||
public static final int USER_DELETE_RESULT = 146;
|
||||
// S->C odpoved uzivatelskeho pingu
|
||||
public static final int USER_PING_RESPONSE = 147;
|
||||
// S->C start uzivatelskeho pingu
|
||||
public static final int USER_PING_STARTED = 148;
|
||||
// S->C stop uzivatelskeho pingu
|
||||
public static final int USER_PING_STOPPED = 149;
|
||||
// S->C log serveru
|
||||
public static final int SERVER_LOG_RESULT = 150;
|
||||
// S->C nove snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_NEW_RESULT = 151;
|
||||
// S->C uprava snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_EDIT_RESULT = 152;
|
||||
// S->C smazani snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_DELETE_RESULT = 153;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
|
||||
// C->S verze klienta
|
||||
public static final int CLIENT_TYPE = 501;
|
||||
// C->S autorizacni data
|
||||
public static final int AUTH_DATA = 502;
|
||||
// C->S pridani mapy
|
||||
public static final int SITE_ADD = 503;
|
||||
// C-S pridani uzivatele
|
||||
public static final int USER_ADD = 504;
|
||||
// C->S editace uzivatele
|
||||
public static final int USER_EDIT = 505;
|
||||
// C->S uprava nastaveni serveru
|
||||
public static final int SERVER_CONFIG_EDIT = 506;
|
||||
// C->S pokyn k restartu serveru
|
||||
public static final int SERVER_RESTART = 507;
|
||||
// C->S nova ikona zařízení
|
||||
public static final int NODE_ICON_NEW = 508;
|
||||
// C->S smazani mapy
|
||||
public static final int SITE_DELETE = 509;
|
||||
// C->S presun node
|
||||
public static final int NODE_POSITION_CHANGE = 510;
|
||||
// C->S novy node
|
||||
public static final int NODE_ADD = 511;
|
||||
// C->S node edit
|
||||
public static final int NODE_CHANGE = 512;
|
||||
// C->S node connection novy
|
||||
public static final int NODE_CONNECTION_NEW = 513;
|
||||
// C->S nastaveni zamku mapy
|
||||
public static final int SITE_SET_LOCK = 514;
|
||||
// C->S smazani node
|
||||
public static final int NODE_DELETE = 515;
|
||||
// C->S snmp test
|
||||
public static final int SNMP_TEST = 516;
|
||||
// C->S dotaz na uptime
|
||||
public static final int SERVER_UPTIME = 517;
|
||||
// C->S SNMP dotaz info zarizeni
|
||||
public static final int NODE_SNMP_INFO = 518;
|
||||
// C->S SNMP dotaz interface zarizeni
|
||||
public static final int NODE_SNMP_INTERFACE = 519;
|
||||
// C->S přesun node na jinou mapu
|
||||
public static final int NODE_MOVE_TO_SITE = 520;
|
||||
// C->S uprava node spojeni
|
||||
public static final int NODE_CONNECTION_EDIT = 521;
|
||||
// C->S dotaz z dialogu connection na interface node
|
||||
public static final int NODE_CONNECTION_SNMP_INTERFACE = 522;
|
||||
// C->S nova node probe
|
||||
public static final int NODE_PROBE_NEW = 523;
|
||||
// C->S odstraneni connection
|
||||
public static final int NODE_CONNECTION_DELETE = 524;
|
||||
// C->S novy snmp profil
|
||||
public static final int SNMP_PROFILE_NEW = 525;
|
||||
// C->S upraveny snmp profile
|
||||
public static final int SNMP_PROFILE_EDIT = 526;
|
||||
// C->S odstraneni snmp profilu
|
||||
public static final int SNMP_PROFILE_DELETE = 527;
|
||||
// C->S uprava node probe
|
||||
public static final int NODE_PROBE_EDIT = 528;
|
||||
// C->S smazani node probe
|
||||
public static final int NODE_PROBE_DELETE = 529;
|
||||
// C->S pridani snmp template
|
||||
public static final int SNMP_TEMPLATE_NEW = 530;
|
||||
// C->S editace snmp template
|
||||
public static final int SNMP_TEMPLATE_EDIT = 531;
|
||||
// C->S smazani snmp template
|
||||
public static final int SNMP_TEMPLATE_DELETE = 532;
|
||||
// C->S smazani device type
|
||||
public static final int DEVICE_TYPE_DELETE = 533;
|
||||
// C->S smazani uzovatele
|
||||
public static final int USER_DELETE = 534;
|
||||
// C->S uzivatelsky ping start
|
||||
public static final int USER_PING_START = 535;
|
||||
// C->S uzivatelsky ping stop
|
||||
public static final int USER_PING_STOP = 536;
|
||||
// C->S dotaz na log serveru
|
||||
public static final int SERVER_LOG = 537;
|
||||
// C->S nove snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_NEW = 538;
|
||||
// C->S uprava snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_EDIT = 539;
|
||||
// C->S smazani snmp mapovani hodnot
|
||||
public static final int VALUE_MAP_DELETE = 540;
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int type;
|
||||
private Object message;
|
||||
|
||||
public Message(int type, Object message) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setMsg(Object message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Object getMsg() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Detekce operačního systému – rozlišení Windows vs. Debian (případně jiný).
|
||||
*/
|
||||
public class OSDetector {
|
||||
|
||||
public enum OS {
|
||||
WINDOWS,
|
||||
DEBIAN,
|
||||
OTHER
|
||||
}
|
||||
|
||||
/**
|
||||
* Vrátí aktuální operační systém.
|
||||
*/
|
||||
public static OS detect() {
|
||||
if (isWindows()) {
|
||||
return OS.WINDOWS;
|
||||
}
|
||||
if (isDebian()) {
|
||||
return OS.DEBIAN;
|
||||
}
|
||||
return OS.OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Je systém Windows?
|
||||
*/
|
||||
public static boolean isWindows() {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
return osName.contains("windows");
|
||||
}
|
||||
|
||||
/**
|
||||
* Je systém Debian? (čistý Debian, nikoli deriváty jako Ubuntu)
|
||||
*/
|
||||
public static boolean isDebian() {
|
||||
// Detekce podle /etc/os-release, aby se odlišil Debian od ostatních distribucí.
|
||||
Path osRelease = Paths.get("/etc/os-release");
|
||||
if (!Files.isRegularFile(osRelease)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(osRelease);
|
||||
for (String line : lines) {
|
||||
// Hledáme řádek "ID=debian"
|
||||
if (line.startsWith("ID=")) {
|
||||
String value = line.substring(3).replaceAll("^\"|\"$", "").trim();
|
||||
return "debian".equalsIgnoreCase(value);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Soubor existuje, ale nepodařilo se přečíst – nebudeme riskovat.
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import jnet.lib.object.PingResult;
|
||||
|
||||
public class PingResponseParser {
|
||||
|
||||
// Regex pro Windows i Linux odpovědi
|
||||
private static final Pattern PATTERN = Pattern.compile(
|
||||
"(?:Reply from |bytes from )?(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})" + // IP
|
||||
"(?:[: ])?" +
|
||||
".*?bytes=(\\d+)" + // bytes
|
||||
".*?time[=<](\\d+)" + // time (může být = nebo <)
|
||||
"ms" +
|
||||
".*?TTL=(\\d+)", // TTL
|
||||
Pattern.CASE_INSENSITIVE | Pattern.DOTALL
|
||||
);
|
||||
|
||||
public static PingResult parse(String line) {
|
||||
if (line == null || line.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Zkusíme najít shodu
|
||||
Matcher m = PATTERN.matcher(line);
|
||||
if (m.find()) {
|
||||
try {
|
||||
String ip = m.group(1);
|
||||
int bytes = Integer.parseInt(m.group(2));
|
||||
long timeMs = Long.parseLong(m.group(3));
|
||||
int ttl = Integer.parseInt(m.group(4));
|
||||
return new PingResult(ip, bytes, timeMs, ttl, true);
|
||||
} catch (NumberFormatException e) {
|
||||
// čísla nešla parsovat – vrátíme neúspěch
|
||||
return new PingResult(null, 0, 0, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Pokud neodpovídá úspěšné odpovědi, může to být "Request timed out." apod.
|
||||
if (line.toLowerCase().contains("timed out") || line.toLowerCase().contains("unreachable")) {
|
||||
return new PingResult(null, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
return null; // neznámý formát
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class ResourceLoader {
|
||||
|
||||
/**
|
||||
* Vrátí objekt File pro zadanou relativní cestu. Nejprve hledá vedle JARu /
|
||||
* v pracovním adresáři. Pokud nenajde, hledá v adresářové struktuře
|
||||
* projektu (pro vývoj v IDE).
|
||||
*/
|
||||
public static File getFile(String relativePath) {
|
||||
File prodFile = null;
|
||||
try {
|
||||
// 1. Produkční cesta (přímo vedle JARu / v kořeni spuštění)
|
||||
String jarPath = ResourceLoader.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().toURI().getPath();
|
||||
File jarFile = new File(jarPath);
|
||||
prodFile = new File(jarFile.getParent(), relativePath);
|
||||
if (prodFile.exists()) {
|
||||
return prodFile;
|
||||
}
|
||||
|
||||
// 2. Vývojářská cesta pro IDE (NetBeans spouští projekt z kořene jNetServer/)
|
||||
File ideFile = new File("src/main/resources", relativePath);
|
||||
if (ideFile.exists()) {
|
||||
return ideFile;
|
||||
}
|
||||
|
||||
} catch (URISyntaxException ex) {
|
||||
System.getLogger(ResourceLoader.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
|
||||
}// Pokud soubor nikde neexistuje, vrátí původní cestu (vyhodí standardní chybu v aplikaci)
|
||||
return prodFile;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
package jnet.lib;
|
||||
|
||||
import org.snmp4j.CommunityTarget;
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
import org.snmp4j.util.DefaultPDUFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import jnet.lib.object.SnmpWalkItem;
|
||||
import org.snmp4j.smi.OID;
|
||||
import org.snmp4j.smi.SMIConstants;
|
||||
import org.snmp4j.smi.VariableBinding;
|
||||
|
||||
public class SnmpWalk {
|
||||
|
||||
private static final int MAX_REPETITIONS = 50;
|
||||
|
||||
public static List<SnmpWalkItem> walk(String rootOid, CommunityTarget target, AtomicBoolean cancelFlag) throws Exception {
|
||||
List<SnmpWalkItem> result = new ArrayList<>();
|
||||
|
||||
try (DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping(); Snmp snmp = new Snmp(transport)) {
|
||||
transport.listen();
|
||||
|
||||
int pduType = (target.getVersion() == SnmpConstants.version1) ? PDU.GETNEXT : PDU.GETBULK;
|
||||
DefaultPDUFactory pduFactory = new DefaultPDUFactory(pduType);
|
||||
|
||||
OID currentOid = new OID(rootOid);
|
||||
boolean finished = false;
|
||||
|
||||
while (!finished && !cancelFlag.get() && !Thread.currentThread().isInterrupted()) {
|
||||
PDU pdu = pduFactory.createPDU(target);
|
||||
if (pduType == PDU.GETBULK) {
|
||||
pdu.setMaxRepetitions(MAX_REPETITIONS);
|
||||
}
|
||||
pdu.add(new VariableBinding(currentOid));
|
||||
|
||||
ResponseEvent event = snmp.send(pdu, target);
|
||||
if (event == null) {
|
||||
break;
|
||||
}
|
||||
PDU responsePDU = event.getResponse();
|
||||
if (responsePDU == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Oprava: používáme List, nikoli pole
|
||||
List<? extends VariableBinding> vbs = responsePDU.getVariableBindings();
|
||||
if (vbs == null || vbs.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (VariableBinding vb : vbs) {
|
||||
if (vb == null) {
|
||||
continue;
|
||||
}
|
||||
OID oid = vb.getOid();
|
||||
if (oid == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int syntax = vb.getVariable().getSyntax();
|
||||
|
||||
if (syntax == SMIConstants.EXCEPTION_END_OF_MIB_VIEW) {
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
if (syntax == SMIConstants.EXCEPTION_NO_SUCH_OBJECT
|
||||
|| syntax == SMIConstants.EXCEPTION_NO_SUCH_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.add(new SnmpWalkItem(
|
||||
oid.toString(),
|
||||
vb.getVariable().toString(),
|
||||
getTypeName(syntax)
|
||||
));
|
||||
currentOid = oid;
|
||||
}
|
||||
}
|
||||
|
||||
if (cancelFlag.get() || Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException("Walk byl přerušen uživatelem.");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getTypeName(int syntax) {
|
||||
switch (syntax) {
|
||||
case SMIConstants.SYNTAX_INTEGER:
|
||||
return "Integer32";
|
||||
case SMIConstants.SYNTAX_OCTET_STRING:
|
||||
return "OctetString";
|
||||
case SMIConstants.SYNTAX_NULL:
|
||||
return "Null";
|
||||
case SMIConstants.SYNTAX_OBJECT_IDENTIFIER:
|
||||
return "OID";
|
||||
case SMIConstants.SYNTAX_IPADDRESS:
|
||||
return "IpAddress";
|
||||
case SMIConstants.SYNTAX_COUNTER32:
|
||||
return "Counter32";
|
||||
case SMIConstants.SYNTAX_GAUGE32:
|
||||
return "Gauge32";
|
||||
case SMIConstants.SYNTAX_TIMETICKS:
|
||||
return "TimeTicks";
|
||||
case SMIConstants.SYNTAX_OPAQUE:
|
||||
return "Opaque";
|
||||
case SMIConstants.SYNTAX_COUNTER64:
|
||||
return "Counter64";
|
||||
case SMIConstants.EXCEPTION_NO_SUCH_OBJECT:
|
||||
return "NoSuchObject";
|
||||
case SMIConstants.EXCEPTION_NO_SUCH_INSTANCE:
|
||||
return "NoSuchInstance";
|
||||
case SMIConstants.EXCEPTION_END_OF_MIB_VIEW:
|
||||
return "EndOfMibView";
|
||||
default:
|
||||
return "Unknown (" + syntax + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static int getTypeId(String syntax) {
|
||||
switch (syntax) {
|
||||
case "Integer32":
|
||||
return SMIConstants.SYNTAX_INTEGER;
|
||||
case "OctetString":
|
||||
return SMIConstants.SYNTAX_OCTET_STRING;
|
||||
case "Null":
|
||||
return SMIConstants.SYNTAX_NULL;
|
||||
case "OID":
|
||||
return SMIConstants.SYNTAX_OBJECT_IDENTIFIER;
|
||||
case "IpAddress":
|
||||
return SMIConstants.SYNTAX_IPADDRESS;
|
||||
case "Gauge32":
|
||||
return SMIConstants.SYNTAX_GAUGE32;
|
||||
case "Counter32":
|
||||
return SMIConstants.SYNTAX_COUNTER32;
|
||||
case "TimeTicks":
|
||||
return SMIConstants.SYNTAX_TIMETICKS;
|
||||
case "Opaque":
|
||||
return SMIConstants.SYNTAX_OPAQUE;
|
||||
case "Counter64":
|
||||
return SMIConstants.SYNTAX_COUNTER64;
|
||||
case "NoSuchObject":
|
||||
return SMIConstants.EXCEPTION_NO_SUCH_OBJECT;
|
||||
case "NoSuchInstance":
|
||||
return SMIConstants.EXCEPTION_NO_SUCH_INSTANCE;
|
||||
case "EndOfMibView":
|
||||
return SMIConstants.EXCEPTION_END_OF_MIB_VIEW;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Status implements Serializable {
|
||||
|
||||
public static final int NA = 0;
|
||||
public static final int OK = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int OFFLINE = 3;
|
||||
|
||||
public static String getStatusName(int id) {
|
||||
switch (id) {
|
||||
case OK:
|
||||
return "Online";
|
||||
case WARNING:
|
||||
return "Varování";
|
||||
case OFFLINE:
|
||||
return "Offline";
|
||||
default:
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package jnet.lib.snmp;
|
||||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -3,19 +3,19 @@ package jnet.lib.object;
|
|||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class ObjectType implements Serializable{
|
||||
public class DeviceType implements Serializable{
|
||||
|
||||
int id;
|
||||
String name;
|
||||
String imgStr;
|
||||
|
||||
public ObjectType(int id, String name, String imgStr) {
|
||||
public DeviceType(int id, String name, String imgStr) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.imgStr = imgStr;
|
||||
}
|
||||
|
||||
public ObjectType(String name, String imgStr) {
|
||||
public DeviceType(String name, String imgStr) {
|
||||
this.name = name;
|
||||
this.imgStr = imgStr;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class Event implements Serializable{
|
||||
|
||||
private long id;
|
||||
private int node;
|
||||
private int status;
|
||||
private long start;
|
||||
private long end;
|
||||
private int duration;
|
||||
|
||||
public Event(long id, int node, int status, long start) {
|
||||
this.id = id;
|
||||
this.node = node;
|
||||
this.start = start;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Event(long id, int node, int status, long start, long end, int duration) {
|
||||
this.id = id;
|
||||
this.node = node;
|
||||
this.status = status;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(int node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public long getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(long start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public long getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(long end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Interface implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String description; // původní (plný) popis z ifDescr
|
||||
private String shortDescription; // zkrácená verze popisu
|
||||
private String operStatus;
|
||||
private String speed;
|
||||
private String type;
|
||||
private String macAddress;
|
||||
private String adminStatus;
|
||||
private String lastChangeTime;
|
||||
private String alias; // uživatelský alias (ifAlias)
|
||||
|
||||
// Hlavní konstruktor se všemi parametry včetně shortDescription
|
||||
public Interface(int id, String description, String shortDescription, String operStatus,
|
||||
String speed, String type, String macAddress, String adminStatus,
|
||||
String lastChangeTime, String alias) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.shortDescription = shortDescription;
|
||||
this.operStatus = operStatus;
|
||||
this.speed = speed;
|
||||
this.type = type;
|
||||
this.macAddress = macAddress;
|
||||
this.adminStatus = adminStatus;
|
||||
this.lastChangeTime = lastChangeTime;
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
// Konstruktor pro zpětnou kompatibilitu (shortDescription = description)
|
||||
public Interface(int id, String description, String operStatus, String speed, String type,
|
||||
String macAddress, String adminStatus, String lastChangeTime, String alias) {
|
||||
this(id, description, description, operStatus, speed, type, macAddress,
|
||||
adminStatus, lastChangeTime, alias);
|
||||
}
|
||||
|
||||
// Původní konstruktor bez aliasu (pro zachování kompatibility)
|
||||
public Interface(int id, String description, String operStatus, String speed, String type,
|
||||
String macAddress, String adminStatus, String lastChangeTime) {
|
||||
this(id, description, description, operStatus, speed, type, macAddress,
|
||||
adminStatus, lastChangeTime, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Interface ID: ").append(id).append("\n");
|
||||
sb.append("Description: ").append(description).append("\n");
|
||||
if (!shortDescription.equals(description)) {
|
||||
sb.append("Short Description: ").append(shortDescription).append("\n");
|
||||
}
|
||||
if (alias != null && !alias.isEmpty() && !alias.equals(shortDescription)) {
|
||||
sb.append("Alias: ").append(alias).append("\n");
|
||||
}
|
||||
sb.append("Operational Status: ").append(operStatus).append("\n");
|
||||
sb.append("Speed: ").append(speed).append("\n");
|
||||
sb.append("Type: ").append(type).append("\n");
|
||||
sb.append("MAC Address: ").append(macAddress).append("\n");
|
||||
sb.append("Administrative Status: ").append(adminStatus).append("\n");
|
||||
sb.append("Last Link Change: ").append(lastChangeTime).append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// Gettery a settery
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getShortDescription() {
|
||||
return shortDescription;
|
||||
}
|
||||
|
||||
public void setShortDescription(String shortDescription) {
|
||||
this.shortDescription = shortDescription;
|
||||
}
|
||||
|
||||
public String getOperStatus() {
|
||||
return operStatus;
|
||||
}
|
||||
|
||||
public void setOperStatus(String operStatus) {
|
||||
this.operStatus = operStatus;
|
||||
}
|
||||
|
||||
public String getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(String speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
||||
public void setMacAddress(String macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
}
|
||||
|
||||
public String getAdminStatus() {
|
||||
return adminStatus;
|
||||
}
|
||||
|
||||
public void setAdminStatus(String adminStatus) {
|
||||
this.adminStatus = adminStatus;
|
||||
}
|
||||
|
||||
public String getLastChangeTime() {
|
||||
return lastChangeTime;
|
||||
}
|
||||
|
||||
public void setLastChangeTime(String lastChangeTime) {
|
||||
this.lastChangeTime = lastChangeTime;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,31 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import jnet.lib.Status;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MapObject implements Serializable {
|
||||
public class Node implements Serializable {
|
||||
|
||||
public static final int NODE_DEVICE = 1;
|
||||
public static final int NODE_MAP = 2;
|
||||
public static final int NODE_STATIC = 3;
|
||||
|
||||
|
||||
private int map;
|
||||
private int status;
|
||||
private int id;
|
||||
private String name;
|
||||
private int objectType;
|
||||
private String ip;
|
||||
private int siteId;
|
||||
private int x;
|
||||
private int y;
|
||||
private int type; // 1 = device, 2 = map, 3 = static object
|
||||
private String ip;
|
||||
private int icon;
|
||||
private int status;
|
||||
private boolean ping;
|
||||
private String user;
|
||||
private String password;
|
||||
private boolean enablePing;
|
||||
private String description;
|
||||
private String location;
|
||||
private int snmpProfile;
|
||||
private ArrayList<SnmpProbe> snmpProbe;
|
||||
private boolean active;
|
||||
public int pingAttemp;
|
||||
private boolean winbox;
|
||||
private String winboxPort;
|
||||
private boolean ssh;
|
||||
|
|
@ -35,81 +38,46 @@ public class MapObject implements Serializable {
|
|||
private boolean sms;
|
||||
private String smsPort;
|
||||
private int smsVerze;
|
||||
|
||||
public MapObject(int id,
|
||||
String name,
|
||||
int map,
|
||||
int objectType,
|
||||
String ip,
|
||||
int x,
|
||||
int y,
|
||||
String user,
|
||||
String password,
|
||||
String description,
|
||||
String location,
|
||||
int snmpProfile,
|
||||
ArrayList<SnmpProbe> snmpProbe,
|
||||
boolean active,
|
||||
boolean winbox,
|
||||
String winboxPort,
|
||||
boolean ssh,
|
||||
String sshPort,
|
||||
boolean web,
|
||||
String webPort,
|
||||
int webVerze,
|
||||
boolean telnet,
|
||||
String telnetPort,
|
||||
boolean sms,
|
||||
String smsPort,
|
||||
int smsVerze
|
||||
) {
|
||||
this.status = Status.NA;
|
||||
private int siteLink; // kdyz typ=2 zde je id mapy na ktery odkazuje
|
||||
private List<NodeProbe> probe;
|
||||
private int deviceType;
|
||||
|
||||
public Node(int id, String name, int siteId, int x, int y, int type, int icon, String ip, String user, String password, String description, String location, int snmpProfile, int status, boolean ping, boolean winbox, String winboxPort, boolean ssh, String sshPort, boolean web, String webPort, int webVersion, boolean telnet, String telnetPort, boolean sms, String smsPort, int smsVersion, int siteLink, List<NodeProbe> probe) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.map = map;
|
||||
this.objectType = objectType;
|
||||
this.ip = ip;
|
||||
this.siteId = siteId;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.type = type;
|
||||
this.icon = icon;
|
||||
this.deviceType = icon;
|
||||
this.ip = ip;
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.description = description;
|
||||
this.location = location;
|
||||
this.snmpProfile = snmpProfile;
|
||||
this.snmpProbe = snmpProbe;
|
||||
this.active = active;
|
||||
this.status = status;
|
||||
this.ping = ping;
|
||||
this.winbox = winbox;
|
||||
this.winboxPort = winboxPort;
|
||||
this.ssh = ssh;
|
||||
this.sshPort = sshPort;
|
||||
this.web = web;
|
||||
this.webPort = webPort;
|
||||
this.webVerze = webVerze;
|
||||
this.webVerze = webVersion;
|
||||
this.telnet = telnet;
|
||||
this.telnetPort = telnetPort;
|
||||
this.sms = sms;
|
||||
this.smsPort = smsPort;
|
||||
this.smsVerze = smsVerze;
|
||||
this.smsVerze = smsVersion;
|
||||
this.siteLink = siteLink;
|
||||
this.probe = new ArrayList<>();
|
||||
this.probe = probe;
|
||||
}
|
||||
|
||||
public MapObject() {
|
||||
|
||||
}
|
||||
public Node() {
|
||||
|
||||
public int getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(int map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
@ -128,20 +96,12 @@ public class MapObject implements Serializable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public int getObjectType() {
|
||||
return objectType;
|
||||
public int getSiteId() {
|
||||
return siteId;
|
||||
}
|
||||
|
||||
public void setObjectType(int objectType) {
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
public void setSiteId(int siteId) {
|
||||
this.siteId = siteId;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
|
@ -160,6 +120,38 @@ public class MapObject implements Serializable {
|
|||
this.y = y;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean isPing() {
|
||||
return ping;
|
||||
}
|
||||
|
||||
public void setPing(boolean ping) {
|
||||
this.ping = ping;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
|
@ -176,14 +168,6 @@ public class MapObject implements Serializable {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean isEnablePing() {
|
||||
return enablePing;
|
||||
}
|
||||
|
||||
public void setEnablePing(boolean enablePing) {
|
||||
this.enablePing = enablePing;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
|
@ -208,30 +192,6 @@ public class MapObject implements Serializable {
|
|||
this.snmpProfile = snmpProfile;
|
||||
}
|
||||
|
||||
public ArrayList<SnmpProbe> getSnmpProbe() {
|
||||
return snmpProbe;
|
||||
}
|
||||
|
||||
public void setSnmpProbe(ArrayList<SnmpProbe> snmpProbe) {
|
||||
this.snmpProbe = snmpProbe;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public int getPingAttemp() {
|
||||
return pingAttemp;
|
||||
}
|
||||
|
||||
public void setPingAttemp(int pingAttemp) {
|
||||
this.pingAttemp = pingAttemp;
|
||||
}
|
||||
|
||||
public boolean isWinbox() {
|
||||
return winbox;
|
||||
}
|
||||
|
|
@ -328,6 +288,66 @@ public class MapObject implements Serializable {
|
|||
this.smsVerze = smsVerze;
|
||||
}
|
||||
|
||||
|
||||
public int getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(int icon) {
|
||||
this.icon = icon;
|
||||
this.deviceType = icon;
|
||||
}
|
||||
|
||||
public int getSiteLink() {
|
||||
return siteLink;
|
||||
}
|
||||
|
||||
public void setSiteLink(int siteLink) {
|
||||
this.siteLink = siteLink;
|
||||
}
|
||||
|
||||
public List<NodeProbe> getProbe() {
|
||||
return probe;
|
||||
}
|
||||
|
||||
public void setProbe(List<NodeProbe> probe) {
|
||||
this.probe = probe;
|
||||
}
|
||||
|
||||
public int getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Node{"
|
||||
+ "id=" + id
|
||||
+ ", name='" + name + '\''
|
||||
+ ", siteId=" + siteId
|
||||
+ ", x=" + x
|
||||
+ ", y=" + y
|
||||
+ ", type=" + type
|
||||
+ ", icon=" + icon
|
||||
+ ", ip='" + ip + '\''
|
||||
+ ", status=" + status
|
||||
+ ", ping=" + ping
|
||||
+ ", user='" + user + '\''
|
||||
+ ", password='" + password + '\''
|
||||
+ ", description='" + description + '\''
|
||||
+ ", location='" + location + '\''
|
||||
+ ", snmpProfile=" + snmpProfile
|
||||
+ ", winbox=" + winbox
|
||||
+ ", winboxPort='" + winboxPort + '\''
|
||||
+ ", ssh=" + ssh
|
||||
+ ", sshPort='" + sshPort + '\''
|
||||
+ ", web=" + web
|
||||
+ ", webPort='" + webPort + '\''
|
||||
+ ", webVerze=" + webVerze
|
||||
+ ", telnet=" + telnet
|
||||
+ ", telnetPort='" + telnetPort + '\''
|
||||
+ ", sms=" + sms
|
||||
+ ", smsPort='" + smsPort + '\''
|
||||
+ ", smsVerze=" + smsVerze
|
||||
+ '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class NodeConnection implements Serializable{
|
||||
|
||||
public static final int TYPE_OTHER = 0;
|
||||
public static final int TYPE_GE = 1;
|
||||
public static final int TYPE_FE = 2;
|
||||
public static final int TYPE_E = 3;
|
||||
public static final int TYPE_10GE = 4;
|
||||
public static final int TYPE_100M_FIBER = 5;
|
||||
public static final int TYPE_1G_FIBER = 6;
|
||||
public static final int TYPE_10G_FIBER = 7;
|
||||
public static final int TYPE_WIRELESS = 8;
|
||||
public static final int TYPE_TUNEL = 9;
|
||||
public static final int TYPE_VLAN = 10;
|
||||
|
||||
private int id;
|
||||
private int nodeFrom;
|
||||
private int nodeTo;
|
||||
private int type;
|
||||
private boolean readTraffic;
|
||||
private int trafficNode;
|
||||
private int trafficIface;
|
||||
private int site;
|
||||
private long tx;
|
||||
private long rx;
|
||||
|
||||
public NodeConnection(int id, int site, int nodeFrom, int nodeTo, int type, boolean readTraffic, int trafficNode, int trafficIface) {
|
||||
this.id = id;
|
||||
this.site = site;
|
||||
this.nodeFrom = nodeFrom;
|
||||
this.nodeTo = nodeTo;
|
||||
this.type = type;
|
||||
this.readTraffic = readTraffic;
|
||||
this.trafficNode = trafficNode;
|
||||
this.trafficIface = trafficIface;
|
||||
}
|
||||
|
||||
public NodeConnection() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getNodeFrom() {
|
||||
return nodeFrom;
|
||||
}
|
||||
|
||||
public void setNodeFrom(int nodeFrom) {
|
||||
this.nodeFrom = nodeFrom;
|
||||
}
|
||||
|
||||
public int getNodeTo() {
|
||||
return nodeTo;
|
||||
}
|
||||
|
||||
public void setNodeTo(int nodeTo) {
|
||||
this.nodeTo = nodeTo;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isReadTraffic() {
|
||||
return readTraffic;
|
||||
}
|
||||
|
||||
public void setReadTraffic(boolean readTraffic) {
|
||||
this.readTraffic = readTraffic;
|
||||
}
|
||||
|
||||
public int getTrafficNode() {
|
||||
return trafficNode;
|
||||
}
|
||||
|
||||
public void setTrafficNode(int trafficNode) {
|
||||
this.trafficNode = trafficNode;
|
||||
}
|
||||
|
||||
public int getTrafficIface() {
|
||||
return trafficIface;
|
||||
}
|
||||
|
||||
public void setTrafficIface(int trafficIface) {
|
||||
this.trafficIface = trafficIface;
|
||||
}
|
||||
|
||||
public int getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setSite(int site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public long getTx() {
|
||||
return tx;
|
||||
}
|
||||
|
||||
public void setTx(long tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
public long getRx() {
|
||||
return rx;
|
||||
}
|
||||
|
||||
public void setRx(long rx) {
|
||||
this.rx = rx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.snmp4j.smi.Variable;
|
||||
|
||||
|
||||
public class NodeProbe implements Serializable {
|
||||
|
||||
|
||||
public static final String CONVERSION_TYPE_NONE = "NONE";
|
||||
public static final String CONVERSION_TYPE_DIVIDE = "DIVIDE";
|
||||
public static final String CONVERSION_TYPE_MULTIPLY = "MULTIPLY";
|
||||
public static final String CONVERSION_TYPE_OFFSET = "OFFSET";
|
||||
public static final String CONVERSION_TYPE_EXPRESSION = "EXPRESSION";
|
||||
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String oid;
|
||||
private int dataType;
|
||||
private String conversionType;
|
||||
private double conversionValue;
|
||||
private String conversionExpression;
|
||||
private String unit;
|
||||
private int valueMap;
|
||||
private Variable value;
|
||||
private int interval;
|
||||
private int nodeId;
|
||||
private boolean viewOnMap;
|
||||
|
||||
public NodeProbe(int id, String name, String oid, int dataType, String conversionType, double conversionValue, String conversionExpression, String unit, int valueMap, int interval, boolean viewOnMap) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.oid = oid;
|
||||
this.dataType = dataType;
|
||||
this.conversionType = conversionType;
|
||||
this.conversionValue = conversionValue;
|
||||
this.unit = unit;
|
||||
this.valueMap = valueMap;
|
||||
this.interval = interval;
|
||||
this.viewOnMap = viewOnMap;
|
||||
}
|
||||
|
||||
public NodeProbe() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(String oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
|
||||
public int getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(int dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getConversionType() {
|
||||
return conversionType;
|
||||
}
|
||||
|
||||
public void setConversionType(String conversionType) {
|
||||
this.conversionType = conversionType;
|
||||
}
|
||||
|
||||
public double getConversionValue() {
|
||||
return conversionValue;
|
||||
}
|
||||
|
||||
public void setConversionValue(double conversionValue) {
|
||||
this.conversionValue = conversionValue;
|
||||
}
|
||||
|
||||
public String getConversionExpression() {
|
||||
return conversionExpression;
|
||||
}
|
||||
|
||||
public void setConversionExpression(String conversionExpression) {
|
||||
this.conversionExpression = conversionExpression;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public int getValueMap() {
|
||||
return valueMap;
|
||||
}
|
||||
|
||||
public void setValueMap(int valueMap) {
|
||||
this.valueMap = valueMap;
|
||||
}
|
||||
|
||||
public Variable getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Variable value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public void setInterval(int interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public int getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(int nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public boolean isViewOnMap() {
|
||||
return viewOnMap;
|
||||
}
|
||||
|
||||
public void setViewOnMap(boolean viewOnMap) {
|
||||
this.viewOnMap = viewOnMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class NodeState implements Serializable{
|
||||
|
||||
private int id;
|
||||
private int state;
|
||||
|
||||
public NodeState(int id, int state) {
|
||||
this.id = id;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
|
||||
public class PingResult {
|
||||
private final String ip;
|
||||
private final int bytes;
|
||||
private final long timeMs;
|
||||
private final int ttl;
|
||||
private final boolean success;
|
||||
|
||||
public PingResult(String ip, int bytes, long timeMs, int ttl, boolean success) {
|
||||
this.ip = ip;
|
||||
this.bytes = bytes;
|
||||
this.timeMs = timeMs;
|
||||
this.ttl = ttl;
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getIp() { return ip; }
|
||||
public int getBytes() { return bytes; }
|
||||
public long getTimeMs() { return timeMs; }
|
||||
public int getTtl() { return ttl; }
|
||||
public boolean isSuccess() { return success; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("IP: %s, bytes=%d, time=%dms, TTL=%d", ip, bytes, timeMs, ttl);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,21 @@ public class ServerConfig implements Serializable {
|
|||
private int pingTimeout;
|
||||
private int instabilityAttempt;
|
||||
private int instabilityLimit;
|
||||
private int trafficInterval;
|
||||
private int trafficBatchInterval;
|
||||
private int probeBatchInterval;
|
||||
private boolean debug;
|
||||
|
||||
public ServerConfig(int pingRepeat, int pingAttempt, int pingTimeout, int instabilityAttempt, int instabilityLimit) {
|
||||
public ServerConfig(int pingRepeat, int pingAttempt, int pingTimeout, int instabilityAttempt, int instabilityLimit, int trafficInterval, int trafficBatchInterval, int probeBatchInterval, boolean debug) {
|
||||
this.pingRepeat = pingRepeat;
|
||||
this.pingAttempt = pingAttempt;
|
||||
this.pingTimeout = pingTimeout;
|
||||
this.instabilityAttempt = instabilityAttempt;
|
||||
this.instabilityLimit = instabilityLimit;
|
||||
this.trafficInterval = trafficInterval;
|
||||
this.trafficBatchInterval = trafficBatchInterval;
|
||||
this.probeBatchInterval = probeBatchInterval;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public int getPingRepeat() {
|
||||
|
|
@ -57,6 +65,40 @@ public class ServerConfig implements Serializable {
|
|||
public void setInstabilityLimit(int instabilityLimit) {
|
||||
this.instabilityLimit = instabilityLimit;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public int getTrafficInterval() {
|
||||
return trafficInterval;
|
||||
}
|
||||
|
||||
public void setTrafficInterval(int trafficInterval) {
|
||||
this.trafficInterval = trafficInterval;
|
||||
}
|
||||
|
||||
public int getTrafficBatchInterval() {
|
||||
return trafficBatchInterval;
|
||||
}
|
||||
|
||||
public void setTrafficBatchInterval(int trafficBatchInterval) {
|
||||
this.trafficBatchInterval = trafficBatchInterval;
|
||||
}
|
||||
|
||||
public int getProbeBatchInterval() {
|
||||
return probeBatchInterval;
|
||||
}
|
||||
|
||||
public void setProbeBatchInterval(int probeBatchInterval) {
|
||||
this.probeBatchInterval = probeBatchInterval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jnet.lib.Status;
|
||||
|
||||
public class Site implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private boolean lock;
|
||||
private List<Node> node;
|
||||
private List<NodeConnection> nodeConnection;
|
||||
|
||||
public Site(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lock = false;
|
||||
this.node = new ArrayList<>();
|
||||
this.nodeConnection = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Site(int id, String name, boolean lock, List<Node> node, List<NodeConnection> nodeConnection) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lock = lock;
|
||||
this.node = node;
|
||||
this.nodeConnection = nodeConnection;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
public List<Node> getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setNode(ArrayList<Node> node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public List<NodeConnection> getNodeConnection() {
|
||||
return nodeConnection;
|
||||
}
|
||||
|
||||
public void setNodeConnection(List<NodeConnection> nodeConnection) {
|
||||
this.nodeConnection = nodeConnection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getSiteState() {
|
||||
for (Node n : node) {
|
||||
if (n != null && n.getStatus() == Status.OFFLINE) {
|
||||
return Status.OFFLINE;
|
||||
}
|
||||
}
|
||||
for (Node n : node) {
|
||||
if (n != null && n.getStatus() == Status.WARNING) {
|
||||
return Status.WARNING;
|
||||
}
|
||||
}
|
||||
for (Node n : node) {
|
||||
if (n != null && n.getStatus() == Status.OK) {
|
||||
return Status.OK;
|
||||
}
|
||||
}
|
||||
return Status.NA; // Status.OK zde představuje ONLINE
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,20 +11,18 @@ public class SnmpProfile implements Serializable {
|
|||
private int version;
|
||||
private String port;
|
||||
private String communityRead;
|
||||
private String communityWrite;
|
||||
|
||||
private static final int version1 = SnmpConstants.version1;
|
||||
private static final int version2c = SnmpConstants.version2c;
|
||||
private static final int version3 = SnmpConstants.version3;
|
||||
public static final int version1 = SnmpConstants.version1;
|
||||
public static final int version2c = SnmpConstants.version2c;
|
||||
public static final int version3 = SnmpConstants.version3;
|
||||
|
||||
|
||||
public SnmpProfile(int id, String name, int version, String port, String communityRead, String communityWrite) {
|
||||
public SnmpProfile(int id, String name, int version, String port, String communityRead) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.communityRead = communityRead;
|
||||
this.communityWrite = communityWrite;
|
||||
}
|
||||
|
||||
public SnmpProfile() {
|
||||
|
|
@ -70,15 +68,5 @@ public class SnmpProfile implements Serializable {
|
|||
this.communityRead = communityRead;
|
||||
}
|
||||
|
||||
public String getCommunityWrite() {
|
||||
return communityWrite;
|
||||
}
|
||||
|
||||
public void setCommunityWrite(String communityWrite) {
|
||||
this.communityWrite = communityWrite;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.snmp4j.smi.Variable;
|
||||
|
||||
|
||||
public class SnmpResult implements Serializable {
|
||||
private final int taskId;
|
||||
private final String oid;
|
||||
private final Variable value;
|
||||
private final String error;
|
||||
private final boolean success;
|
||||
|
||||
public SnmpResult(int taskId, String oid, Variable value, String error, boolean success) {
|
||||
this.taskId = taskId;
|
||||
this.oid = oid;
|
||||
this.value = value;
|
||||
this.error = error;
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getTaskId() { return taskId; }
|
||||
public String getOid() { return oid; }
|
||||
public Variable getValue() { return value; }
|
||||
public String getError() { return error; }
|
||||
public boolean isSuccess() { return success; }
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SnmpTemplate implements Serializable {
|
||||
|
||||
public static final String CONVERSION_TYPE_NONE = "NONE";
|
||||
public static final String CONVERSION_TYPE_DIVIDE = "DIVIDE";
|
||||
public static final String CONVERSION_TYPE_MULTIPLY = "MULTIPLY";
|
||||
public static final String CONVERSION_TYPE_OFFSET = "OFFSET";
|
||||
public static final String CONVERSION_TYPE_EXPRESSION = "EXPRESSION";
|
||||
|
||||
|
||||
private int id;
|
||||
private int deviceType;
|
||||
private String name;
|
||||
private String oid;
|
||||
private int dataType;
|
||||
private String conversionType;
|
||||
private double conversionValue;
|
||||
private String conversionExpression;
|
||||
private String unit;
|
||||
private int valueMapId;
|
||||
private String description;
|
||||
|
||||
public SnmpTemplate(int id, int deviceType, String name, String oid, int dataType, String conversionType, double conversionValue, String conversionExpression, String unit, int valueMapId, String description) {
|
||||
this.id = id;
|
||||
this.deviceType = deviceType;
|
||||
this.name = name;
|
||||
this.oid = oid;
|
||||
this.dataType = dataType;
|
||||
this.conversionType = conversionType;
|
||||
this.conversionValue = conversionValue;
|
||||
this.conversionExpression = conversionExpression;
|
||||
this.unit = unit;
|
||||
this.valueMapId = valueMapId;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public SnmpTemplate() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(int deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(String oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
|
||||
public int getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(int dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getConversionType() {
|
||||
return conversionType;
|
||||
}
|
||||
|
||||
public void setConversionType(String conversionType) {
|
||||
this.conversionType = conversionType;
|
||||
}
|
||||
|
||||
public double getConversionValue() {
|
||||
return conversionValue;
|
||||
}
|
||||
|
||||
public void setConversionValue(double conversionValue) {
|
||||
this.conversionValue = conversionValue;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public int getValueMap() {
|
||||
return valueMapId;
|
||||
}
|
||||
|
||||
public void setValueMap(int valueMapId) {
|
||||
this.valueMapId = valueMapId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getConversionExpression() {
|
||||
return conversionExpression;
|
||||
}
|
||||
|
||||
public void setConversionExpression(String conversionExpression) {
|
||||
this.conversionExpression = conversionExpression;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +1,23 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class SnmpValueMap implements Serializable {
|
||||
|
||||
public class SnmpProbe implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private int objId;
|
||||
private List<SnmpValueMapItem> item;
|
||||
|
||||
public SnmpProbe(int id, String name, int objId) {
|
||||
public SnmpValueMap(int id, String name, List<SnmpValueMapItem> item) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.objId = objId;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public SnmpValueMap() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
@ -31,14 +34,12 @@ public class SnmpProbe implements Serializable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public int getObjId() {
|
||||
return objId;
|
||||
public List<SnmpValueMapItem> getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setObjId(int objId) {
|
||||
this.objId = objId;
|
||||
public void setItem(List<SnmpValueMapItem> item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SnmpValueMapItem implements Serializable {
|
||||
|
||||
int id;
|
||||
String rawValue;
|
||||
String mappedValue;
|
||||
|
||||
public SnmpValueMapItem(int id, String rawValue, String mappedValue) {
|
||||
this.id = id;
|
||||
this.rawValue = rawValue;
|
||||
this.mappedValue = mappedValue;
|
||||
}
|
||||
public SnmpValueMapItem(String rawValue, String mappedValue) {
|
||||
this.rawValue = rawValue;
|
||||
this.mappedValue = mappedValue;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRawValue() {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
public void setRawValue(String rawValue) {
|
||||
this.rawValue = rawValue;
|
||||
}
|
||||
|
||||
public String getMappedValue() {
|
||||
return mappedValue;
|
||||
}
|
||||
|
||||
public void setMappedValue(String mappedValue) {
|
||||
this.mappedValue = mappedValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
public class SnmpWalkItem {
|
||||
private final String oid;
|
||||
private final String value;
|
||||
private final String type;
|
||||
|
||||
public SnmpWalkItem(String oid, String value, String type) {
|
||||
this.oid = oid;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getOid() { return oid; }
|
||||
public String getValue() { return value; }
|
||||
public String getType() { return type; }
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package jnet.lib.object;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class TrafficData implements Serializable {
|
||||
|
||||
public final int deviceId;
|
||||
public final long inBps;
|
||||
public final long outBps;
|
||||
public final long timestamp;
|
||||
|
||||
public TrafficData(int deviceId, long inBps, long outBps, long timestamp) {
|
||||
this.deviceId = deviceId;
|
||||
this.inBps = inBps;
|
||||
this.outBps = outBps;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,21 @@ public class User implements Serializable {
|
|||
private boolean editObject;
|
||||
private boolean editServer;
|
||||
|
||||
public User() {
|
||||
this.id = -1;
|
||||
this.username = "";
|
||||
this.password = "";
|
||||
this.addMap = false;
|
||||
this.removeMap = false;
|
||||
this.editMap = false;
|
||||
this.addObject = false;
|
||||
this.removeObject = false;
|
||||
this.editObject = false;
|
||||
this.editServer = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public User(int id, String username, String password, boolean addMap, boolean removeMap, boolean editMap, boolean addObject, boolean removeObject, boolean editObject, boolean editServer) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
Loading…
Reference in New Issue