diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:22 +0000 |
commit | 38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch) | |
tree | 356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/sensu/sensu_go/plugins | |
parent | Adding upstream version 7.7.0+dfsg. (diff) | |
download | ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip |
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/sensu/sensu_go/plugins')
9 files changed, 683 insertions, 14 deletions
diff --git a/ansible_collections/sensu/sensu_go/plugins/filter/backends.py b/ansible_collections/sensu/sensu_go/plugins/filter/backends.py index ecafd458f..a71f25ec5 100644 --- a/ansible_collections/sensu/sensu_go/plugins/filter/backends.py +++ b/ansible_collections/sensu/sensu_go/plugins/filter/backends.py @@ -6,6 +6,39 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +DOCUMENTATION = ''' + name: backends + author: Tadej Borovsak (@tadeboro) + version_added: 1.13.2 + short_description: Format websocket connection for backends hosts from inventory. + description: + - Socket connection format function. + - Filter backends hosts from ansible inventory groups. + - The return value is a list of websocket connection addresses. + positional: _input + options: + _input: + description: Inventory host variables (hostvars). + type: dict + required: true + groups: + description: List of ansible inventory groups. + type: list + required: true +''' + +EXAMPLES = ''' + - name: Filter backends from ansible inventory and format a list of websocket connection addresses + ansible.builtin.debug: + msg: "{{ hostvars | sensu.sensu_go.backends(groups) }}" +''' + +RETURN = ''' + _value: + description: List of websocket connection addresses. + type: list +''' + def _format_backend(vars): if "api_key_file" in vars: diff --git a/ansible_collections/sensu/sensu_go/plugins/filter/backends.yml b/ansible_collections/sensu/sensu_go/plugins/filter/backends.yml new file mode 100644 index 000000000..31d6df4bd --- /dev/null +++ b/ansible_collections/sensu/sensu_go/plugins/filter/backends.yml @@ -0,0 +1,35 @@ +--- +# -*- coding: utf-8 -*- +# Copyright: (c) 2020, XLAB Steampunk <steampunk@xlab.si> +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +DOCUMENTATION: + name: backends + author: Tadej Borovsak (@tadeboro) + version_added: 1.13.2 + short_description: Format websocket connection for backends hosts from inventory. + description: + - Socket connection format function. + - Filter backends hosts from ansible inventory groups. + - The return value is a list of websocket connection addresses. + positional: _input + options: + _input: + description: Inventory host variables (hostvars). + type: dict + required: true + groups: + description: List of ansible inventory groups. + type: list + required: true + +EXAMPLES: | + - name: Filter backends from ansible inventory and format a list of websocket connection addresses + ansible.builtin.debug: + msg: "{{ hostvars | sensu.sensu_go.backends(groups) }}" + +RETURN: + _value: + description: List of websocket connection addresses. + type: list diff --git a/ansible_collections/sensu/sensu_go/plugins/filter/package_name.py b/ansible_collections/sensu/sensu_go/plugins/filter/package_name.py index 80e9a8750..ae48218c4 100644 --- a/ansible_collections/sensu/sensu_go/plugins/filter/package_name.py +++ b/ansible_collections/sensu/sensu_go/plugins/filter/package_name.py @@ -6,6 +6,51 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +DOCUMENTATION = ''' + name: package_name + author: Tadej Borovsak (@tadeboro) + version_added: 1.13.2 + short_description: Format package name + description: + - Package name format function. + - The return value is a string respresenting package name and build version. + positional: _input + options: + _input: + description: Package type. + choices: [ apt, yum ] + type: string + required: true + name: + description: Package name. + type: string + required: true + version: + description: Package version. + type: string + required: true + build: + description: Package build. + type: string + required: true +''' + +EXAMPLES = ''' + - name: Install apt component + apt: + name: "{{ 'apt' | sensu.sensu_go.package_name(name, version, build) }}" + + - name: Install yum component + yum: + name: "{{ 'yum' | sensu.sensu_go.package_name(name, version, build) }}" +''' + +RETURN = ''' + _value: + description: Package name, version and build as a formatted string. + type: string +''' + def _apt_package_name(name, version, build): if version == "latest": diff --git a/ansible_collections/sensu/sensu_go/plugins/filter/package_name.yml b/ansible_collections/sensu/sensu_go/plugins/filter/package_name.yml new file mode 100644 index 000000000..d23038de4 --- /dev/null +++ b/ansible_collections/sensu/sensu_go/plugins/filter/package_name.yml @@ -0,0 +1,47 @@ +--- +# -*- coding: utf-8 -*- +# Copyright: (c) 2020, XLAB Steampunk <steampunk@xlab.si> +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +DOCUMENTATION: + name: package_name + author: Tadej Borovsak (@tadeboro) + version_added: 1.13.2 + short_description: Format package name + description: + - Package name format function. + - The return value is a string respresenting package name and build version. + positional: _input + options: + _input: + description: Package type. + choices: [ apt, yum ] + type: string + required: true + name: + description: Package name. + type: string + required: true + version: + description: Package version. + type: string + required: true + build: + description: Package build. + type: string + required: true + +EXAMPLES: | + - name: Install apt component + apt: + name: "{{ 'apt' | sensu.sensu_go.package_name(name, version, build) }}" + + - name: Install yum component + yum: + name: "{{ 'yum' | sensu.sensu_go.package_name(name, version, build) }}" + +RETURN: + _value: + description: Package name, version and build as a formatted string. + type: string diff --git a/ansible_collections/sensu/sensu_go/plugins/module_utils/errors.py b/ansible_collections/sensu/sensu_go/plugins/module_utils/errors.py index 5be0675c7..931a3a39b 100644 --- a/ansible_collections/sensu/sensu_go/plugins/module_utils/errors.py +++ b/ansible_collections/sensu/sensu_go/plugins/module_utils/errors.py @@ -23,5 +23,9 @@ class SensuError(Error): """ Error that signals problems with Sensu Go web API. """ +class RequirementsError(Error): + """ Error that signals problems with missing requirements. """ + + class BonsaiError(Error): """ Error that signals problems with Bonsai assets. """ diff --git a/ansible_collections/sensu/sensu_go/plugins/modules/datastore.py b/ansible_collections/sensu/sensu_go/plugins/modules/datastore.py index 706f3d1d8..9df339021 100644 --- a/ansible_collections/sensu/sensu_go/plugins/modules/datastore.py +++ b/ansible_collections/sensu/sensu_go/plugins/modules/datastore.py @@ -43,6 +43,48 @@ options: - The maximum number of connections to hold in the PostgreSQL connection pool. type: int + max_conn_lifetime: + description: + - Maximum time a connection can persist before being destroyed. + type: str + max_idle_conns: + description: + - Maximum number of number of idle connections to retain. + type: int + default: 2 + batch_workers: + description: + - Number of Goroutines sending data to PostgreSQL, as specified in the PostgreSQL configuration. + - Set to current PostgreSQL pool size as default. + type: int + batch_buffer: + description: + - Maximum number of requests to buffer in memory. + type: int + default: 0 + batch_size: + description: + - Number of requests in each PostgreSQL write transaction, as specified in the PostgreSQL configuration. + type: int + default: 1 + enable_round_robin: + description: + - Enables round robin scheduling on PostgreSQL. + - Any existing round robin scheduling will stop and migrate to PostgreSQL as entities check in with keepalives. + - Sensu will gradually delete the existing etcd scheduler state as keepalives on the etcd scheduler keys expire over time. + type: bool + default: false + strict: + description: + - When the PostgresConfig resource is created, configuration validation will include connecting to the PostgreSQL database + and executing a query to confirm whether the connected user has permission to create database tables. + - Sensu-backend will try to connect to PostgreSQL indefinitely at 5-second intervals instead of reverting to etcd after 3 attempts. + - We recommend setting strict to true in most cases. If the connection fails or the user does not have permission to + create database tables, resource configuration will fail and the configuration will not be persisted. + This extended configuration is useful for debugging when you are not sure whether the configuration + is correct or the database is working properly. + type: bool + default: false notes: - Currently, only one external datastore can be active at a time. The module will fail to perform its operation if this would break that invariant. @@ -58,6 +100,13 @@ EXAMPLES = ''' sensu.sensu_go.datastore: name: my-postgres state: absent + +- name: Add external datastore with pool_size and max_conn_lifetime specified + sensu.sensu_go.datastore: + name: my-postgres + dsn: postgresql://user:secret@host:port/dbname + pool_size: 1 + max_conn_lifetime: "5m30s" ''' RETURN = ''' @@ -140,10 +189,36 @@ def main(): dsn=dict(), pool_size=dict( type="int", - ) + default=0, + ), + max_conn_lifetime=dict( + type="str", + ), + max_idle_conns=dict( + type="int", + default=2, + ), + batch_workers=dict( + type="int", + ), + batch_buffer=dict( + type="int", + default=0, + ), + batch_size=dict( + type="int", + default=1, + ), + enable_round_robin=dict( + type="bool", + default=False, + ), + strict=dict( + type="bool", + default=False, + ), ), ) - client = arguments.get_sensu_client(module.params["auth"]) list_path = utils.build_url_path(API_GROUP, API_VERSION, None, "provider") resource_path = utils.build_url_path( @@ -153,9 +228,9 @@ def main(): type="PostgresConfig", api_version=API_VERSION, metadata=dict(name=module.params["name"]), - spec=arguments.get_spec_payload(module.params, "dsn", "pool_size"), + spec=arguments.get_spec_payload(module.params, "dsn", "pool_size", "max_conn_lifetime", "max_idle_conns", "batch_workers", + "batch_buffer", "batch_size", "enable_round_robin", "strict"), ) - try: changed, datastore = sync( module.params["state"], client, list_path, resource_path, payload, diff --git a/ansible_collections/sensu/sensu_go/plugins/modules/pipeline.py b/ansible_collections/sensu/sensu_go/plugins/modules/pipeline.py new file mode 100644 index 000000000..21f30ca53 --- /dev/null +++ b/ansible_collections/sensu/sensu_go/plugins/modules/pipeline.py @@ -0,0 +1,317 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2019, XLAB Steampunk <steampunk@xlab.si> +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = { + "metadata_version": "1.1", + "status": ["stableinterface"], + "supported_by": "certified", +} +API_VERSION = dict(v1="pipeline/v1", v2="core/v2") +HANDLER_TYPE = dict(handler="Handler", tcp_stream_handler="TCPStreamHandler", sumo_logic_metrics_handler="SumoLogicMetricsHandler") +MUTATOR_TYPE = dict(mutator="Mutator") +FILTER_TYPE = dict(event_filter="EventFilter") + +DOCUMENTATION = ''' +module: pipeline +author: + - Domen Dobnikar (@domen_dobnikar) +short_description: Manage Sensu pipeline +description: + - Create, update or delete a Sensu pipeline. + - For more information, refer to the Sensu documentation at + U(https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/pipelines/). +version_added: 1.14.0 +extends_documentation_fragment: + - sensu.sensu_go.auth + - sensu.sensu_go.name + - sensu.sensu_go.namespace + - sensu.sensu_go.state + - sensu.sensu_go.labels +seealso: + - module: sensu.sensu_go.socket_handler + - module: sensu.sensu_go.handler_info + - module: sensu.sensu_go.pipe_handler + - module: sensu.sensu_go.filter + - module: sensu.sensu_go.filter_info + - module: sensu.sensu_go.mutator + - module: sensu.sensu_go.mutator_info +options: + workflows: + description: + - Array of workflows (by names) to use when filtering, mutating, and handling observability events with a pipeline. + type: list + elements: dict + suboptions: + name: + description: + - Name of the Sensu pipeline workflow. + type: str + required: true + filters: + description: + - Reference for the Sensu event filters to use when filtering events for the pipeline. + - Each pipeline workflow can reference more than one event filter. + - If a workflow has more than one filter, Sensu applies the filters in a series, starting with the filter that is listed first. + type: list + elements: dict + suboptions: + name: + description: + - Name of the Sensu event filter to use for the workflow. + - You can use the built-in event filters, as well as your existing event filters, in pipeline workflows. + type: str + required: true + type: + description: + - The sensuctl create resource type for the event filter. + - Event filters should always be type EventFilter. + type: str + default: event_filter + choices: [ event_filter ] + mutator: + description: + - Reference for the Sensu mutator to use to mutate event data for the workflow. + - Each pipeline workflow can reference only one mutator. + type: dict + suboptions: + name: + description: + - Name of the Sensu mutator to use for the workflow. + - You can use your existing mutators in pipeline workflows. + type: str + required: true + type: + description: + - The sensuctl create resource type for the mutator. + - Mutators should always be type Mutator. + type: str + default: mutator + choices: [ mutator ] + handler: + description: + - Reference for the Sensu handler to use for event processing in the workflow. + - Each pipeline workflow must reference one handler. + - Pipelines ignore any filters and mutators specified in handler definitions. + type: dict + required: true + suboptions: + name: + description: + - Name of the Sensu handler to use for the workflow. + - You can use your existing handlers in pipeline workflows. + - Pipelines ignore any filters and mutators specified in handler definitions. + type: str + required: true + type: + description: + - The sensuctl create resource type for the handler. + type: str + required: true + choices: [ handler, tcp_stream_handler, sumo_logic_metrics_handler ] +''' + +EXAMPLES = ''' +- name: Create a pipeline + sensu.sensu_go.pipeline: + name: this_pipeline + workflows: + - name: this-wf + handler: + name: this_handler + type: tcp_stream_handler + filters: + - name: this_filter + - name: this_filter_2 + mutator: + name: this_mutator + +- name: Delete pipeline + sensu.sensu_go.pipeline: + name: this_pipeline + state: absent +''' + +RETURN = ''' +object: + description: Object representing Sensu pipeline. + returned: success + type: dict + sample: + metadata: + created_by: admin + name: this_pipeline + namespace: default + workflows: + - filters: + - api_version: core/v2 + name: this_filter + type: EventFilter + - api_version: core/v2 + name: this_filter_2 + type: EventFilter + handler: + api_version: pipeline/v1 + name: this_handler + type: TCPStreamHandler + mutator: + api_version: core/v2 + name: this_mutator + type: Mutator + name: this-wf +''' + +from ansible.module_utils.basic import AnsibleModule + +from ..module_utils import arguments, errors, utils + + +def do_differ(current, desired): + return ( + utils.do_differ(current, desired, "pipelines") + ) + + +def handle_mutator_api_and_type(payload_mutator): + payload_mutator["type"] = MUTATOR_TYPE[payload_mutator["type"]] + payload_mutator["api_version"] = API_VERSION["v2"] + + +def handle_filter_api_and_type(payload_filters, workflow): + filter_count = 0 + for filter in workflow["filters"]: + payload_filters[filter_count]["type"] = FILTER_TYPE[filter["type"]] + payload_filters[filter_count]["api_version"] = API_VERSION["v2"] + filter_count += 1 + + +def handle_handler_api_and_type(payload_handler): + if payload_handler["type"] in ["tcp_stream_handler", "sumo_logic_metrics_handler"]: + payload_handler["api_version"] = API_VERSION["v1"] + else: + payload_handler["api_version"] = API_VERSION["v2"] + payload_handler["type"] = HANDLER_TYPE[payload_handler["type"]] + + +def handle_api_version_and_types(module, payload): + payload_count = 0 + for workflow in module.params["workflows"]: + # HANDLER + handle_handler_api_and_type(payload["workflows"][payload_count]["handler"]) + + # MUTATOR + if workflow.get("mutator"): + handle_mutator_api_and_type(payload["workflows"][payload_count]["mutator"]) + elif "mutator" in payload["workflows"][payload_count]: + payload["workflows"][payload_count].pop("mutator") + + # FILTERS + if workflow.get("filters"): + handle_filter_api_and_type( + payload["workflows"][payload_count]["filters"], workflow) + elif "filters" in payload["workflows"][payload_count]: + payload["workflows"][payload_count].pop("filters") + payload_count += 1 + + +def main(): + required_if = [ + ('state', 'present', ['workflows']) + ] + module = AnsibleModule( + required_if=required_if, + supports_check_mode=True, + argument_spec=dict( + arguments.get_spec( + "auth", "name", "state", "namespace", "labels", + ), + workflows=dict( + type="list", + elements="dict", + options=dict( + name=dict( + type="str", + required=True, + ), + filters=dict( + type="list", + elements="dict", + options=dict( + name=dict( + type="str", + required=True, + ), + type=dict( + type="str", + default="event_filter", + choices=[ + "event_filter", + ], + ), + ), + ), + mutator=dict( + type="dict", + options=dict( + name=dict( + type="str", + required=True, + ), + type=dict( + type="str", + default="mutator", + choices=[ + "mutator", + ], + ), + ), + ), + handler=dict( + type="dict", + required=True, + options=dict( + name=dict( + type="str", + required=True, + ), + type=dict( + type="str", + required=True, + choices=[ + "handler", + "tcp_stream_handler", + "sumo_logic_metrics_handler" + ], + ), + ), + ), + ), + ), + ), + ) + client = arguments.get_sensu_client(module.params['auth']) + path = utils.build_core_v2_path( + module.params['namespace'], 'pipelines', module.params['name'], + ) + payload = arguments.get_mutation_payload( + module.params, 'workflows' + ) + if module.params["state"] == "present": + handle_api_version_and_types(module, payload) + try: + changed, handler = utils.sync( + module.params['state'], client, path, payload, module.check_mode, + do_differ, + ) + module.exit_json(changed=changed, object=handler) + except errors.Error as e: + module.fail_json(msg=str(e)) + + +if __name__ == '__main__': + main() diff --git a/ansible_collections/sensu/sensu_go/plugins/modules/pipeline_info.py b/ansible_collections/sensu/sensu_go/plugins/modules/pipeline_info.py new file mode 100644 index 000000000..f67998ff6 --- /dev/null +++ b/ansible_collections/sensu/sensu_go/plugins/modules/pipeline_info.py @@ -0,0 +1,118 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright: (c) 2019, XLAB Steampunk <steampunk@xlab.si> +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +ANSIBLE_METADATA = { + "metadata_version": "1.1", + "status": ["stableinterface"], + "supported_by": "certified", +} + +DOCUMENTATION = ''' +module: pipeline_info +author: + - Domen Dobnikar (@domen_dobnikar) +short_description: List available Sensu pipelines. +description: + - Retrieve information about Sensu Go pipelines. + - For more information, refer to the Sensu documentation at + U(https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/pipelines/). +version_added: 1.14.0 +extends_documentation_fragment: + - sensu.sensu_go.requirements + - sensu.sensu_go.auth + - sensu.sensu_go.namespace + +seealso: + - module: sensu.sensu_go.socket_handler + - module: sensu.sensu_go.handler_info + - module: sensu.sensu_go.pipe_handler + - module: sensu.sensu_go.filter + - module: sensu.sensu_go.filter_info + - module: sensu.sensu_go.mutator + - module: sensu.sensu_go.mutator_info +options: + name: + description: + - Name of a specific pipeline. + type: str +''' + +EXAMPLES = ''' +- name: List all Sensu pipelines + sensu.sensu_go.pipeline_info: + register: result + +- name: List the selected Sensu pipeline + sensu.sensu_go.pipeline_info: + name: my_pipeline + register: result +''' + +RETURN = """ +objects: + description: List of Sensu pipelines. + returned: success + type: list + elements: dict + sample: + - metadata: + created_by: admin + name: this_pipeline + namespace: default + workflows: null + - metadata: + created_by: admin + name: this_pipeline_1 + namespace: default + workflows: + - handler: + api_version: core/v2 + name: best_handler_1 + type: Handler + name: best_workflow_1 + - metadata: + created_by: admin + name: this_pipeline_2 + namespace: default + workflows: + - handler: + api_version: core/v2 + name: best_handler_2 + type: Handler + name: best_workflow_1 +""" + +from ansible.module_utils.basic import AnsibleModule + +from ..module_utils import arguments, errors, utils + + +def main(): + module = AnsibleModule( + supports_check_mode=True, + argument_spec=dict( + arguments.get_spec("auth", "namespace"), + name=dict(), # Name is not required in info modules. + ), + ) + + client = arguments.get_sensu_client(module.params["auth"]) + path = utils.build_core_v2_path( + module.params["namespace"], "pipelines", module.params["name"], + ) + try: + handlers = utils.prepare_result_list(utils.get(client, path)) + except errors.Error as e: + module.fail_json(msg=str(e)) + + module.exit_json(changed=False, objects=handlers) + + +if __name__ == '__main__': + main() diff --git a/ansible_collections/sensu/sensu_go/plugins/modules/user.py b/ansible_collections/sensu/sensu_go/plugins/modules/user.py index 4ef155867..44c2a4f38 100644 --- a/ansible_collections/sensu/sensu_go/plugins/modules/user.py +++ b/ansible_collections/sensu/sensu_go/plugins/modules/user.py @@ -147,7 +147,11 @@ def update_password(client, path, username, password, check_mode): username=username, password=password, )) else: - hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) + # Raise exception if BCRYPT library is not present on host. + if HAS_BCRYPT: + hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) + else: + raise errors.RequirementsError(missing_required_lib('bcrypt')) utils.put(client, path + '/reset_password', dict( username=username, password_hash=hash.decode('ascii'), )) @@ -285,15 +289,6 @@ def main(): path = utils.build_core_v2_path(None, 'users', module.params['name']) try: - if not HAS_BCRYPT and client.version >= "5.21.0": - module.fail_json( - msg=missing_required_lib('bcrypt'), - exception=BCRYPT_IMPORT_ERROR, - ) - except errors.SensuError as e: - module.fail_json(msg=str(e)) - - try: remote_object = utils.get(client, path) except errors.Error as e: module.fail_json(msg=str(e)) |