-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
win32_event_log/datadog_checks/win32_event_log/config_models/__init__.py
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,18 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from .instance import InstanceConfig | ||
from .shared import SharedConfig | ||
|
||
|
||
class ConfigMixin: | ||
_config_model_instance: InstanceConfig | ||
_config_model_shared: SharedConfig | ||
|
||
@property | ||
def config(self) -> InstanceConfig: | ||
return self._config_model_instance | ||
|
||
@property | ||
def shared_config(self) -> SharedConfig: | ||
return self._config_model_shared |
148 changes: 148 additions & 0 deletions
148
win32_event_log/datadog_checks/win32_event_log/config_models/defaults.py
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,148 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from datadog_checks.base.utils.models.fields import get_default_field_value | ||
|
||
|
||
def shared_default_event_priority(field, value): | ||
return 'normal' | ||
|
||
|
||
def shared_event_priority(field, value): | ||
return 'normal' | ||
|
||
|
||
def shared_interpret_messages(field, value): | ||
return True | ||
|
||
|
||
def shared_service(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def shared_tag_event_id(field, value): | ||
return False | ||
|
||
|
||
def shared_tag_sid(field, value): | ||
return False | ||
|
||
|
||
def instance_auth_type(field, value): | ||
return 'default' | ||
|
||
|
||
def instance_bookmark_frequency(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_domain(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_empty_default_hostname(field, value): | ||
return False | ||
|
||
|
||
def instance_event_format(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_event_id(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_event_priority(field, value): | ||
return 'normal' | ||
|
||
|
||
def instance_excluded_messages(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_filters(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_host(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_included_messages(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_interpret_messages(field, value): | ||
return True | ||
|
||
|
||
def instance_legacy_mode(field, value): | ||
return False | ||
|
||
|
||
def instance_log_file(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_message_filters(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_min_collection_interval(field, value): | ||
return 15 | ||
|
||
|
||
def instance_password(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_path(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_payload_size(field, value): | ||
return 10 | ||
|
||
|
||
def instance_query(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_server(field, value): | ||
return 'localhost' | ||
|
||
|
||
def instance_service(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_source_name(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_start(field, value): | ||
return 'now' | ||
|
||
|
||
def instance_tag_event_id(field, value): | ||
return False | ||
|
||
|
||
def instance_tag_sid(field, value): | ||
return False | ||
|
||
|
||
def instance_tags(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_timeout(field, value): | ||
return 5 | ||
|
||
|
||
def instance_type(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_user(field, value): | ||
return get_default_field_value(field, value) |
71 changes: 71 additions & 0 deletions
71
win32_event_log/datadog_checks/win32_event_log/config_models/instance.py
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,71 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
from typing import Any, Mapping, Optional, Sequence | ||
|
||
from pydantic import BaseModel, root_validator, validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class InstanceConfig(BaseModel): | ||
class Config: | ||
allow_mutation = False | ||
|
||
auth_type: Optional[str] | ||
bookmark_frequency: Optional[int] | ||
domain: Optional[str] | ||
empty_default_hostname: Optional[bool] | ||
event_format: Optional[Sequence[str]] | ||
event_id: Optional[Sequence[str]] | ||
event_priority: Optional[str] | ||
excluded_messages: Optional[Sequence[str]] | ||
filters: Optional[Mapping[str, Any]] | ||
host: Optional[str] | ||
included_messages: Optional[Sequence[str]] | ||
interpret_messages: Optional[bool] | ||
legacy_mode: Optional[bool] | ||
log_file: Optional[Sequence[str]] | ||
message_filters: Optional[Sequence[str]] | ||
min_collection_interval: Optional[float] | ||
password: Optional[str] | ||
path: Optional[str] | ||
payload_size: Optional[int] | ||
query: Optional[str] | ||
server: Optional[str] | ||
service: Optional[str] | ||
source_name: Optional[Sequence[str]] | ||
start: Optional[str] | ||
tag_event_id: Optional[bool] | ||
tag_sid: Optional[bool] | ||
tags: Optional[Sequence[str]] | ||
timeout: Optional[float] | ||
type: Optional[Sequence[str]] | ||
user: Optional[str] | ||
|
||
@root_validator(pre=True) | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values)) | ||
|
||
@validator('*', pre=True, always=True) | ||
def _ensure_defaults(cls, v, field): | ||
if v is not None or field.required: | ||
return v | ||
|
||
return getattr(defaults, f'instance_{field.name}')(field, v) | ||
|
||
@validator('*') | ||
def _run_validations(cls, v, field): | ||
if not v: | ||
return v | ||
|
||
return getattr(validators, f'instance_{field.name}', identity)(v, field=field) | ||
|
||
@root_validator(pre=False) | ||
def _final_validation(cls, values): | ||
return validation.core.finalize_config(getattr(validators, 'finalize_instance', identity)(values)) |
47 changes: 47 additions & 0 deletions
47
win32_event_log/datadog_checks/win32_event_log/config_models/shared.py
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,47 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel, root_validator, validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class SharedConfig(BaseModel): | ||
class Config: | ||
allow_mutation = False | ||
|
||
default_event_priority: Optional[str] | ||
event_priority: Optional[str] | ||
interpret_messages: Optional[bool] | ||
service: Optional[str] | ||
tag_event_id: Optional[bool] | ||
tag_sid: Optional[bool] | ||
|
||
@root_validator(pre=True) | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_shared', identity)(values)) | ||
|
||
@validator('*', pre=True, always=True) | ||
def _ensure_defaults(cls, v, field): | ||
if v is not None or field.required: | ||
return v | ||
|
||
return getattr(defaults, f'shared_{field.name}')(field, v) | ||
|
||
@validator('*') | ||
def _run_validations(cls, v, field): | ||
if not v: | ||
return v | ||
|
||
return getattr(validators, f'shared_{field.name}', identity)(v, field=field) | ||
|
||
@root_validator(pre=False) | ||
def _final_validation(cls, values): | ||
return validation.core.finalize_config(getattr(validators, 'finalize_shared', identity)(values)) |
3 changes: 3 additions & 0 deletions
3
win32_event_log/datadog_checks/win32_event_log/config_models/validators.py
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,3 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) |