Skip to content

Commit

Permalink
Clean up docs, change it to adoc (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrongestNumber9 authored Aug 3, 2023
1 parent d7d1478 commit c63355f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
64 changes: 29 additions & 35 deletions README.md → README.adoc
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
# teragrep RFC5424 parser
= teragrep RFC5424 parser
Features
* Fast

Non-features
* Excellent strictness


## License
== License
AGPLv3 with link:https://github.com/teragrep/rlo_06/blob/master/LICENSE#L665-L670[additional permissions] granted in the license.


## Usage
== Usage
This parser uses subscriptions to pick up interesting message elements
from the message stream.

For generic message property extraction use:
```java

[source,java]
----
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
subscription.subscribeAll();
// or following where parameter is type of ParserEnum
subscription.add(ParserEnum.TIMESTAMP);
subscription.add(ParserEnum.MSG);
```
----

For structured data property extraction use:
```java

[source,java]
----
RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription();
// subscribe with following where first is SD-ID and second is PARAM-NAME
sdSubscription.subscribeElement("event_key@12345","paramKey");
```

After desired subscriptions are created then allocate a resultset object:
```java
ParserResultset res = new ParserResultset(subscription, sdSubscription);
```
----

Create a parser with the desired InputStream
```java
RFC5424Parser parser = new RFC5424Parser(inputStream);
```

```java
if (parser.next(res) == true) {
String msg = res.getMsgAsUTF8String();
String sdValue = res.getSdValueAsUTF8String("event_key@12345","paramKey")
}
```

[source,java]
----
RFC5424Parser parser = new RFC5424Parser(inputStream, subscription, sdSubscription);
----

Next event can be extracted as follows
```java
res.clear(); // clear resultset before calling .next() again
if(parser.next(res) == true) {
String msg = res.getMsgAsUTF8String();
String sdValue = res.getSdValueAsUTF8String("event_key@12345","paramKey")

[source,java]
----
if (parser.next()) {
ResultSetAsString results = new ResultSetAsString(parser.get());
String msg = results.getMsg();
String sdValue = results.getSdValue("event_key@12345","paramKey");
}
```
----

## Todo
```
RFC5424Parser.java
```
== Todo

=== RFC5424Parser.java
* Take maximum allocation sizes from ParserResultset for string length checking
* Throw if maximum size is exceeded
* Throw if quotation exceed maximum line. THIS STALLS AT THE MOMENT.
Expand All @@ -68,8 +63,7 @@ RFC5424Parser.java
* Try extracting sdParsing to a dedicated class
* Try extracting buffer handling to a dedicated class

```
SytanxTest.java
```
=== Tests

* More test cases, see palindromicity code

6 changes: 0 additions & 6 deletions src/test/java/com/teragrep/rlo_06/BrokenSyntaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ void testBrokenFail() throws Exception {
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
subscription.subscribeAll();
RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription();
ParserResultSet res = new ParserResultSet(subscription, sdSubscription);
RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription);
parser.setInputStream(new ByteArrayInputStream( (SYSLOG_MESSAGE).getBytes()));
Assertions.assertThrows(ParseException.class, parser::next);
res.clear();
}

@Test
Expand All @@ -26,7 +24,6 @@ void testNilTimestamp() throws Exception {
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
subscription.subscribeAll();
RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription(true);
ParserResultSet res = new ParserResultSet(subscription, sdSubscription);
RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription);
ResultSetAsString resultsetAsString = new ResultSetAsString(parser.get());
parser.setInputStream(new ByteArrayInputStream( (input).getBytes()));
Expand All @@ -39,7 +36,6 @@ void testNilTimestamp() throws Exception {
Assertions.assertEquals("DEA", resultsetAsString.getProcid(), "Procid");
Assertions.assertEquals("MSG-01", resultsetAsString.getMsgid(), "msgid");
Assertions.assertEquals("sigsegv", resultsetAsString.getMsg(), "msg");
res.clear();
}

@Test
Expand All @@ -48,11 +44,9 @@ void testOpenSD() throws Exception {
RFC5424ParserSubscription subscription = new RFC5424ParserSubscription();
subscription.subscribeAll();
RFC5424ParserSDSubscription sdSubscription = new RFC5424ParserSDSubscription();
ParserResultSet res = new ParserResultSet(subscription, sdSubscription);
RFC5424Parser parser = new RFC5424Parser(null, subscription, sdSubscription);
parser.setInputStream(new ByteArrayInputStream((SYSLOG_MESSAGE).getBytes()));
Assertions.assertThrows(ParseException.class, parser::next);
res.clear();
}


Expand Down

0 comments on commit c63355f

Please sign in to comment.