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
Add API JSON log handling #11171
Merged
davidjiglesias
merged 20 commits into
dev-support-api-json-log
from
feature/10867-api-json-log
Apr 20, 2022
Merged
Add API JSON log handling #11171
davidjiglesias
merged 20 commits into
dev-support-api-json-log
from
feature/10867-api-json-log
Apr 20, 2022
Conversation
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
5 tasks
Kondent
force-pushed
the
feature/10867-api-json-log
branch
3 times, most recently
from
December 14, 2021 13:56
1b1c8bc
to
3560b61
Compare
Kondent
force-pushed
the
feature/10867-api-json-log
branch
3 times, most recently
from
February 11, 2022 17:18
6337ad3
to
3f1f2f2
Compare
Kondent
force-pushed
the
feature/10867-api-json-log
branch
3 times, most recently
from
February 14, 2022 19:55
e14b911
to
5c78316
Compare
Kondent
force-pushed
the
feature/10867-api-json-log
branch
from
February 15, 2022 19:27
04d3565
to
66f1103
Compare
mcarmona99
suggested changes
Feb 17, 2022
mcarmona99
approved these changes
Feb 18, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Kondent
force-pushed
the
feature/10867-api-json-log
branch
from
February 25, 2022 13:46
a600133
to
43a38e7
Compare
This was referenced Mar 4, 2022
mcarmona99
force-pushed
the
feature/10867-api-json-log
branch
from
March 18, 2022 15:14
9963eef
to
bfba0a8
Compare
davidjiglesias
approved these changes
Apr 20, 2022
mcarmona99
pushed a commit
that referenced
this pull request
Apr 21, 2022
* Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
mcarmona99
pushed a commit
that referenced
this pull request
Apr 27, 2022
* Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
mcarmona99
pushed a commit
that referenced
this pull request
May 4, 2022
* Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
mcarmona99
pushed a commit
that referenced
this pull request
May 5, 2022
* Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
mcarmona99
pushed a commit
that referenced
this pull request
May 9, 2022
* Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
davidjiglesias
pushed a commit
that referenced
this pull request
May 11, 2022
…ncy (#13197) * Add python-json-logger to requirements.txt (#11153) * Add API JSON log handling (#11171) * Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com> Co-authored-by: Alexis Rivas <84642680+Kondent@users.noreply.github.com> Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
FrancoRivero
pushed a commit
that referenced
this pull request
May 13, 2022
…ncy (#13197) * Add python-json-logger to requirements.txt (#11153) * Add API JSON log handling (#11171) * Add API JSON Logs * Fix related unittest * Fix API config from AIT * Fix alogging unittest and wazuhjsonformatter * Add docstrings * Add traceback message handling * Fix wazuhjsonformatter and related unittest * Add few improvements regarding key names and debug2 handling * Fix unittest for alogging * Add minor fixes after the rebase from master * Add minor fixes at related unit test * Add support for logging into both file types at the same time * Fix related unit test * Fix CustomFilter class and add related unit test * Add foreground fix related with default formatter * Fix related unit test * Add log rotation support for json files * Add requested changes: docstrings and minor fixes * Fix log rotation unit test * Remove python-json-logger from requirements file. Added in #11153 Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com> Co-authored-by: Alexis Rivas <84642680+Kondent@users.noreply.github.com> Co-authored-by: Alexis Rivas <alexis.rivas@wazuh.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Under this development, I made a few adjustments to make API log parsing easier by allowing our API to write them in JSON format, besides plain text.
Changes on this PR:
api.yaml
.api.yaml
from AIT.api/api/test/test_alogging.py
.api/api/test/test_configuration.py
.framework/wazuh/core/cluster/tests/test_utils.py
.framework/wazuh/core/tests/test_wlogging.py
.api/api/configuration.py
.api/api/validator.py
.api/scripts/wazuh-apid.py
.framework/scripts/wazuh-clusterd.py
.framework/wazuh/core/wlogging.py
.framework/requirements.txt
.api/api/alogging.py
.API Default Configuration Block:
NOTE:
format
allowed values arejson
,plain
,json,plain
andplain,json
JSON Log Handler
With this customization of
python-json-logger
we're adding the information to the log entry with the formatting we want.In other words, API json log will have three keys:
timestamp
,levelname
anddata
. The last key is a dict with two more keys:type
andpayload
.type
: str. Value could beinformative
,error
orrequest
.payload
: str or dict. Value could be a plain text message or a dict if the value for thetype
key isrequest
.NOTE: every log entry will have these three main keys, even with log level set as
DEBUG
orDEBUG2
API JSON Log Sample:
Starting
Request
Unhandled Exception
Starting with
DEBUG2
Foreground mode - JSON
Foreground mode - PLAIN
Foreground mode - BOTH
Unit Test: API
Unit Test: Framework
Related Integration tests (dependency installed in a local environment):
Dependencies Scanner:
Full report.json