-
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.
add agent_check template for publishing platform integrations
- Loading branch information
1 parent
ef41af5
commit cafad04
Showing
20 changed files
with
442 additions
and
11 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
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
1 change: 1 addition & 0 deletions
1
...adog_checks/dev/tooling/templates/integration/check_only/{check_name}/changelog.d/1.added
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 @@ | ||
Initial Release |
2 changes: 2 additions & 0 deletions
2
...ecks/dev/tooling/templates/integration/check_only/{check_name}/datadog_checks/__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,2 @@ | ||
{license_header} | ||
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore |
2 changes: 2 additions & 0 deletions
2
...ng/templates/integration/check_only/{check_name}/datadog_checks/{check_name}/__about__.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,2 @@ | ||
{license_header} | ||
__version__ = '{starting_version}' |
5 changes: 5 additions & 0 deletions
5
...ing/templates/integration/check_only/{check_name}/datadog_checks/{check_name}/__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,5 @@ | ||
{license_header} | ||
from .__about__ import __version__ | ||
from .check import {check_class} | ||
|
||
__all__ = ['__version__', '{check_class}'] |
96 changes: 96 additions & 0 deletions
96
...ooling/templates/integration/check_only/{check_name}/datadog_checks/{check_name}/check.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,96 @@ | ||
{license_header} | ||
from typing import Any # noqa: F401 | ||
|
||
from datadog_checks.base import AgentCheck # noqa: F401 | ||
|
||
# from datadog_checks.base.utils.db import QueryManager | ||
# from requests.exceptions import ConnectionError, HTTPError, InvalidURL, Timeout | ||
# from json import JSONDecodeError | ||
|
||
|
||
class {check_class}(AgentCheck): | ||
|
||
# This will be the prefix of every metric and service check the integration sends | ||
__NAMESPACE__ = '{check_name}' | ||
|
||
def __init__(self, name, init_config, instances): | ||
super({check_class}, self).__init__(name, init_config, instances) | ||
|
||
# Use self.instance to read the check configuration | ||
# self.url = self.instance.get("url") | ||
|
||
# If the check is going to perform SQL queries you should define a query manager here. | ||
# More info at | ||
# https://datadoghq.dev/integrations-core/base/databases/#datadog_checks.base.utils.db.core.QueryManager | ||
# sample_query = {{ | ||
# "name": "sample", | ||
# "query": "SELECT * FROM sample_table", | ||
# "columns": [ | ||
# {{"name": "metric", "type": "gauge"}} | ||
# ], | ||
# }} | ||
# self._query_manager = QueryManager(self, self.execute_query, queries=[sample_query]) | ||
# self.check_initializations.append(self._query_manager.compile_queries) | ||
|
||
def check(self, _): | ||
# type: (Any) -> None | ||
# The following are useful bits of code to help new users get started. | ||
|
||
# Perform HTTP Requests with our HTTP wrapper. | ||
# More info at https://datadoghq.dev/integrations-core/base/http/ | ||
# try: | ||
# response = self.http.get(self.url) | ||
# response.raise_for_status() | ||
# response_json = response.json() | ||
|
||
# except Timeout as e: | ||
# self.service_check( | ||
# "can_connect", | ||
# AgentCheck.CRITICAL, | ||
# message="Request timeout: {{}}, {{}}".format(self.url, e), | ||
# ) | ||
# raise | ||
|
||
# except (HTTPError, InvalidURL, ConnectionError) as e: | ||
# self.service_check( | ||
# "can_connect", | ||
# AgentCheck.CRITICAL, | ||
# message="Request failed: {{}}, {{}}".format(self.url, e), | ||
# ) | ||
# raise | ||
|
||
# except JSONDecodeError as e: | ||
# self.service_check( | ||
# "can_connect", | ||
# AgentCheck.CRITICAL, | ||
# message="JSON Parse failed: {{}}, {{}}".format(self.url, e), | ||
# ) | ||
# raise | ||
|
||
# except ValueError as e: | ||
# self.service_check( | ||
# "can_connect", AgentCheck.CRITICAL, message=str(e) | ||
# ) | ||
# raise | ||
|
||
# This is how you submit metrics | ||
# There are different types of metrics that you can submit (gauge, event). | ||
# More info at https://datadoghq.dev/integrations-core/base/api/#datadog_checks.base.checks.base.AgentCheck | ||
# self.gauge("test", 1.23, tags=['foo:bar']) | ||
|
||
# Perform database queries using the Query Manager | ||
# self._query_manager.execute() | ||
|
||
# This is how you use the persistent cache. This cache file based and persists across agent restarts. | ||
# If you need an in-memory cache that is persisted across runs | ||
# You can define a dictionary in the __init__ method. | ||
# self.write_persistent_cache("key", "value") | ||
# value = self.read_persistent_cache("key") | ||
|
||
# If your check ran successfully, you can send the status. | ||
# More info at | ||
# https://datadoghq.dev/integrations-core/base/api/#datadog_checks.base.checks.base.AgentCheck.service_check | ||
# self.service_check("can_connect", AgentCheck.OK) | ||
|
||
# If it didn't then it should send a critical service check | ||
self.service_check("can_connect", AgentCheck.CRITICAL) |
19 changes: 19 additions & 0 deletions
19
...integration/check_only/{check_name}/datadog_checks/{check_name}/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,19 @@ | ||
{license_header} | ||
|
||
{documentation} | ||
|
||
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 |
10 changes: 10 additions & 0 deletions
10
...integration/check_only/{check_name}/datadog_checks/{check_name}/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,10 @@ | ||
{license_header} | ||
|
||
{documentation} | ||
|
||
def instance_empty_default_hostname(): | ||
return False | ||
|
||
|
||
def instance_min_collection_interval(): | ||
return 15 |
45 changes: 45 additions & 0 deletions
45
...integration/check_only/{check_name}/datadog_checks/{check_name}/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,45 @@ | ||
{license_header} | ||
|
||
{documentation} | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, field_validator, model_validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class InstanceConfig(BaseModel): | ||
model_config = ConfigDict( | ||
validate_default=True, | ||
arbitrary_types_allowed=True, | ||
frozen=True, | ||
) | ||
empty_default_hostname: Optional[bool] = None | ||
min_collection_interval: Optional[float] = None | ||
service: Optional[str] = None | ||
tags: Optional[tuple[str, ...]] = None | ||
|
||
@model_validator(mode='before') | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values)) | ||
|
||
@field_validator('*', mode='before') | ||
def _validate(cls, value, info): | ||
field = cls.model_fields[info.field_name] | ||
field_name = field.alias or info.field_name | ||
if field_name in info.context['configured_fields']: | ||
value = getattr(validators, f'instance_{{info.field_name}}', identity)(value, field=field) | ||
else: | ||
value = getattr(defaults, f'instance_{{info.field_name}}', lambda: value)() | ||
|
||
return validation.utils.make_immutable(value) | ||
|
||
@model_validator(mode='after') | ||
def _final_validation(cls, model): | ||
return validation.core.check_model(getattr(validators, 'check_instance', identity)(model)) |
42 changes: 42 additions & 0 deletions
42
...s/integration/check_only/{check_name}/datadog_checks/{check_name}/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,42 @@ | ||
{license_header} | ||
|
||
{documentation} | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, field_validator, model_validator | ||
|
||
from datadog_checks.base.utils.functions import identity | ||
from datadog_checks.base.utils.models import validation | ||
|
||
from . import defaults, validators | ||
|
||
|
||
class SharedConfig(BaseModel): | ||
model_config = ConfigDict( | ||
validate_default=True, | ||
arbitrary_types_allowed=True, | ||
frozen=True, | ||
) | ||
service: Optional[str] = None | ||
|
||
@model_validator(mode='before') | ||
def _initial_validation(cls, values): | ||
return validation.core.initialize_config(getattr(validators, 'initialize_shared', identity)(values)) | ||
|
||
@field_validator('*', mode='before') | ||
def _validate(cls, value, info): | ||
field = cls.model_fields[info.field_name] | ||
field_name = field.alias or info.field_name | ||
if field_name in info.context['configured_fields']: | ||
value = getattr(validators, f'shared_{{info.field_name}}', identity)(value, field=field) | ||
else: | ||
value = getattr(defaults, f'shared_{{info.field_name}}', lambda: value)() | ||
|
||
return validation.utils.make_immutable(value) | ||
|
||
@model_validator(mode='after') | ||
def _final_validation(cls, model): | ||
return validation.core.check_model(getattr(validators, 'check_shared', identity)(model)) |
11 changes: 11 additions & 0 deletions
11
...tegration/check_only/{check_name}/datadog_checks/{check_name}/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,11 @@ | ||
{license_header} | ||
|
||
# Here you can include additional config validators or transformers | ||
# | ||
# def initialize_instance(values, **kwargs): | ||
# if 'my_option' not in values and 'my_legacy_option' in values: | ||
# values['my_option'] = values['my_legacy_option'] | ||
# if values.get('my_number') > 10: | ||
# raise ValueError('my_number max value is 10, got %s' % str(values.get('my_number'))) | ||
# | ||
# return values |
Oops, something went wrong.