Alerting Plugins (#93)
* Alert Plugin Signed-off-by: Arnav Das <arnav.das88@gmail.com> * lint file header license Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Tests For Alerting[Monitors] Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Tests For Alerting[Destinations] Signed-off-by: Arnav Das <arnav.das88@gmail.com> * dynamic lookup 90#issuecomment-1003396742 Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Alerting Async Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Lint Changes Signed-off-by: Arnav Das <arnav.das88@gmail.com> * alerting plugins integration tests Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Integ UnitTests Skip on OPENSEARCH_VERSION >= 2.0.0 Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Unit Test Skip Complete Signed-off-by: Arnav Das <arnav.das88@gmail.com> * License Headers fixed Signed-off-by: Arnav Das <arnav.das88@gmail.com> * test_urllib3_connection timeout Signed-off-by: Arnav Das <arnav.das88@gmail.com> * lint Signed-off-by: Arnav Das <arnav.das88@gmail.com> * Fix licenses in all files Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> * Remove elastic search licenses on new files Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> * Fix formatting Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Arnav Das <arnav.das88@gmail.com> Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Co-authored-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
This commit is contained in:
@@ -34,6 +34,7 @@ docker run \
|
||||
--network=${network_name} \
|
||||
--env "STACK_VERSION=${STACK_VERSION}" \
|
||||
--env "OPENSEARCH_URL=${opensearch_url}" \
|
||||
--env "OPENSEARCH_VERSION=${OPENSEARCH_VERSION}" \
|
||||
--env "TEST_SUITE=${TEST_SUITE}" \
|
||||
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
|
||||
--env "TEST_TYPE=server" \
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import nox
|
||||
|
||||
SOURCE_FILES = (
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# flake8: noqa
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# type: ignore
|
||||
|
||||
# This file exists for the sole reason of making mypy not
|
||||
|
||||
@@ -37,6 +37,7 @@ from .features import FeaturesClient
|
||||
from .indices import IndicesClient
|
||||
from .ingest import IngestClient
|
||||
from .nodes import NodesClient
|
||||
from .plugins import PluginsClient
|
||||
from .remote import RemoteClient
|
||||
from .snapshot import SnapshotClient
|
||||
from .tasks import TasksClient
|
||||
@@ -197,6 +198,7 @@ class AsyncOpenSearch(object):
|
||||
self.remote = RemoteClient(self)
|
||||
self.snapshot = SnapshotClient(self)
|
||||
self.tasks = TasksClient(self)
|
||||
self.plugins = PluginsClient(self)
|
||||
|
||||
self.features = FeaturesClient(self)
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class AsyncOpenSearch(object):
|
||||
self,
|
||||
hosts: Any = ...,
|
||||
transport_class: Type[AsyncTransport] = ...,
|
||||
**kwargs: Any,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
def __repr__(self) -> str: ...
|
||||
async def __aenter__(self) -> "AsyncOpenSearch": ...
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
import warnings
|
||||
|
||||
from ..plugins.alerting import AlertingClient
|
||||
from .utils import NamespacedClient
|
||||
|
||||
|
||||
class PluginsClient(NamespacedClient):
|
||||
def __init__(self, client):
|
||||
super(PluginsClient, self).__init__(client)
|
||||
# self.query_workbench = QueryWorkbenchClient(client)
|
||||
# self.reporting = ReportingClient(client)
|
||||
# self.notebooks = NotebooksClient(client)
|
||||
self.alerting = AlertingClient(client)
|
||||
# self.anomaly_detection = AnomalyDetectionClient(client)
|
||||
# self.trace_analytics = TraceAnalyticsClient(client)
|
||||
# self.index_management = IndexManagementClient(client)
|
||||
# self.security = SecurityClient(client)
|
||||
|
||||
self._dynamic_lookup(client)
|
||||
|
||||
def _dynamic_lookup(self, client):
|
||||
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
|
||||
|
||||
plugins = [
|
||||
# "query_workbench",
|
||||
# "reporting",
|
||||
# "notebooks",
|
||||
"alerting",
|
||||
# "anomaly_detection",
|
||||
# "trace_analytics",
|
||||
# "index_management",
|
||||
# "security"
|
||||
]
|
||||
for plugin in plugins:
|
||||
if not hasattr(client, plugin):
|
||||
setattr(client, plugin, getattr(self, plugin))
|
||||
else:
|
||||
warnings.warn(
|
||||
f"Cannot load `{plugin}` directly to AsyncOpenSearch. `{plugin}` already exists in AsyncOpenSearch. Please use `AsyncOpenSearch.plugin.{plugin}` instead.",
|
||||
category=RuntimeWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
from typing import Any
|
||||
|
||||
from ..client import AsyncOpenSearch
|
||||
from ..plugins.alerting import AlertingClient as AlertingClient
|
||||
from .utils import NamespacedClient as NamespacedClient
|
||||
|
||||
class PluginsClient(NamespacedClient):
|
||||
alerting: Any
|
||||
def __init__(self, client: AsyncOpenSearch) -> None: ...
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import warnings
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ...client.utils import ( # noqa
|
||||
SKIP_IN_PATH,
|
||||
NamespacedClient,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
from ..compat import * # noqa
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# Licensed to Elasticsearch B.V.under one or more agreements.
|
||||
# Elasticsearch B.V.licenses this file to you under the Apache 2.0 License.
|
||||
# See the LICENSE file in the project root for more information
|
||||
@@ -203,7 +204,7 @@ async def async_streaming_bulk(
|
||||
raise_on_error,
|
||||
ignore_status,
|
||||
*args,
|
||||
**kwargs,
|
||||
**kwargs
|
||||
),
|
||||
):
|
||||
|
||||
@@ -470,5 +471,5 @@ async def async_reindex(
|
||||
target_client,
|
||||
_change_doc_index(docs, target_index),
|
||||
chunk_size=chunk_size,
|
||||
**kwargs,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import ssl
|
||||
@@ -97,7 +98,7 @@ class AIOHttpConnection(AsyncConnection):
|
||||
http_compress=None,
|
||||
opaque_id=None,
|
||||
loop=None,
|
||||
**kwargs,
|
||||
**kwargs
|
||||
):
|
||||
"""
|
||||
Default connection class for ``AsyncOpenSearch`` using the `aiohttp` library and the http protocol.
|
||||
@@ -142,7 +143,7 @@ class AIOHttpConnection(AsyncConnection):
|
||||
headers=headers,
|
||||
http_compress=http_compress,
|
||||
opaque_id=opaque_id,
|
||||
**kwargs,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if http_auth is not None:
|
||||
|
||||
@@ -64,5 +64,5 @@ class AIOHttpConnection(AsyncConnection):
|
||||
http_compress: Optional[bool] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
loop: Any = ...,
|
||||
**kwargs: Any,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
@@ -0,0 +1,200 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from ..client.utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
class AlertingClient(NamespacedClient):
|
||||
@query_params()
|
||||
async def search_monitor(self, body, params=None, headers=None):
|
||||
"""
|
||||
Returns the search result for a monitor.
|
||||
|
||||
:arg monitor_id: The configuration for the monitor we are trying to search
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", "_search"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def get_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Returns the details of a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to fetch
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params("dryrun")
|
||||
async def run_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Runs/Executes a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to execute
|
||||
:arg dryrun: Shows the results of a run without actions sending any message
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id, "_execute"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def create_monitor(self, body=None, params=None, headers=None):
|
||||
"""
|
||||
Creates a monitor with inputs, triggers, and actions.
|
||||
|
||||
:arg body: The configuration for the monitor (`inputs`, `triggers`, and `actions`)
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "monitors"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def update_monitor(self, monitor_id, body=None, params=None, headers=None):
|
||||
"""
|
||||
Updates a monitor's inputs, triggers, and actions.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to update
|
||||
:arg body: The configuration for the monitor (`inputs`, `triggers`, and `actions`)
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"PUT",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def delete_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Deletes a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to delete
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"DELETE",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def get_destination(self, destination_id=None, params=None, headers=None):
|
||||
"""
|
||||
Returns the details of a specific destination.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to fetch. If None, returns all destinations
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id)
|
||||
if destination_id
|
||||
else _make_path("_plugins", "_alerting", "destinations"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def create_destination(self, body=None, params=None, headers=None):
|
||||
"""
|
||||
Creates a destination for slack, mail, or custom-webhook.
|
||||
|
||||
:arg body: The configuration for the destination
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "destinations"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def update_destination(
|
||||
self, destination_id, body=None, params=None, headers=None
|
||||
):
|
||||
"""
|
||||
Updates a destination's inputs, triggers, and actions.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to update
|
||||
:arg body: The configuration for the destination
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"PUT",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def delete_destination(self, destination_id, params=None, headers=None):
|
||||
"""
|
||||
Deletes a specific destination.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to delete
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"DELETE",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def get_alerts(self, params=None, headers=None):
|
||||
"""
|
||||
Returns all alerts.
|
||||
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", "alerts"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def acknowledge_alert(self, monitor_id, body=None, params=None, headers=None):
|
||||
"""
|
||||
Acknowledges an alert.
|
||||
|
||||
:arg monitor_id: The id of the monitor, the alert belongs to
|
||||
:arg body: The alerts to be acknowledged
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path(
|
||||
"_plugins",
|
||||
"_alerting",
|
||||
"monitors",
|
||||
monitor_id,
|
||||
"_acknowledge",
|
||||
"alerts",
|
||||
),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
@@ -0,0 +1,82 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
from typing import Any, Union
|
||||
|
||||
from ..client.utils import NamespacedClient as NamespacedClient
|
||||
|
||||
class AlertingClient(NamespacedClient):
|
||||
def search_monitor(
|
||||
self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_monitor(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def run_monitor(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def create_monitor(
|
||||
self,
|
||||
body: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def update_monitor(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
body: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def delete_monitor(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_destination(
|
||||
self,
|
||||
destination_id: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def create_destination(
|
||||
self,
|
||||
body: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def update_destination(
|
||||
self,
|
||||
destination_id: Any,
|
||||
body: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def delete_destination(
|
||||
self,
|
||||
destination_id: Any,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_alerts(
|
||||
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def acknowledge_alert(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
body: Union[Any, None] = ...,
|
||||
params: Union[Any, None] = ...,
|
||||
headers: Union[Any, None] = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
|
||||
@@ -24,4 +24,5 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
__versionstr__ = "2.0.0"
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
@@ -37,6 +38,7 @@ from .features import FeaturesClient
|
||||
from .indices import IndicesClient
|
||||
from .ingest import IngestClient
|
||||
from .nodes import NodesClient
|
||||
from .plugins import PluginsClient
|
||||
from .remote import RemoteClient
|
||||
from .snapshot import SnapshotClient
|
||||
from .tasks import TasksClient
|
||||
@@ -200,6 +202,8 @@ class OpenSearch(object):
|
||||
|
||||
self.features = FeaturesClient(self)
|
||||
|
||||
self.plugins = PluginsClient(self)
|
||||
|
||||
def __repr__(self):
|
||||
try:
|
||||
# get a list of all connections
|
||||
|
||||
@@ -57,10 +57,7 @@ class OpenSearch(object):
|
||||
snapshot: SnapshotClient
|
||||
tasks: TasksClient
|
||||
def __init__(
|
||||
self,
|
||||
hosts: Any = ...,
|
||||
transport_class: Type[Transport] = ...,
|
||||
**kwargs: Any,
|
||||
self, hosts: Any = ..., transport_class: Type[Transport] = ..., **kwargs: Any
|
||||
) -> None: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __enter__(self) -> "OpenSearch": ...
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
import warnings
|
||||
|
||||
from ..plugins.alerting import AlertingClient
|
||||
from .utils import NamespacedClient
|
||||
|
||||
|
||||
class PluginsClient(NamespacedClient):
|
||||
def __init__(self, client):
|
||||
super(PluginsClient, self).__init__(client)
|
||||
# self.query_workbench = QueryWorkbenchClient(client)
|
||||
# self.reporting = ReportingClient(client)
|
||||
# self.notebooks = NotebooksClient(client)
|
||||
self.alerting = AlertingClient(client)
|
||||
# self.anomaly_detection = AnomalyDetectionClient(client)
|
||||
# self.trace_analytics = TraceAnalyticsClient(client)
|
||||
# self.index_management = IndexManagementClient(client)
|
||||
# self.security = SecurityClient(client)
|
||||
|
||||
self._dynamic_lookup(client)
|
||||
|
||||
def _dynamic_lookup(self, client):
|
||||
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
|
||||
|
||||
plugins = [
|
||||
# "query_workbench",
|
||||
# "reporting",
|
||||
# "notebooks",
|
||||
"alerting",
|
||||
# "anomaly_detection",
|
||||
# "trace_analytics",
|
||||
# "index_management",
|
||||
# "security"
|
||||
]
|
||||
for plugin in plugins:
|
||||
if not hasattr(client, plugin):
|
||||
setattr(client, plugin, getattr(self, plugin))
|
||||
else:
|
||||
warnings.warn(
|
||||
"Cannot load `{plugin}` directly to OpenSearch. `{plugin}` already exists in OpenSearch. Please use `OpenSearch.plugin.{plugin}` instead.".format(
|
||||
plugin=plugin
|
||||
),
|
||||
category=RuntimeWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
from typing import Any
|
||||
|
||||
from ..client import OpenSearch
|
||||
from ..plugins.alerting import AlertingClient as AlertingClient
|
||||
from .utils import NamespacedClient as NamespacedClient
|
||||
|
||||
class PluginsClient(NamespacedClient):
|
||||
alerting: Any
|
||||
def __init__(self, client: OpenSearch) -> None: ...
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import NamespacedClient, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import warnings
|
||||
|
||||
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .base import Connection
|
||||
from .http_requests import RequestsHttpConnection
|
||||
from .http_urllib3 import Urllib3HttpConnection, create_ssl_context
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import gzip
|
||||
import io
|
||||
import logging
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import time
|
||||
import warnings
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import ssl
|
||||
import time
|
||||
import warnings
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from .base import Connection
|
||||
|
||||
try:
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import logging
|
||||
import random
|
||||
import threading
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ImproperlyConfigured",
|
||||
"OpenSearchException",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
from .actions import (
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import logging
|
||||
import time
|
||||
from operator import methodcaller
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ..exceptions import OpenSearchException
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# type: ignore
|
||||
|
||||
import os
|
||||
@@ -100,3 +101,12 @@ def _get_version(version_string):
|
||||
|
||||
def opensearch_version(client):
|
||||
return _get_version(client.info()["version"]["number"])
|
||||
|
||||
|
||||
if "OPENSEARCH_VERSION" in os.environ:
|
||||
OPENSEARCH_VERSION = _get_version(os.environ["OPENSEARCH_VERSION"])
|
||||
else:
|
||||
client = OpenSearch(
|
||||
OPENSEARCH_URL,
|
||||
)
|
||||
OPENSEARCH_VERSION = opensearch_version(client)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
#
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
@@ -0,0 +1,199 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from ..client.utils import NamespacedClient, _make_path, query_params
|
||||
|
||||
|
||||
class AlertingClient(NamespacedClient):
|
||||
@query_params()
|
||||
def search_monitor(self, body, params=None, headers=None):
|
||||
"""
|
||||
Returns the search result for a monitor.
|
||||
|
||||
:arg monitor_id: The configuration for the monitor we are trying to search
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", "_search"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def get_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Returns the details of a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to fetch
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params("dryrun")
|
||||
def run_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Runs/Executes a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to execute
|
||||
:arg dryrun: Shows the results of a run without actions sending any message
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id, "_execute"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def create_monitor(self, body=None, params=None, headers=None):
|
||||
"""
|
||||
Creates a monitor with inputs, triggers, and actions.
|
||||
|
||||
:arg body: The configuration for the monitor (`inputs`, `triggers`, and `actions`)
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "monitors"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def update_monitor(self, monitor_id, body=None, params=None, headers=None):
|
||||
"""
|
||||
Updates a monitor's inputs, triggers, and actions.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to update
|
||||
:arg body: The configuration for the monitor (`inputs`, `triggers`, and `actions`)
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"PUT",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def delete_monitor(self, monitor_id, params=None, headers=None):
|
||||
"""
|
||||
Deletes a specific monitor.
|
||||
|
||||
:arg monitor_id: The id of the monitor we are trying to delete
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"DELETE",
|
||||
_make_path("_plugins", "_alerting", "monitors", monitor_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def get_destination(self, destination_id=None, params=None, headers=None):
|
||||
"""
|
||||
Returns the details of a specific destination.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to fetch. If None, returns all destinations
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id)
|
||||
if destination_id
|
||||
else _make_path("_plugins", "_alerting", "destinations"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def create_destination(self, body=None, params=None, headers=None):
|
||||
"""
|
||||
Creates a destination for slack, mail, or custom-webhook.
|
||||
|
||||
:arg body: The configuration for the destination
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path("_plugins", "_alerting", "destinations"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def update_destination(self, destination_id, body=None, params=None, headers=None):
|
||||
"""
|
||||
Updates a destination's inputs, triggers, and actions.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to update
|
||||
:arg body: The configuration for the destination
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"PUT",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def delete_destination(self, destination_id, params=None, headers=None):
|
||||
"""
|
||||
Deletes a specific destination.
|
||||
|
||||
:arg destination_id: The id of the destination we are trying to delete
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"DELETE",
|
||||
_make_path("_plugins", "_alerting", "destinations", destination_id),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def get_alerts(self, params=None, headers=None):
|
||||
"""
|
||||
Returns all alerts.
|
||||
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"GET",
|
||||
_make_path("_plugins", "_alerting", "monitors", "alerts"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def acknowledge_alert(self, monitor_id, body=None, params=None, headers=None):
|
||||
"""
|
||||
Acknowledges an alert.
|
||||
|
||||
:arg monitor_id: The id of the monitor, the alert belongs to
|
||||
:arg body: The alerts to be acknowledged
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"POST",
|
||||
_make_path(
|
||||
"_plugins",
|
||||
"_alerting",
|
||||
"monitors",
|
||||
monitor_id,
|
||||
"_acknowledge",
|
||||
"alerts",
|
||||
),
|
||||
params=params,
|
||||
headers=headers,
|
||||
body=body,
|
||||
)
|
||||
@@ -0,0 +1,73 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
#
|
||||
|
||||
from typing import Any, Union
|
||||
|
||||
from ..client.utils import NamespacedClient as NamespacedClient
|
||||
from ..client.utils import query_params as query_params
|
||||
|
||||
class AlertingClient(NamespacedClient):
|
||||
def search_monitor(
|
||||
self, body: Any, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_monitor(
|
||||
self, monitor_id: Any, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def run_monitor(
|
||||
self, monitor_id: Any, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def create_monitor(
|
||||
self,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def update_monitor(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def delete_monitor(
|
||||
self, monitor_id: Any, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_destination(
|
||||
self,
|
||||
destination_id: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def create_destination(
|
||||
self,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def update_destination(
|
||||
self,
|
||||
destination_id: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
def delete_destination(
|
||||
self, destination_id: Any, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def get_alerts(
|
||||
self, params: Any | None = ..., headers: Any | None = ...
|
||||
) -> Union[bool, Any]: ...
|
||||
def acknowledge_alert(
|
||||
self,
|
||||
monitor_id: Any,
|
||||
body: Any | None = ...,
|
||||
params: Any | None = ...,
|
||||
headers: Any | None = ...,
|
||||
) -> Union[bool, Any]: ...
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
try:
|
||||
import simplejson as json
|
||||
except ImportError:
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import time
|
||||
from itertools import chain
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from ..plugins.alerting import AlertingClient as AlertingClient
|
||||
from .utils import NamespacedClient as NamespacedClient
|
||||
from typing import Any
|
||||
|
||||
class PluginsClient(NamespacedClient):
|
||||
alerting: Any
|
||||
def __init__(self, client) -> None: ...
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
@@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from ..client.utils import NamespacedClient as NamespacedClient, query_params as query_params
|
||||
from typing import Any, Union
|
||||
|
||||
class AlertingClient(NamespacedClient):
|
||||
def search_monitor(self, body, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def get_monitor(self, monitor_id, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def run_monitor(self, monitor_id, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def create_monitor(self, body: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def update_monitor(self, monitor_id, body: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def delete_monitor(self, monitor_id, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def get_destination(self, destination_id: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def create_destination(self, body: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def update_destination(self, destination_id, body: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def delete_destination(self, destination_id, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def get_alerts(self, params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
def acknowledge_alert(self, monitor_id, body: Any | None = ..., params: Any | None = ..., headers: Any | None = ...) -> Union[bool, Any]: ...
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import re
|
||||
from os.path import abspath, dirname, join
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import subprocess
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# Licensed to Elasticsearch B.V.under one or more agreements.
|
||||
# Elasticsearch B.V.licenses this file to you under the Apache 2.0 License.
|
||||
# See the LICENSE file in the project root for more information
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
"""
|
||||
Dynamically generated set of TestCases based on set of yaml files decribing
|
||||
some integration tests. These files are shared among all official OpenSearch
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import asyncio
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from collections import defaultdict
|
||||
from unittest import SkipTest # noqa: F401
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import warnings
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from test_opensearchpy.test_cases import OpenSearchTestCase
|
||||
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from test_opensearchpy.test_cases import OpenSearchTestCase
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from test_opensearchpy.test_cases import OpenSearchTestCase
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
from test_opensearchpy.test_cases import OpenSearchTestCase
|
||||
|
||||
|
||||
class TestAlerting(OpenSearchTestCase):
|
||||
def test_create_monitor(self):
|
||||
# Test Post Method
|
||||
self.client.alerting.create_monitor({})
|
||||
self.assert_url_called("POST", "/_plugins/_alerting/monitors")
|
||||
|
||||
def test_run_monitor(self):
|
||||
self.client.alerting.run_monitor("...")
|
||||
self.assert_url_called("POST", "/_plugins/_alerting/monitors/.../_execute")
|
||||
|
||||
def test_get_monitor(self):
|
||||
# Test Get Method
|
||||
self.client.alerting.get_monitor("...")
|
||||
self.assert_url_called("GET", "/_plugins/_alerting/monitors/...")
|
||||
|
||||
def test_search_monitor(self):
|
||||
# Test Search Method
|
||||
self.client.alerting.search_monitor({})
|
||||
self.assert_url_called("GET", "/_plugins/_alerting/monitors/_search")
|
||||
|
||||
def test_update_monitor(self):
|
||||
# Test Update Method
|
||||
self.client.alerting.update_monitor("...")
|
||||
self.assert_url_called("PUT", "/_plugins/_alerting/monitors/...")
|
||||
|
||||
def test_delete_monitor(self):
|
||||
# Test Delete Method
|
||||
self.client.alerting.delete_monitor("...")
|
||||
self.assert_url_called("DELETE", "/_plugins/_alerting/monitors/...")
|
||||
|
||||
def test_create_destination(self):
|
||||
# Test Post Method
|
||||
self.client.alerting.create_destination({})
|
||||
self.assert_url_called("POST", "/_plugins/_alerting/destinations")
|
||||
|
||||
def test_get_destination(self):
|
||||
# Test Get Method
|
||||
|
||||
# Get a specific destination
|
||||
self.client.alerting.get_destination("...")
|
||||
self.assert_url_called("GET", "/_plugins/_alerting/destinations/...")
|
||||
|
||||
# Get all destinations
|
||||
self.client.alerting.get_destination()
|
||||
self.assert_url_called("GET", "/_plugins/_alerting/destinations")
|
||||
|
||||
def test_update_destination(self):
|
||||
# Test Update Method
|
||||
self.client.alerting.update_destination("...")
|
||||
self.assert_url_called("PUT", "/_plugins/_alerting/destinations/...")
|
||||
|
||||
def test_delete_destination(self):
|
||||
# Test Delete Method
|
||||
self.client.alerting.delete_destination("...")
|
||||
self.assert_url_called("DELETE", "/_plugins/_alerting/destinations/...")
|
||||
|
||||
def test_get_alerts(self):
|
||||
self.client.alerting.get_alerts()
|
||||
self.assert_url_called("GET", "/_plugins/_alerting/monitors/alerts")
|
||||
|
||||
def test_acknowledge_alerts(self):
|
||||
self.client.alerting.acknowledge_alert("...")
|
||||
self.assert_url_called(
|
||||
"POST", "/_plugins/_alerting/monitors/.../_acknowledge/alerts"
|
||||
)
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from opensearchpy.client.utils import _bulk_body, _escape, _make_path, query_params
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
@@ -784,7 +785,8 @@ class TestConnectionHttpbin:
|
||||
|
||||
def test_urllib3_connection(self):
|
||||
# Defaults
|
||||
conn = Urllib3HttpConnection("httpbin.org", port=443, use_ssl=True)
|
||||
# httpbin.org can be slow sometimes. Hence the timeout
|
||||
conn = Urllib3HttpConnection("httpbin.org", port=443, use_ssl=True, timeout=60)
|
||||
user_agent = conn._get_default_user_agent()
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -798,7 +800,7 @@ class TestConnectionHttpbin:
|
||||
|
||||
# http_compress=False
|
||||
conn = Urllib3HttpConnection(
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=False
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=False, timeout=60
|
||||
)
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -812,7 +814,7 @@ class TestConnectionHttpbin:
|
||||
|
||||
# http_compress=True
|
||||
conn = Urllib3HttpConnection(
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=True
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=True, timeout=60
|
||||
)
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -830,6 +832,7 @@ class TestConnectionHttpbin:
|
||||
use_ssl=True,
|
||||
http_compress=True,
|
||||
headers={"header1": "value1"},
|
||||
timeout=60,
|
||||
)
|
||||
status, data = self.httpbin_anything(
|
||||
conn, headers={"header2": "value2", "header1": "override!"}
|
||||
@@ -851,7 +854,7 @@ class TestConnectionHttpbin:
|
||||
|
||||
def test_requests_connection(self):
|
||||
# Defaults
|
||||
conn = RequestsHttpConnection("httpbin.org", port=443, use_ssl=True)
|
||||
conn = RequestsHttpConnection("httpbin.org", port=443, use_ssl=True, timeout=60)
|
||||
user_agent = conn._get_default_user_agent()
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -865,7 +868,7 @@ class TestConnectionHttpbin:
|
||||
|
||||
# http_compress=False
|
||||
conn = RequestsHttpConnection(
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=False
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=False, timeout=60
|
||||
)
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -879,7 +882,7 @@ class TestConnectionHttpbin:
|
||||
|
||||
# http_compress=True
|
||||
conn = RequestsHttpConnection(
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=True
|
||||
"httpbin.org", port=443, use_ssl=True, http_compress=True, timeout=60
|
||||
)
|
||||
status, data = self.httpbin_anything(conn)
|
||||
assert status == 200
|
||||
@@ -897,6 +900,7 @@ class TestConnectionHttpbin:
|
||||
use_ssl=True,
|
||||
http_compress=True,
|
||||
headers={"header1": "value1"},
|
||||
timeout=60,
|
||||
)
|
||||
status, data = self.httpbin_anything(
|
||||
conn, headers={"header2": "value2", "header1": "override!"}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import time
|
||||
|
||||
from opensearchpy.connection import Connection
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from opensearchpy.exceptions import TransportError
|
||||
|
||||
from .test_cases import TestCase
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import sys
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from unittest import SkipTest
|
||||
|
||||
from opensearchpy.helpers import test
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from . import OpenSearchTestCase
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from mock import patch
|
||||
|
||||
from opensearchpy import TransportError, helpers
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# The OpenSearch Contributors require contributions made to
|
||||
# this file be licensed under the Apache-2.0 license or a
|
||||
# compatible open source license.
|
||||
#
|
||||
# Modifications Copyright OpenSearch Contributors. See
|
||||
# GitHub history for details.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
from opensearchpy.helpers.test import OPENSEARCH_VERSION
|
||||
|
||||
from . import OpenSearchTestCase
|
||||
|
||||
|
||||
class TestAlertingPlugin(OpenSearchTestCase):
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_create_destination(self):
|
||||
# Test to create alert destination
|
||||
dummy_destination = {
|
||||
"name": "my-destination",
|
||||
"type": "slack",
|
||||
"slack": {"url": "http://www.example.com"},
|
||||
}
|
||||
response = self.client.alerting.create_destination(dummy_destination)
|
||||
|
||||
self.assertNotIn("errors", response)
|
||||
self.assertIn("_id", response)
|
||||
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_get_destination(self):
|
||||
# Create a dummy destination
|
||||
self.test_create_destination()
|
||||
|
||||
# Try fetching the destination
|
||||
response = self.client.alerting.get_destination()
|
||||
|
||||
self.assertNotIn("errors", response)
|
||||
self.assertGreaterEqual(response["totalDestinations"], 1)
|
||||
self.assertEqual(response["totalDestinations"], len(response["destinations"]))
|
||||
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_create_monitor(self):
|
||||
# Create a dummy destination
|
||||
self.test_create_destination()
|
||||
|
||||
# Try fetching the destination
|
||||
destination = self.client.alerting.get_destination()
|
||||
self.assertGreaterEqual(
|
||||
destination["totalDestinations"],
|
||||
1,
|
||||
"No destination entries found in the database.",
|
||||
)
|
||||
|
||||
# Select the first destination available
|
||||
destination = destination["destinations"][0]
|
||||
|
||||
# A dummy schedule for 1 minute interval
|
||||
schedule = {"period": {"interval": 1, "unit": "MINUTES"}}
|
||||
|
||||
# A dummy query fetching everything
|
||||
query = {"query": {"query_string": {"query": "*"}}}
|
||||
|
||||
# A dummy action with the dummy destination
|
||||
action = {
|
||||
"name": "test-action",
|
||||
"destination_id": destination["id"],
|
||||
"message_template": {"source": "This is my message body."},
|
||||
"throttle_enabled": True,
|
||||
"throttle": {"value": 27, "unit": "MINUTES"},
|
||||
"subject_template": {"source": "TheSubject"},
|
||||
}
|
||||
|
||||
# A dummy trigger with the dummy action
|
||||
triggers = {
|
||||
"name": "test-trigger",
|
||||
"severity": "1",
|
||||
"condition": {
|
||||
"script": {
|
||||
"source": "ctx.results[0].hits.total.value > 0",
|
||||
"lang": "painless",
|
||||
}
|
||||
},
|
||||
"actions": [action],
|
||||
}
|
||||
|
||||
# A dummy monitor with the dummy schedule, dummy query, dummy trigger
|
||||
monitor = {
|
||||
"type": "monitor",
|
||||
"name": "test-monitor",
|
||||
"monitor_type": "query_level_monitor",
|
||||
"enabled": True,
|
||||
"schedule": schedule,
|
||||
"inputs": [{"search": {"indices": ["*"], "query": query}}],
|
||||
"triggers": [triggers],
|
||||
}
|
||||
|
||||
response = self.client.alerting.create_monitor(monitor)
|
||||
|
||||
self.assertNotIn("errors", response)
|
||||
self.assertIn("_id", response)
|
||||
self.assertIn("monitor", response)
|
||||
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_search_monitor(self):
|
||||
# Create a dummy monitor
|
||||
self.test_create_monitor()
|
||||
|
||||
# Create a monitor search query by it's name
|
||||
query = {"query": {"match": {"monitor.name": "test-monitor"}}}
|
||||
|
||||
# Perform the search with the above query
|
||||
response = self.client.alerting.search_monitor(query)
|
||||
|
||||
self.assertNotIn("errors", response)
|
||||
self.assertIn("hits", response)
|
||||
self.assertEqual(response["hits"]["total"]["value"], 1, "No monitor found.")
|
||||
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_get_monitor(self):
|
||||
# Create a dummy monitor
|
||||
self.test_create_monitor()
|
||||
|
||||
# Create a monitor search query by it's name
|
||||
query = {"query": {"match": {"monitor.name": "test-monitor"}}}
|
||||
|
||||
# Perform the search with the above query
|
||||
response = self.client.alerting.search_monitor(query)
|
||||
|
||||
# Select the first monitor
|
||||
monitor = response["hits"]["hits"][0]
|
||||
|
||||
# Fetch the monitor by id
|
||||
response = self.client.alerting.get_monitor(monitor["_id"])
|
||||
|
||||
self.assertNotIn("errors", response)
|
||||
self.assertIn("_id", response)
|
||||
self.assertIn("monitor", response)
|
||||
|
||||
@unittest.skipUnless(
|
||||
(OPENSEARCH_VERSION) and (OPENSEARCH_VERSION < (2, 0, 0)),
|
||||
"Plugin not supported for opensearch version",
|
||||
)
|
||||
def test_run_monitor(self):
|
||||
# Create a dummy monitor
|
||||
self.test_create_monitor()
|
||||
|
||||
# Create a monitor search query by it's name
|
||||
query = {"query": {"match": {"monitor.name": "test-monitor"}}}
|
||||
|
||||
# Perform the search with the above query
|
||||
response = self.client.alerting.search_monitor(query)
|
||||
|
||||
# Select the first monitor
|
||||
monitor = response["hits"]["hits"][0]
|
||||
|
||||
# Run the monitor by id
|
||||
response = self.client.alerting.run_monitor(monitor["_id"])
|
||||
|
||||
self.assertEqual(response["error"], None)
|
||||
self.assertIn("monitor_name", response)
|
||||
self.assertIn("period_start", response)
|
||||
self.assertIn("period_end", response)
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
"""
|
||||
Dynamically generated set of TestCases based on set of yaml files describing
|
||||
some integration tests. These files are shared among all official OpenSearch
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from typing import Any, AsyncGenerator, Dict, Generator
|
||||
|
||||
from opensearchpy1 import (
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from typing import Any, AsyncGenerator, Dict
|
||||
|
||||
from opensearchpy import (
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from typing import Any, Dict, Generator
|
||||
|
||||
from opensearchpy import ConnectionPool, OpenSearch, RequestsHttpConnection, Transport
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import time
|
||||
|
||||
from opensearchpy import OpenSearch
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
"""A command line tool for building and verifying releases
|
||||
Can be used for building both 'opensearchpy' and 'opensearchpyX' dists.
|
||||
Only requires 'name' in 'setup.py' and the directory to be changed.
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
"""Script which verifies that all source files have a license header.
|
||||
Has two modes: 'fix' and 'check'. 'fix' fixes problems, 'check' will
|
||||
error out if 'fix' would have changed the file.
|
||||
|
||||
Reference in New Issue
Block a user