Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: QNAP NAP parser #2132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/sources/vendor/QNAP/nas.md
@@ -0,0 +1,26 @@
# Nas

QNAP NAS QTS|QES shares a common syslog format.

## Key facts

* RFC3164
* Program based filter

## Links

| Ref | Link |
|----------------|------------------------------------------|
| Splunk Add-on | <https://splunkbase.splunk.com/app/4632> |

## Sourcetypes

| sourcetype | notes |
|----------------|-----------------|
| qnap:syslog | QNAP NAS syslog |

## Sourcetype and Index Configuration

| key | sourcetype | index | notes |
|----------|----------------|----------------|-----------------|
| qnap_nas | qnap:syslog | infraops | none |
21 changes: 21 additions & 0 deletions package/etc/conf.d/conflib/syslog/app-syslog-qnap_nas.conf
@@ -0,0 +1,21 @@
block parser qnap_nas-parser() {
channel {
rewrite {
r_set_splunk_dest_default(
index('infraops')
source("program:qulogd")
sourcetype('qnap:syslog')
vendor('qnap')
product('nas')
template('t_standard')
);
};
};
};

application qnap_nas[sc4s-syslog-pgm] {
filter {
program('qulogd' type(string) flags(prefix));
};
parser { qnap_nas-parser(); };
};
44 changes: 44 additions & 0 deletions tests/test_qnap_nas.py
@@ -0,0 +1,44 @@
# Copyright 2019 Splunk, Inc.
#
# Use of this source code is governed by a BSD-2-clause-style
# license that can be found in the LICENSE-BSD2 file or at
# https://opensource.org/licenses/BSD-2-Clause
import random

from jinja2 import Environment

from .sendmessage import *
from .splunkutils import *
from .timeutils import *

env = Environment()

# <30>Jul 15 18:03:54 NAShostname qulogd[13241]: conn log: Users: admin, Source IP: 10.0.0.1, Computer name: ---, Connection type: HTTP, Accessed resources: ---, Action: Logout
# <30>Jul 15 18:06:46 NAShostname qulogd[13241]: conn log: Users: admin, Source IP: 10.0.0.1, Computer name: localhost, Connection type: SMB, Accessed resources: Multimedia/folder/file.txt, Action: Read
def test_qnap_nas_qts(record_property, setup_wordlist, setup_splunk, setup_sc4s):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks okay, only one thing we already removed setup_wordlist fixture. If you will be ready to update a test I will merge this PR.

host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist))

dt = datetime.datetime.now()
iso, bsd, time, date, tzoffset, tzname, epoch = time_operations(dt)

# Tune time functions
epoch = epoch[:-7]

mt = env.from_string(
"{{mark}}{{ bsd }} qnap-{{host}} qulogd[13241]: conn log: Users: admin, Source IP: 10.0.0.1, Computer name: localhost, Connection type: SMB, Accessed resources: Multimedia/folder/file.txt, Action: Read"
)
message = mt.render(mark="<27>", bsd=bsd, host=host)
sendsingle(message, setup_sc4s[0], setup_sc4s[1][514])

st = env.from_string(
"search _time={{ epoch }} index=infraops sourcetype=qnap:syslog host=qnap-{{host}}"
)
search = st.render(epoch=epoch, host=host)

resultCount, eventCount = splunk_single(setup_splunk, search)

record_property("host", host)
record_property("resultCount", resultCount)
record_property("message", message)

assert resultCount == 1