-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from wazuh/1034-agentd-stats-enhancement
wazuh-agentd stats IT
- Loading branch information
Showing
8 changed files
with
632 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (C) 2015-2021, Wazuh Inc. | ||
# Created by Wazuh, Inc. <info@wazuh.com>. | ||
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2 | ||
|
||
import re | ||
|
||
from wazuh_testing.fim import change_internal_options | ||
|
||
|
||
# Callbacks | ||
def callback_state_interval_not_valid(line): | ||
match = re.match(r'.*Invalid definition for agent.state_interval:', line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_state_interval_not_found(line): | ||
match = re.match(r".*Definition not found for: 'agent.state_interval'", line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_state_file_not_enabled(line): | ||
match = re.match(r'.*State file is disabled', line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_state_file_enabled(line): | ||
match = re.match(r'.*State file updating thread started', line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_state_file_updated(line): | ||
match = re.match(r'.*Updating state file', line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_ack(line): | ||
match = re.match(r".*Received message: '#!-agent ack ", line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_keepalive(line): | ||
match = re.match(r'.*Sending keep alive', line) | ||
return True if match is not None else None | ||
|
||
|
||
def callback_connected_to_server(line): | ||
match = re.match(r'.*Connected to the server', line) | ||
return True if match is not None else None | ||
|
||
|
||
def set_state_interval(interval, internal_file_path): | ||
"""Set agent.state_interval value on internal_options.conf | ||
Args: | ||
interval: | ||
- Different than `None`: set agent.state_interval | ||
value on internal_options.conf | ||
- `None`: agent.state_interval will be removed | ||
from internal_options.conf | ||
""" | ||
if interval is not None: | ||
change_internal_options('agent.state_interval', interval, internal_file_path, '.*') | ||
else: | ||
new_content = '' | ||
with open(internal_file_path) as opts: | ||
for line in opts: | ||
new_line = line if 'agent.state_interval' not in line else '' | ||
new_content += new_line | ||
|
||
with open(internal_file_path, 'w') as opts: | ||
opts.write(new_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/integration/test_agentd/data/wazuh_state_config_tests.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
- | ||
name: "Negative state interval" | ||
test_case: | ||
log_expect: 'interval_not_valid' | ||
interval: -1 | ||
state_file_exist: false | ||
agentd_ends: true | ||
- | ||
name: "Undefined state interval value" | ||
test_case: | ||
log_expect: 'file_not_enabled' | ||
interval: " " | ||
state_file_exist: false | ||
agentd_ends: false | ||
- | ||
name: "State interval option dont exist" | ||
test_case: | ||
log_expect: 'interval_not_found' | ||
interval: null | ||
state_file_exist: false | ||
agentd_ends: true | ||
- | ||
name: "Zero state interval" | ||
test_case: | ||
log_expect: 'file_not_enabled' | ||
interval: 0 | ||
state_file_exist: false | ||
agentd_ends: false | ||
- | ||
name: "Too big state interval" | ||
test_case: | ||
log_expect: 'interval_not_valid' | ||
interval: 86401 | ||
state_file_exist: false | ||
agentd_ends: true | ||
- | ||
name: "Default state interval" | ||
test_case: | ||
log_expect: 'file_enabled' | ||
interval: 5 | ||
state_file_exist: true | ||
agentd_ends: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
- | ||
name: "No connection with remoted" | ||
test_case: | ||
input: | ||
remoted: false | ||
output: | ||
- | ||
type: "file" | ||
fields: | ||
status: "pending" | ||
last_keepalive: "" | ||
last_ack: "" | ||
msg_count: "" | ||
- | ||
name: "Successful connection with remoted" | ||
test_case: | ||
input: | ||
remoted: true | ||
output: | ||
- | ||
type: "file" | ||
fields: | ||
status: "connected" | ||
last_keepalive: true | ||
last_ack: true | ||
msg_count: true | ||
- | ||
type: "remote" | ||
fields: | ||
status: "connected" | ||
last_keepalive: true | ||
last_ack: true | ||
msg_count: true | ||
- | ||
name: "Only remote request available" | ||
test_case: | ||
input: | ||
remoted: true | ||
interval: '0' | ||
output: | ||
- | ||
type: "remote" | ||
fields: | ||
status: "connected" | ||
last_keepalive: true | ||
last_ack: true | ||
msg_count: true |
Oops, something went wrong.