Skip to content
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

Alerting Plugins #93

Merged
merged 28 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b15a5e
Alert Plugin
arnavdas88 Dec 15, 2021
d827041
Merge branch 'opensearch-project:main' into main
arnavdas88 Dec 28, 2021
c76236b
lint file header license
arnavdas88 Dec 29, 2021
d95b6cd
Merge branch 'opensearch-project:main' into main
arnavdas88 Jan 5, 2022
785c5b2
Tests For Alerting[Monitors]
arnavdas88 Jan 5, 2022
7d7f6f4
Merge branch 'opensearch-project:main' into main
arnavdas88 Jan 16, 2022
0b46aa8
Tests For Alerting[Destinations]
arnavdas88 Jan 17, 2022
2ca4d59
dynamic lookup 90#issuecomment-1003396742
arnavdas88 Jan 17, 2022
3b11995
Alerting Async
arnavdas88 Jan 19, 2022
b1f4344
Merge branch 'opensearch-project:main' into main
arnavdas88 Feb 15, 2022
8db89e7
Lint Changes
arnavdas88 Apr 7, 2022
2619cae
Merge branch 'opensearch-project:main' into main
arnavdas88 May 18, 2022
7bd9e17
alerting plugins integration tests
arnavdas88 May 18, 2022
a6fc619
Merge branch 'opensearch-project:main' into main
arnavdas88 May 31, 2022
fc79fdf
Merge branch 'opensearch-project:main' into main
arnavdas88 Jun 18, 2022
e8b1a0e
Merge branch 'opensearch-project:main' into main
arnavdas88 Jul 12, 2022
0d87201
Integ UnitTests Skip on OPENSEARCH_VERSION >= 2.0.0
arnavdas88 Jul 12, 2022
e4c111b
Unit Test Skip Complete
arnavdas88 Jul 12, 2022
be47811
Merge branch 'opensearch-project:main' into main
arnavdas88 Jul 20, 2022
1a990c1
Merge branch 'opensearch-project:main' into main
arnavdas88 Sep 4, 2022
e5d23f6
License Headers fixed
arnavdas88 Sep 7, 2022
e20038c
test_urllib3_connection timeout
arnavdas88 Sep 7, 2022
43268f1
lint
arnavdas88 Sep 7, 2022
853c91c
Fix licenses in all files
harshavamsi Sep 23, 2022
1dfbbaa
Merge pull request #1 from harshavamsi/fix/license
arnavdas88 Sep 23, 2022
37dfd91
Remove elastic search licenses on new files
harshavamsi Sep 29, 2022
86c66cd
Fix formatting
harshavamsi Sep 29, 2022
9c14dae
Merge pull request #2 from harshavamsi/fix/license
arnavdas88 Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions opensearchpy/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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
Expand Down Expand Up @@ -200,6 +201,8 @@ class as kwargs, or a string in the format of ``host[:port]`` which will be

self.features = FeaturesClient(self)

self.plugins = PluginsClient(self)

def __repr__(self):
try:
# get a list of all connections
Expand Down
26 changes: 26 additions & 0 deletions opensearchpy/client/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0

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)
arnavdas88 marked this conversation as resolved.
Show resolved Hide resolved
# 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)
17 changes: 17 additions & 0 deletions opensearchpy/client/plugins.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
8 changes: 8 additions & 0 deletions opensearchpy/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions opensearchpy/plugins/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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.
200 changes: 200 additions & 0 deletions opensearchpy/plugins/alerting.py
Original file line number Diff line number Diff line change
@@ -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.
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
arnavdas88 marked this conversation as resolved.
Show resolved Hide resolved

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,
)
71 changes: 71 additions & 0 deletions opensearchpy/plugins/alerting.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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]: ...
7 changes: 7 additions & 0 deletions out/opensearchpy/client/plugins.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ..plugins.alerting import AlertingClient as AlertingClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add license header

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need license headers here.

from .utils import NamespacedClient as NamespacedClient
from typing import Any

class PluginsClient(NamespacedClient):
alerting: Any
def __init__(self, client) -> None: ...
Empty file.
16 changes: 16 additions & 0 deletions out/opensearchpy/plugins/alerting.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from ..client.utils import NamespacedClient as NamespacedClient, query_params as query_params
arnavdas88 marked this conversation as resolved.
Show resolved Hide resolved
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]: ...