From e5bbf378aa7fb8b90e5c8ad5bf92fc85accf0f10 Mon Sep 17 00:00:00 2001 From: WadeStern Date: Thu, 24 Apr 2025 14:36:45 -0400 Subject: [PATCH 1/2] Added action plugin for setting the adapter log level --- plugins/action/set_adapter_log_level.py | 45 ++++++++++++++++++++++++ plugins/modules/set_adapter_log_level.py | 27 ++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 plugins/action/set_adapter_log_level.py create mode 100644 plugins/modules/set_adapter_log_level.py diff --git a/plugins/action/set_adapter_log_level.py b/plugins/action/set_adapter_log_level.py new file mode 100644 index 0000000..aedbbc8 --- /dev/null +++ b/plugins/action/set_adapter_log_level.py @@ -0,0 +1,45 @@ +# Copyright 2024, Itential Inc. All Rights Reserved + +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +# Sets the logging level for a specific Itential Platform adapter. +# Parameters: +# adapter_name: Name of the adapter +# log_level: Desired log level (debug, info, warn, error) +# Example: +# - name: Set adapter logging to debug +# itential.platform.set_adapter_log_level: +# adapter_name: network-adapter +# log_level: debug + +from ansible.plugins.action import ActionBase +from ansible_collections.itential.platform.plugins.module_utils.request import make_request +from ansible.errors import AnsibleError + +class ActionModule(ActionBase): + + _supports_check_mode = False + _supports_async = False + _requires_connection = False + + def run(self, tmp=None, task_vars=None): + adapter_name = self._task.args.get("adapter_name") + log_level = self._task.args.get("log_level") + transport = self._task.args.get("transport") + + if not adapter_name or not log_level or not transport: + raise AnsibleError("adapter_name, log_level, and transport must be provided.") + + endpoint = f"/adapters/{adapter_name}/loglevel" + method = "PUT" + + data = { + "properties": { + "transport": transport, + "level": log_level + } + } + + return make_request(task_vars, method, endpoint, data=data) + diff --git a/plugins/modules/set_adapter_log_level.py b/plugins/modules/set_adapter_log_level.py new file mode 100644 index 0000000..3b5255a --- /dev/null +++ b/plugins/modules/set_adapter_log_level.py @@ -0,0 +1,27 @@ +#!/usr/bin/python + +# Copyright 2024, Itential Inc. All Rights Reserved +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = """ +--- +module: itential.platform.worker_status +author: Itential + +short_description: Get a list of active tasks from an Itential Platform system + +description: + - The M(itential.platform.worker_status) module returns a list of active + tasks from an Itential Platform system. +""" + + +EXAMPLES = """ + - name: get a list of active tasks + itential.platform.worker_status: +""" From 6e614fc6a460a5f6f277da34f3a9bb864703d43f Mon Sep 17 00:00:00 2001 From: WadeStern Date: Thu, 24 Apr 2025 14:44:40 -0400 Subject: [PATCH 2/2] Fixed documentation --- plugins/action/set_adapter_log_level.py | 12 ++++--- plugins/modules/set_adapter_log_level.py | 46 +++++++++++++++++++----- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/plugins/action/set_adapter_log_level.py b/plugins/action/set_adapter_log_level.py index aedbbc8..b0c71c2 100644 --- a/plugins/action/set_adapter_log_level.py +++ b/plugins/action/set_adapter_log_level.py @@ -4,14 +4,18 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Sets the logging level for a specific Itential Platform adapter. +# # Parameters: -# adapter_name: Name of the adapter -# log_level: Desired log level (debug, info, warn, error) -# Example: -# - name: Set adapter logging to debug +# adapter_name: Name of the adapter (e.g., "network-adapter") +# log_level: Desired log level ("debug", "info", "warn", "error") +# transport: Logging transport ("file" or "console") +# +# Example usage: +# - name: Set adapter logging to debug using file transport # itential.platform.set_adapter_log_level: # adapter_name: network-adapter # log_level: debug +# transport: file from ansible.plugins.action import ActionBase from ansible_collections.itential.platform.plugins.module_utils.request import make_request diff --git a/plugins/modules/set_adapter_log_level.py b/plugins/modules/set_adapter_log_level.py index 3b5255a..e0253bf 100644 --- a/plugins/modules/set_adapter_log_level.py +++ b/plugins/modules/set_adapter_log_level.py @@ -10,18 +10,48 @@ DOCUMENTATION = """ --- -module: itential.platform.worker_status +module: set_adapter_log_level author: Itential - -short_description: Get a list of active tasks from an Itential Platform system +short_description: Set the logging level for a specific Itential Platform adapter description: - - The M(itential.platform.worker_status) module returns a list of active - tasks from an Itential Platform system. + - The C(set_adapter_log_level) module configures the log level and transport + method (file or console) for a specific adapter running on the Itential Platform. + +options: + adapter_name: + description: + - Name of the adapter to update the logging level for. + required: true + type: str + + log_level: + description: + - Logging level to set for the adapter. + - Common values include C(debug), C(info), C(warn), C(error). + required: true + type: str + + transport: + description: + - Output transport to apply the log level to. + - Valid values are C(file) and C(console). + required: true + type: str """ - EXAMPLES = """ - - name: get a list of active tasks - itential.platform.worker_status: +- name: Set adapter logging to debug using file transport + itential.platform.set_adapter_log_level: + adapter_name: network-adapter + log_level: debug + transport: file +""" + +RETURN = """ +changed: + description: Whether the log level was successfully updated. + returned: always + type: bool + sample: true """