@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2017, Thierry Sallé (@tsalle)
# Copyright : (c) 2017, Thierry Sallé (@tsalle)
# 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
@ -16,171 +16,152 @@ DOCUMENTATION = '''
- - -
module : grafana_datasource
author :
- " Thierry Sallé (@tsalle) "
- Thierry Sallé ( @tsalle )
version_added : " 2.5 "
short_description : Manage g rafana datasources
short_description : Manage G rafana datasources
description :
- Create / update / delete g rafana datasources via API
- Create / update / delete G rafana datasources via API .
options :
grafana_url :
required : true
description :
- Grafana url
name :
- The Grafana URL .
required : true
name :
description :
- Name of the datasource
ds_type :
- The name of the datasource .
required : true
choices : [ graphite , prometheus , elasticsearch , influxdb , opentsdb , mysql , postgres ]
ds_type :
description :
- Type of the datasource
url :
- The type of the datasource .
required : true
choices : [ elasticsearch , graphite , influxdb , mysql , opentsdb , postgres , prometheus ]
url :
description :
- Url of the datasource
- The URL of the datasource .
required : true
access :
required : false
default : proxy
choices : [ proxy , direct ]
description :
- Access mode for this datasource
- The access mode for this datasource .
choices : [ direct , proxy ]
default : proxy
grafana_user :
required : false
default : admin
description :
- Grafana API user
grafana_password :
required : false
- The Grafana API user .
default : admin
grafana_password :
description :
- Grafana API password
- The Grafana API password .
default : admin
grafana_api_key :
required : false
description :
- Grafana API key
- If set , grafana_user and grafana_password will be ignored
- The Grafana API key .
- If set , C( grafana_user) and C( grafana_password) will be ignored .
database :
required : false
description :
- Name of the database for the datasource .
- This options is required when the ds_type is influxdb , elasticsearch ( index name ) , mysql or postgres
user :
- This options is required when the C ( ds_type ) is C ( influxdb ) , C ( elasticsearch ) ( index name ) , C ( mysql ) or C ( postgres ) .
required : false
user :
description :
- D atasource login user for influxdb datasources
- The d atasource login user for influxdb datasources .
password :
required : false
description :
- D atasource password
- The d atasource password
basic_auth_user :
required : false
description :
- D atasource basic auth user .
- The d atasource basic auth user .
- Setting this option with basic_auth_password will enable basic auth .
basic_auth_password :
required : false
description :
- Datasource basic auth password , when basic auth is true
- The datasource basic auth password , when C ( basic auth ) is C ( yes ) .
with_credentials :
required : false
default : false
description :
- Whether credentials such as cookies or auth headers should be sent with cross - site requests .
type : bool
default : ' no '
tls_client_cert :
required : false
description :
- client tls certificate .
- If tls_client_cert and tls_client_key are set , this will enable tls auth .
- begin s with - - - - - BEGIN CERTIFICATE - - - - -
- The client TLS certificate .
- If C( tls_client_cert) and C( tls_client_key) are set , this will enable TLS authentication .
- Start s with - - - - - BEGIN CERTIFICATE - - - - -
tls_client_key :
required : false
description :
- client tls private key
- befin s with - - - - - BEGIN RSA PRIVATE KEY - - - - -
- The client TLS private key
- Start s with - - - - - BEGIN RSA PRIVATE KEY - - - - -
tls_ca_cert :
required : false
description :
- tls ca certificate for self signed certificates .
- only used when tls_client_cert and tls_client_key are set
- The TLS CA certificate for self signed certificates .
- Only used when C ( tls_client_cert ) and C ( tls_client_key ) are set .
is_default :
required : false
default : false
description :
- Make this datasource the default one
- Make this datasource the default one .
type : bool
default : ' no '
org_id :
required : false
description :
- Grafana Organisation ID in which the datasource should be created
- Not used when grafana_api_key is set , because the grafana_api_key only belong to one organisation .
- Grafana Organisation ID in which the datasource should be created .
- Not used when C( grafana_api_key) is set , because the C( grafana_api_key) only belong to one organisation .
default : 1
state :
required : false
default : present
choices : [ present , absent ]
description :
- Status of the datasource
choices : [ absent , present ]
default : present
es_version :
required : false
default : 5
choices : [ 2 , 5 , 56 ]
description :
- Elasticsearch version ( for ds_type = elasticsearch only )
- Version 56 is for elasticsearch 5.6 + where tou can specify the max_concurrent_shard_requests option .
- Elasticsearch version ( for C ( ds_type = elasticsearch ) only )
- Version 56 is for elasticsearch 5.6 + where tou can specify the C ( max_concurrent_shard_requests ) option .
choices : [ 2 , 5 , 56 ]
default : 5
max_concurrent_shard_requests :
required : false
default : 256
description :
- Starting with elasticsearch 5.6 , you can specify the max concurrent shard per requests .
default : 256
time_field :
required : false
default : timestamp
description :
- Name of the time field in elasticsearch ds
- Name of the time field in elasticsearch ds .
- For example C ( @timestamp )
default : timestamp
time_interval :
required : false
description :
- Minimum group by interval for influxdb or elasticsearch datasources
- for example ' >10s '
- Minimum group by interval for C( influxdb) or C( elasticsearch) datasources .
- for example C ( > 10 s )
interval :
required : false
choices : [ ' ' , ' Hourly ' , ' Daily ' , ' Weekly ' , ' Monthly ' , ' Yearly ' ]
description :
- for elasticsearch ds_type , this is the index pattern used .
- For elasticsearch C ( ds_type ) , this is the index pattern used .
choices : [ ' ' , ' Hourly ' , ' Daily ' , ' Weekly ' , ' Monthly ' , ' Yearly ' ]
tsdb_version :
required : false
choices : [ 1 , 2 , 3 ]
description :
- opentsdb version ( 1 for < = 2.1 , 2 for == 2.2 , 3 for == 2.3 )
- The opentsdb version .
- Use C ( 1 ) for < = 2.1 , C ( 2 ) for == 2.2 , C ( 3 ) for == 2.3 .
choices : [ 1 , 2 , 3 ]
default : 1
tsdb_resolution :
required : false
choices : [ second , millisecond ]
description :
- opentsdb time resolution
default : 1
- The opentsdb time resolution .
choices : [ millisecond , second ]
default : second
sslmode :
choices : [ ' disable ' , ' require ' , ' verify-ca ' , ' verify-full ' ]
description :
- SSL mode for postgres datasoure type .
- SSL mode for C ( postgres ) datasoure type .
choices : [ disable , require , verify - ca , verify - full ]
validate_certs :
required : false
default : True
description :
- Validate or not grafana certificate
- Whether to validate the Grafana certificate .
type : bool
default : ' yes '
'''
EXAMPLES = '''
- - -
- name : c reate elasticsearch datasource
- name : C reate elasticsearch datasource
grafana_datasource :
name : my_elastic
grafana_url : http : / / grafana . company . com
type : elasticsearch
url : https : / / elasticsearch . company . com : 9200
database : my - index_ *
basic_auth : true
basic_auth : yes
basic_auth_user : grafana
basic_auth_password : xxxxxxxx
json_data : ' { " esVersion " :5, " timeField " : " @timestamp " } '