Skip to content

Commit

Permalink
Remove ossec-init.conf references
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco committed Jan 29, 2021
1 parent d7996c9 commit b222e92
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 43 deletions.
32 changes: 12 additions & 20 deletions deps/wazuh_testing/wazuh_testing/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import sys
import subprocess

if sys.platform == 'win32':
WAZUH_PATH = os.path.join("C:", os.sep, "Program Files (x86)", "ossec-agent")
Expand All @@ -17,25 +18,23 @@
API_LOG_FILE_PATH = None

else:
if os.path.isfile("/etc/ossec-init.conf"):
with open("/etc/ossec-init.conf") as ossec_init:
WAZUH_PATH = os.path.join(
[item.rstrip().replace("DIRECTORY=", "").replace("\"", "")
for item in ossec_init.readlines() if "DIRECTORY" in item][0])
if sys.platform == 'darwin':
WAZUH_PATH = os.path.join("/", "Library", "Ossec")
PREFIX = os.path.join('/', 'private', 'var', 'root')
GEN_OSSEC = None
else:
WAZUH_PATH = os.path.join("/", "var", "ossec")
GEN_OSSEC = os.path.join(WAZUH_SOURCES, 'gen_ossec.sh')
PREFIX = os.sep


WAZUH_CONF = os.path.join(WAZUH_PATH, 'etc', 'ossec.conf')
WAZUH_API_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'api.yaml')
WAZUH_SECURITY_CONF = os.path.join(WAZUH_PATH, 'api', 'configuration', 'security', 'security.yaml')
WAZUH_SOURCES = os.path.join('/', 'wazuh')
LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'logs', 'ossec.log')
API_LOG_FILE_PATH = os.path.join(WAZUH_PATH, 'logs', 'api.log')
if sys.platform == 'darwin':
PREFIX = os.path.join('/', 'private', 'var', 'root')
GEN_OSSEC = None
else:
PREFIX = os.sep
GEN_OSSEC = os.path.join(WAZUH_SOURCES, 'gen_ossec.sh')

try:
import grp
import pwd
Expand All @@ -48,15 +47,8 @@
if sys.platform == 'darwin' or sys.platform == 'win32' or sys.platform == 'sunos5':
WAZUH_SERVICE = 'wazuh.agent'
else:
try:
with open(os.path.join(WAZUH_PATH, 'etc/ossec-init.conf'), 'r') as f:
type_ = None
for line in f.readlines():
if 'TYPE' in line:
type_ = line.split('"')[1]
WAZUH_SERVICE = 'wazuh-manager' if type_ == 'server' else 'wazuh-agent'
except FileNotFoundError:
pass
type_ = subprocess.check_output([f"{WAZUH_PATH}/bin/wazuh-control", "info", "-t"], stderr=subprocess.PIPE).decode('utf-8')
WAZUH_SERVICE = 'wazuh-manager' if type_ == 'server' else 'wazuh-agent'

_data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
WAZUH_LOGS_PATH = os.path.join(WAZUH_PATH, 'logs')
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_wpk/test_wpk_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
# 2. v4.1.0
def get_current_version():
if platform.system() == 'Linux':
config_file_path = os.path.join(WAZUH_PATH, 'etc', 'ossec-init.conf')
_config = ConfigObj(config_file_path)
return _config['VERSION']
_version = subprocess.check_output([f"{WAZUH_PATH}/bin/wazuh-control", "info", "-v"], stderr=subprocess.PIPE).decode('utf-8')stderr=subprocess.PIPE).decode('utf-8')
return _version.replace("v", "")

else:
version = None
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_wpk/test_wpk_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@

def get_current_version():
if platform.system() == 'Linux':
config_file_path = os.path.join(WAZUH_PATH, 'etc', 'ossec-init.conf')
_config = ConfigObj(config_file_path)
return _config['VERSION']
_version = subprocess.check_output([f"{WAZUH_PATH}/bin/wazuh-control", "info", "-v"], stderr=subprocess.PIPE).decode('utf-8')stderr=subprocess.PIPE).decode('utf-8')
return _version

MANAGER_VERSION = get_current_version()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,6 @@ checks:
###########################
# Complex directory rules #
###########################
- id: 100300
title: PASS -- Full rule regex match
condition: any
rules:
- d:/etc -> ossec-init.conf -> r:^DIRECTORY

- id: 100301
title: FAIL -- Full rule regex does not match
condition: any
rules:
- d:/etc -> ossec-init.conf -> r:^FAKE

- id: 100302
title: INVALID -- Directory does not exist
condition: any
rules:
- d:/var/ossec/fakedir -> ossec-init.conf -> r:^FAKE
# This check is pass instead of invalid because the existence of the file is optional (not mandatory)
- id: 100303
title: FAIL -- File does not exist
Expand Down

0 comments on commit b222e92

Please sign in to comment.