
    Vh
                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZ  G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionu.  
module: influxdb_query
short_description: Query data points from InfluxDB
description:
  - Query data points from InfluxDB.
author: "René Moser (@resmo)"
requirements:
  - "influxdb >= 0.9"
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  query:
    description:
      - Query to be executed.
    required: true
    type: str
  database_name:
    description:
      - Name of the database.
    required: true
    type: str
extends_documentation_fragment:
  - community.general.influxdb
  - community.general.attributes
ab  
- name: Query connections
  community.general.influxdb_query:
    hostname: "{{ influxdb_ip_address }}"
    database_name: "{{ influxdb_database_name }}"
    query: "select mean(value) from connections"
  register: connection

- name: Query connections with tags filters
  community.general.influxdb_query:
    hostname: "{{ influxdb_ip_address }}"
    database_name: "{{ influxdb_database_name }}"
    query: "select mean(value) from connections where region='zue01' and host='server01'"
  register: connection

- name: Print results from the query
  ansible.builtin.debug:
    var: connection.query_results
z
query_results:
  description: Result from the query.
  returned: success
  type: list
  sample:
    - mean: 1245.5333333333333
      time: "1970-01-01T00:00:00Z"
)AnsibleModule)	to_native)InfluxDbc                       e Zd Zd Zy)AnsibleInfluxDBReadc                     | j                         }	 |j                  |      }|rt        |j                               S y # t        $ r/}| j
                  j                  t        |             Y d }~y d }~ww xY w)N)msg)connect_to_influxdbquerylist
get_points	Exceptionmodule	fail_jsonr   )selfr   clientrses        t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/influxdb_query.pyread_by_queryz!AnsibleInfluxDBRead.read_by_queryM   sh    ))+	4e$BBMMO,,  	4KK!!il!33	4s   +? 	A7%A22A7N)__name__
__module____qualname__r        r   r
   r
   K   s    4r   r
   c                  ,   t        j                         } | j                  t        dd      t        dd             t	        | d      }t        |      }|j                  j                  d      }|j                  |      }|j                  d|       y )	NstrT)typerequired)r"   r!   )r   database_name)argument_specsupports_check_moder   )changedquery_results)
r   influxdb_argument_specupdatedictr   r
   paramsgetr   	exit_json)r$   r   influxr   resultss        r   mainr0   W   s    335M-Du5   # F
 !(FMMg&E""5)G
T9r   __main__N)
__future__r   r   r   r!   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   Cansible_collections.community.general.plugins.module_utils.influxdbr   r
   r0   r   r   r   r   <module>r:      sX    A @:(
 5 A X	4( 	4:" zF r   