summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-08-28 14:38:19 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-08-28 14:38:19 +0200
commit85c654d1ecb3e3705b2004433c01c0735b7642da (patch)
tree24f06b1db39bc987ab95fdc2aeed028f0ba3f33d /java
parent898a0df8ede6fb58241daed7cbb993e7fb01da13 (diff)
downloadrsyslog-85c654d1ecb3e3705b2004433c01c0735b7642da.tar.gz
rsyslog-85c654d1ecb3e3705b2004433c01c0735b7642da.tar.xz
rsyslog-85c654d1ecb3e3705b2004433c01c0735b7642da.zip
added a very rough first sketch of a traffic generator gui
... not really usable yet, but a good milestone
Diffstat (limited to 'java')
-rw-r--r--java/Makefile.am3
-rw-r--r--java/com/rsyslog/gui/msggen/MsgGen.java117
-rw-r--r--java/com/rsyslog/lib/SyslogSender.java96
-rw-r--r--java/com/rsyslog/lib/UDPSyslogSender.java75
4 files changed, 291 insertions, 0 deletions
diff --git a/java/Makefile.am b/java/Makefile.am
index 8e5c041a..5d3cd1b0 100644
--- a/java/Makefile.am
+++ b/java/Makefile.am
@@ -19,9 +19,12 @@ JAVA_SOURCE_FILES = \
com/rsyslog/lib/DiagSess.java \
com/rsyslog/lib/SyslogMessage.java \
com/rsyslog/lib/SyslogMsgConsumer.java \
+ com/rsyslog/lib/SyslogSender.java \
+ com/rsyslog/lib/UDPSyslogSender.java \
com/rsyslog/diag/DiagTalker.java \
com/rsyslog/gui/simpServ/simpServ.java \
com/rsyslog/gui/simpServ/simpServConsumer.java \
+ com/rsyslog/gui/msggen/MsgGen.java \
com/rsyslog/gui/diaggui/Counters.java \
com/rsyslog/gui/diaggui/DiagGUI.java
diff --git a/java/com/rsyslog/gui/msggen/MsgGen.java b/java/com/rsyslog/gui/msggen/MsgGen.java
new file mode 100644
index 00000000..6591d401
--- /dev/null
+++ b/java/com/rsyslog/gui/msggen/MsgGen.java
@@ -0,0 +1,117 @@
+/* A yet very simple syslog message generator
+ *
+ * The purpose of this program is to provide a facility that enables
+ * to generate complex traffic patterns for testing purposes. It still is
+ * in its infancy, but hopefully will evolve.
+ *
+ * Note that this has been created as a stand-alone application because it
+ * was considered useful to have it as a separate program. But it should still
+ * be possible to call its class from any other program, specifically the debug
+ * GUI.
+ *
+ * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+package com.rsyslog.gui.msggen;
+import com.rsyslog.lib.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class MsgGen extends Frame {
+ private TextField target;
+ private TextField message;
+
+ public static void main(String args[]) {
+ new MsgGen();
+ }
+
+ /** creates the menu bar INCLUDING all menu handlers */
+ private void createMenu() {
+ MenuItem item;
+ MenuBar menuBar = new MenuBar();
+ Menu fileMenu = new Menu("File");
+ item = new MenuItem("Exit");
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.exit(0);
+ }
+ });
+ fileMenu.add(item);
+ menuBar.add(fileMenu);
+
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e){
+ System.exit(0);
+ }
+ });
+ setMenuBar(menuBar);
+ }
+
+ /** creates the main GUI */
+ private void createGUI() {
+ target = new TextField("127.0.0.1", 32);
+ message = new TextField(80);
+ message.setText("<161>Test malformed");
+ Panel pCenter = new Panel();
+ pCenter.setLayout(new FlowLayout());
+ pCenter.add(new Label("Target Host:"));
+ pCenter.add(target);
+ pCenter.add(new Label("Msg:"));
+ pCenter.add(message);
+
+ Button b = new Button("Start Test");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ performTest();
+ }
+ });
+ Panel pSouth = new Panel();
+ pSouth.setLayout(new FlowLayout());
+ pSouth.add(b);
+
+ pack();
+ setTitle("Syslog Message Generator");
+ setLayout(new BorderLayout());
+ add(pCenter, BorderLayout.CENTER);
+ add(pSouth, BorderLayout.SOUTH);
+ setSize(800,400);
+ }
+
+ /** perform the test, a potentially complex operation */
+ private void performTest() {
+ try {
+ UDPSyslogSender sender = new UDPSyslogSender(target.getText());
+ for(int i = 0 ; i < 100 ; ++i)
+ sender.sendMSG(message.getText());
+ }
+ catch(Exception e) {
+ JOptionPane.showMessageDialog(this, e.toString(), "Error",
+ JOptionPane.ERROR_MESSAGE, null);
+ }
+ }
+
+
+ /** initialize the GUI. */
+ public MsgGen(){
+ createMenu();
+ createGUI();
+ setVisible(true);
+ }
+}
diff --git a/java/com/rsyslog/lib/SyslogSender.java b/java/com/rsyslog/lib/SyslogSender.java
new file mode 100644
index 00000000..fc0e3fec
--- /dev/null
+++ b/java/com/rsyslog/lib/SyslogSender.java
@@ -0,0 +1,96 @@
+/**
+ * This class specifies all methods common to syslog senders. It also implements
+ * some generic ways to send data. Actual syslog senders (e.g. UDP, TCP, ...) shall
+ * be derived from this class.
+ *
+ * This is a limited-capability implementation of a syslog message together
+ * with all its properties. It is limit to what is currently needed and may
+ * be extended as further need arises.
+ *
+ * @author Rainer Gerhards
+ *
+ * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see http://www.gnu.org/licenses/.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+package com.rsyslog.lib;
+
+public abstract class SyslogSender {
+
+ /** the rawmsg without the PRI part */
+ private String target;
+
+ /** the rawmsg without the PRI part */
+ private boolean isConnected = false;
+
+ /** Constructs Sender, sets target system.
+ * @param target the system to connect to. Syntax of target is depending
+ * on the underlying transport.
+ */
+ public SyslogSender(String target) {
+ this.target = target;
+ }
+
+
+ /** send a message on the wire.
+ * This needs a complete formatted message, which will be extended by
+ * the transport framing, if necessary.
+ *
+ * @param MSG a validly formatted syslog message as of the RFC (all parts)
+ * @throws Exception (depending on transport)
+ */
+ protected abstract void sendTransport(String MSG) throws Exception;
+
+ /** send an alread-formatted message.
+ * Sends a preformatted syslog message payload to the target. Connects
+ * to the target if not already connected.
+ *
+ * @param MSG a validly formatted syslog message as of the RFC (all parts)
+ * @throws Exception (depending on transport)
+ */
+ public void sendMSG(String MSG) throws Exception {
+ if(!isConnected)
+ connect();
+ sendTransport(MSG);
+ }
+
+ /** connect to the target.
+ * Note that this may be a null operation if there is no session-like entity
+ * in the underlying transport (as is for example in UDP).
+ */
+ public void connect() throws Exception {
+ /* the default implementation does (almost) nothing */
+ isConnected = true;
+ }
+
+ /** disconnects from the target.
+ * Note that this may be a null operation if there is no session-like entity
+ * in the underlying transport (as is for example in UDP).
+ */
+ public void disconnect() {
+ /* the default implementation does (almost) nothing */
+ isConnected = false;
+ }
+
+ /** return target of this Sender.
+ * @returns target as initially set
+ */
+ public String getTarget() {
+ return target;
+ }
+}
diff --git a/java/com/rsyslog/lib/UDPSyslogSender.java b/java/com/rsyslog/lib/UDPSyslogSender.java
new file mode 100644
index 00000000..1a2c4726
--- /dev/null
+++ b/java/com/rsyslog/lib/UDPSyslogSender.java
@@ -0,0 +1,75 @@
+/**
+ * A UDP transport implementation of a syslog sender.
+ *
+ * Note that there is an anomaly in this version of the code: we query the remote system
+ * address only once during the connection setup and resue it. If we potentially run for
+ * an extended period of time, the remote address may change, what we do not reflect. For
+ * the current use case, this is acceptable, but if this code is put into more wide-spread
+ * use outside of debugging, a periodic requery should be added.
+ *
+ * @author Rainer Gerhards
+ *
+ * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This file is part of rsyslog.
+ *
+ * Rsyslog is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Rsyslog is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Rsyslog. If not, see http://www.gnu.org/licenses/.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+package com.rsyslog.lib;
+import java.net.*;
+
+public class UDPSyslogSender extends SyslogSender {
+
+ private final int port = 514; // TODO: take from target!
+ private InetAddress targetAddr;
+
+ /** the socket to communicate over with the remote system. */
+ private DatagramSocket sock;
+
+ /** Constructs Sender, sets target system.
+ * @param target the system to connect to. Syntax of target is depending
+ * on the underlying transport.
+ */
+ public UDPSyslogSender(String target) throws Exception {
+ super(target);
+ }
+
+ /** send a message on the wire.
+ * This needs a complete formatted message, which will be extended by
+ * the transport framing, if necessary.
+ *
+ * @param MSG a validly formatted syslog message as of the RFC (all parts)
+ * @throws Exception (depending on transport)
+ */
+ protected void sendTransport(String MSG) throws Exception {
+ byte msg[] = MSG.getBytes();
+ DatagramPacket pkt = new DatagramPacket(msg, msg.length, targetAddr, port);
+ sock.send(pkt);
+ }
+
+
+ /** connect to the target.
+ * For UDP, this means we create the socket.
+ */
+ public void connect() throws Exception {
+ super.connect();
+ sock = new DatagramSocket();
+
+ // TODO: we should extract the actual hostname & port!
+ targetAddr = InetAddress.getByName(getTarget());
+ }
+
+}