Skip to content

Commit

Permalink
fix: sonarqube issues (#2118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikheifets-splunk committed Sep 6, 2023
1 parent cf24a8c commit 1a7faf8
Show file tree
Hide file tree
Showing 151 changed files with 3,182 additions and 3,159 deletions.
2 changes: 1 addition & 1 deletion ansible/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# install requirements in venv
FROM python:3.10 as venv_builder
FROM python:3.10 AS venv_builder
RUN pip install ansible~=6.1.0 --no-cache-dir
RUN pip install pywinrm>=0.4.2 --no-cache-dir
RUN pip install ansible-lint>=6.0.0 --no-cache-dir
Expand Down
25 changes: 13 additions & 12 deletions docs/resources/test_vmware_carbonblack_with_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
# 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
import shortuuid
from jinja2 import Environment, select_autoescape

from .sendmessage import *
from .splunkutils import *
from .timeutils import *
from .sendmessage import sendsingle
from .splunkutils import splunk_single
from .timeutils import time_operations
import datetime

env = Environment()
env = Environment(autoescape=select_autoescape(default_for_string=False))
# Below is a raw message
# <14>1 2022-03-30T11:17:11.900862-04:00 host - - - - Carbon Black App Control event: text="File 'c:\program files\azure advanced threat protection sensor\0.0.0.0\winpcap\x86\packet.dll' [c4e671bf409076a6bf0897e8a11e6f1366d4b21bf742c5e5e116059c9b571363] would have blocked if the rule was not in Report Only mode." type="Policy Enforcement" subtype="Execution block (unapproved file)" hostname="CORP\USER" username="NT AUTHORITY\SYSTEM" date="3/30/2022 3:16:40 PM" ip_address="0.0.0.0" process="c:\program files\azure advanced threat protection sensor\0.0.0.0\microsoft.tri.sensor.updater.exe" file_path="c:\program files\azure advanced threat protection sensor\0.0.0.0\winpcap\x86\packet.dll" file_name="packet.dll" file_hash="c4e671bf409076a6bf0897e8a11e6f1366d4b21bf742c5e5e116059c9b571363" policy="High Enforcement - Domain Controllers" rule_name="Report read-only memory map operations on unapproved executables by .NET applications" process_key="00000433-0000-23d8-01d8-44491b26f203" server_version="0.0.0.0" file_trust="-2" file_threat="-2" process_trust="-2" process_threat="-2" prevalence="50"

# Don't forget to rename the function
def test_vmware_carbonblack_protect(
record_property, setup_wordlist, setup_splunk, setup_sc4s
record_property, setup_splunk, setup_sc4s
):
host = "{}-{}".format(random.choice(setup_wordlist), random.choice(setup_wordlist))
host = f"{shortuuid.ShortUUID().random(length=5).lower()}-{shortuuid.ShortUUID().random(length=5).lower()}"

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

# Tune time functions for Checkpoint
epoch = epoch[:-3]
Expand All @@ -43,10 +44,10 @@ def test_vmware_carbonblack_protect(
)
search = st.render(epoch=epoch, bsd=bsd, host=host)

resultCount, eventCount = splunk_single(setup_splunk, search)
result_count, _ = splunk_single(setup_splunk, search)

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

assert resultCount == 1
assert result_count == 1
5 changes: 4 additions & 1 deletion package/etc/conf.d/conflib/app-lp_dest_archive/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")


Expand Down
8 changes: 5 additions & 3 deletions package/etc/conf.d/destinations/dest_bsd/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

msg_template = "$(template t_syslog)"
Expand All @@ -20,7 +23,6 @@
if r != "":
dests.append(r)

# dests = f'DEFAULT,{ os.getenv("SYSLOG_ALT_DESTS","") }'.rstrip(",").split(",")
for group in dests:
altname = f"_{ group }".lower()

Expand Down Expand Up @@ -48,7 +50,7 @@
diskbuff_reliable = False

# Used to calc disk space for buffer
disk_space, used, free = shutil.disk_usage(os.getenv(f"SC4S_VAR", "/"))
disk_space, used, free = shutil.disk_usage(os.getenv("SC4S_VAR", "/"))
disk_space = disk_space - 5000000000

if disk_space < 0:
Expand Down
14 changes: 8 additions & 6 deletions package/etc/conf.d/destinations/dest_hec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def hec_endpoint_collector(hec_path, url_hec):
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

msg_template = "$(template ${.splunk.sc4s_hec_template} $(template t_splunk_hec))"
Expand All @@ -29,7 +32,6 @@ def hec_endpoint_collector(hec_path, url_hec):
if r != "":
dests.append(r)

# dests = f'DEFAULT,{ os.getenv("SPLUNK_HEC_ALT_DESTS","") }'.rstrip(",").split(",")
for group in dests:
url = os.getenv(f"SC4S_DEST_SPLUNK_HEC_{group}_URL")
altname = ""
Expand Down Expand Up @@ -69,7 +71,7 @@ def hec_endpoint_collector(hec_path, url_hec):
buff_dir_enable = False

# Used to calc disk space for buffer
disk_space, used, free = shutil.disk_usage(os.getenv(f"SC4S_VAR", "/"))
disk_space, used, free = shutil.disk_usage(os.getenv("SC4S_VAR", "/"))
disk_space = disk_space - 5000000000

if disk_space < 0:
Expand All @@ -82,7 +84,7 @@ def hec_endpoint_collector(hec_path, url_hec):
headers += user_headers.split(",")
token = os.getenv(f"SC4S_DEST_SPLUNK_HEC_{group}_TOKEN")
headers.append(f"Authorization: Splunk {token}")
headers.append(f"__splunk_app_name: sc4syslog")
headers.append("__splunk_app_name: sc4syslog")
sc4s_version = os.getenv('SC4S_VERSION', "0.0.0")
headers.append(f"__splunk_app_version: {sc4s_version}")

Expand All @@ -95,9 +97,9 @@ def hec_endpoint_collector(hec_path, url_hec):
"y",
"yes",
]:
headers.append(f"Connection: close")
headers.append("Connection: close")
else:
headers.append(f"Connection: keep-alive")
headers.append("Connection: keep-alive")

msg = tm.render(
group=group,
Expand Down
8 changes: 5 additions & 3 deletions package/etc/conf.d/destinations/dest_syslog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

msg_template = "$(template t_syslog)"
Expand All @@ -20,7 +23,6 @@
if r != "":
dests.append(r)

# dests = f'DEFAULT,{ os.getenv("SYSLOG_ALT_DESTS","") }'.rstrip(",").split(",")
for group in dests:
altname = f"_{ group }".lower()

Expand Down Expand Up @@ -48,7 +50,7 @@
diskbuff_reliable = False

# Used to calc disk space for buffer
disk_space, used, free = shutil.disk_usage(os.getenv(f"SC4S_VAR", "/"))
disk_space, used, free = shutil.disk_usage(os.getenv("SC4S_VAR", "/"))
disk_space = disk_space - 5000000000

if disk_space < 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")


Expand Down
5 changes: 4 additions & 1 deletion package/etc/conf.d/log_paths/2/lp_dest_alts_global/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

plugin_path = os.path.dirname(os.path.abspath(__file__))
templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

def normalize_env_variable_input(env_variable: str):
Expand Down
5 changes: 4 additions & 1 deletion package/etc/conf.d/sc4slib/app-lp-global-archive/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

keys = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

keys = []
Expand Down
11 changes: 7 additions & 4 deletions package/etc/conf.d/sc4slib/global_options/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
plugin_path = os.path.dirname(os.path.abspath(__file__))

templateLoader = jinja2.FileSystemLoader(searchpath=plugin_path)
templateEnv = jinja2.Environment(loader=templateLoader)
templateEnv = jinja2.Environment(
loader=templateLoader,
autoescape=jinja2.select_autoescape(default_for_string=False),
)
tm = templateEnv.get_template("plugin.jinja")

msg = tm.render(
stats_freq=os.getenv(f"SC4S_GLOBAL_OPTIONS_STATS_FREQ", 30),
stats_level=os.getenv(f"SC4S_GLOBAL_OPTIONS_STATS_LEVEL", 1),
log_fifo=os.getenv(f"SC4S_GLOBAL_OPTIONS_LOG_FIFO", 10000),
stats_freq=os.getenv("SC4S_GLOBAL_OPTIONS_STATS_FREQ", 30),
stats_level=os.getenv("SC4S_GLOBAL_OPTIONS_STATS_LEVEL", 1),
log_fifo=os.getenv("SC4S_GLOBAL_OPTIONS_LOG_FIFO", 10000),
)

print(msg)
Loading

0 comments on commit 1a7faf8

Please sign in to comment.