Skip to content

Commit

Permalink
Merge branch 'main' into auto-bump-grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
rndmh3ro authored Jan 4, 2024
2 parents f503e81 + 0aedf86 commit f3fdc80
Show file tree
Hide file tree
Showing 86 changed files with 3,900 additions and 3,119 deletions.
13 changes: 12 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@
"code",
"test"
]
},
{
"login": "Nemental",
"name": "Moritz",
"avatar_url": "https://avatars.githubusercontent.com/u/15136847?v=4",
"profile": "https://nemental.de",
"contributions": [
"bug",
"code"
]
}
],
"contributorsPerLine": 7,
Expand All @@ -195,5 +205,6 @@
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular"
"commitConvention": "angular",
"commitType": "docs"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
__pycache__/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](https://github.com/ansible-collections/grafana/workflows/CI/badge.svg?branch=master)
[![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/community.grafana)](https://codecov.io/gh/ansible-collections/community.grafana)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

This repo hosts the `community.grafana` Ansible Collection.
Expand Down Expand Up @@ -253,6 +253,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/prndrbr"><img src="https://avatars.githubusercontent.com/u/96344856?v=4?s=100" width="100px;" alt="Pierre"/><br /><sub><b>Pierre</b></sub></a><br /><a href="https://github.com/ansible-collections/community.grafana/issues?q=author%3Aprndrbr" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/miksonx"><img src="https://avatars.githubusercontent.com/u/5308184?v=4?s=100" width="100px;" alt="MiksonX"/><br /><sub><b>MiksonX</b></sub></a><br /><a href="https://github.com/ansible-collections/community.grafana/issues?q=author%3Amiksonx" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/amenzhinsky"><img src="https://avatars.githubusercontent.com/u/1308953?v=4?s=100" width="100px;" alt="Aliaksandr Mianzhynski"/><br /><sub><b>Aliaksandr Mianzhynski</b></sub></a><br /><a href="https://github.com/ansible-collections/community.grafana/commits?author=amenzhinsky" title="Code">💻</a> <a href="https://github.com/ansible-collections/community.grafana/commits?author=amenzhinsky" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://nemental.de"><img src="https://avatars.githubusercontent.com/u/15136847?v=4?s=100" width="100px;" alt="Moritz"/><br /><sub><b>Moritz</b></sub></a><br /><a href="https://github.com/ansible-collections/community.grafana/issues?q=author%3ANemental" title="Bug reports">🐛</a> <a href="https://github.com/ansible-collections/community.grafana/commits?author=Nemental" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/324_formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- Format with black, remove unused variables
2 changes: 2 additions & 0 deletions changelogs/fragments/325_linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- fix linting with ansible-lint write.
2 changes: 2 additions & 0 deletions changelogs/fragments/325_true_false.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- default to true/false in docs and code
8 changes: 8 additions & 0 deletions changelogs/fragments/331-dashboard-by-org-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

minor_changes:
- Add parameter `org_name` to `grafana_dashboard`

trivial:
- Add tests for new `grafana_dashboard`-parameter `org_name`
- Refactor tests for `grafana_dashboard`
4 changes: 4 additions & 0 deletions changelogs/fragments/332-datasource-by-org-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

minor_changes:
- Add parameter `org_name` to `grafana_datasource`
2 changes: 2 additions & 0 deletions changelogs/fragments/335-add-datasource-type-tempo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Add support for Grafana Tempo datasource type (https://grafana.com/docs/grafana/latest/datasources/tempo/)
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
namespace: community
name: grafana
version: 1.6.1
Expand Down
7 changes: 5 additions & 2 deletions hacking/find_grafana_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
def get_by_major(version):
if version.startswith("v"):
version = version[1:]
return (version[0], version, int(version.replace('.', '')))
return (version[0], version, int(version.replace(".", "")))


def get_grafana_releases():
r = requests.get('https://api.github.com/repos/grafana/grafana/releases?per_page=50', headers={"Accept": "application/vnd.github.v3+json"})
r = requests.get(
"https://api.github.com/repos/grafana/grafana/releases?per_page=50",
headers={"Accept": "application/vnd.github.v3+json"},
)
if r.status_code != 200:
raise Exception("Failed to get releases from GitHub")
return r.json()
Expand Down
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
requires_ansible: '>=2.9.0'
requires_ansible: ">=2.9.0"
action_groups:
grafana:
- grafana_dashboard
Expand Down
119 changes: 70 additions & 49 deletions plugins/callback/grafana_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = '''
DOCUMENTATION = """
name: grafana_annotations
type: notification
short_description: send ansible events as annotations on charts to grafana over http api.
Expand All @@ -29,7 +30,7 @@
options:
grafana_url:
description: Grafana annotations api URL
required: True
required: true
env:
- name: GRAFANA_URL
ini:
Expand All @@ -45,7 +46,7 @@
key: validate_grafana_certs
- section: callback_grafana_annotations
key: validate_certs
default: True
default: true
type: bool
aliases: [ validate_grafana_certs ]
http_agent:
Expand Down Expand Up @@ -104,7 +105,7 @@
default: []
type: list
elements: integer
'''
"""

import json
import socket
Expand Down Expand Up @@ -148,7 +149,7 @@


def to_millis(dt):
return int(dt.strftime('%s')) * 1000
return int(dt.strftime("%s")) * 1000


class CallbackModule(CallbackBase):
Expand All @@ -161,15 +162,15 @@ class CallbackModule(CallbackBase):
"""

CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'aggregate'
CALLBACK_NAME = 'community.grafana.grafana_annotations'
CALLBACK_TYPE = "aggregate"
CALLBACK_NAME = "community.grafana.grafana_annotations"
CALLBACK_NEEDS_WHITELIST = True

def __init__(self, display=None):

super(CallbackModule, self).__init__(display=display)

self.headers = {'Content-Type': 'application/json'}
self.headers = {"Content-Type": "application/json"}
self.force_basic_auth = False
self.hostname = socket.gethostname()
self.username = getpass.getuser()
Expand All @@ -178,37 +179,42 @@ def __init__(self, display=None):

def set_options(self, task_keys=None, var_options=None, direct=None):

super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
super(CallbackModule, self).set_options(
task_keys=task_keys, var_options=var_options, direct=direct
)

self.grafana_api_key = self.get_option('grafana_api_key')
self.grafana_url = self.get_option('grafana_url')
self.validate_grafana_certs = self.get_option('validate_certs')
self.http_agent = self.get_option('http_agent')
self.grafana_user = self.get_option('grafana_user')
self.grafana_password = self.get_option('grafana_password')
self.dashboard_id = self.get_option('grafana_dashboard_id')
self.panel_ids = self.get_option('grafana_panel_ids')
self.grafana_api_key = self.get_option("grafana_api_key")
self.grafana_url = self.get_option("grafana_url")
self.validate_grafana_certs = self.get_option("validate_certs")
self.http_agent = self.get_option("http_agent")
self.grafana_user = self.get_option("grafana_user")
self.grafana_password = self.get_option("grafana_password")
self.dashboard_id = self.get_option("grafana_dashboard_id")
self.panel_ids = self.get_option("grafana_panel_ids")

if self.grafana_api_key:
self.headers['Authorization'] = "Bearer %s" % self.grafana_api_key
self.headers["Authorization"] = "Bearer %s" % self.grafana_api_key
else:
self.force_basic_auth = True

if self.grafana_url is None:
self.disabled = True
self._display.warning('Grafana URL was not provided. The '
'Grafana URL can be provided using '
'the `GRAFANA_URL` environment variable.')
self._display.debug('Grafana URL: %s' % self.grafana_url)
self._display.warning(
"Grafana URL was not provided. The "
"Grafana URL can be provided using "
"the `GRAFANA_URL` environment variable."
)
self._display.debug("Grafana URL: %s" % self.grafana_url)

def v2_playbook_on_start(self, playbook):
self.playbook = playbook._file_name
text = PLAYBOOK_START_TXT.format(playbook=self.playbook, hostname=self.hostname,
username=self.username)
text = PLAYBOOK_START_TXT.format(
playbook=self.playbook, hostname=self.hostname, username=self.username
)
data = {
'time': to_millis(self.start_time),
'text': text,
'tags': ['ansible', 'ansible_event_start', self.playbook, self.hostname]
"time": to_millis(self.start_time),
"text": text,
"tags": ["ansible", "ansible_event_start", self.playbook, self.hostname],
}
self._send_annotation(data)

Expand All @@ -223,30 +229,39 @@ def v2_playbook_on_stats(self, stats):
if self.errors == 0:
status = "OK"

text = PLAYBOOK_STATS_TXT.format(playbook=self.playbook, hostname=self.hostname,
duration=duration.total_seconds(),
status=status, username=self.username,
summary=json.dumps(summarize_stat))
text = PLAYBOOK_STATS_TXT.format(
playbook=self.playbook,
hostname=self.hostname,
duration=duration.total_seconds(),
status=status,
username=self.username,
summary=json.dumps(summarize_stat),
)

data = {
'time': to_millis(self.start_time),
'timeEnd': to_millis(end_time),
'isRegion': True,
'text': text,
'tags': ['ansible', 'ansible_report', self.playbook, self.hostname]
"time": to_millis(self.start_time),
"timeEnd": to_millis(end_time),
"isRegion": True,
"text": text,
"tags": ["ansible", "ansible_report", self.playbook, self.hostname],
}
self._send_annotations(data)

def v2_runner_on_failed(self, result, ignore_errors=False, **kwargs):
text = PLAYBOOK_ERROR_TXT.format(playbook=self.playbook, hostname=self.hostname,
username=self.username, task=result._task,
host=result._host.name, result=self._dump_results(result._result))
text = PLAYBOOK_ERROR_TXT.format(
playbook=self.playbook,
hostname=self.hostname,
username=self.username,
task=result._task,
host=result._host.name,
result=self._dump_results(result._result),
)
if ignore_errors:
return
data = {
'time': to_millis(datetime.now()),
'text': text,
'tags': ['ansible', 'ansible_event_failure', self.playbook, self.hostname]
"time": to_millis(datetime.now()),
"text": text,
"tags": ["ansible", "ansible_event_failure", self.playbook, self.hostname],
}
self.errors += 1
self._send_annotations(data)
Expand All @@ -263,10 +278,16 @@ def _send_annotations(self, data):

def _send_annotation(self, annotation):
try:
open_url(self.grafana_url, data=json.dumps(annotation), headers=self.headers,
method="POST",
validate_certs=self.validate_grafana_certs,
url_username=self.grafana_user, url_password=self.grafana_password,
http_agent=self.http_agent, force_basic_auth=self.force_basic_auth)
open_url(
self.grafana_url,
data=json.dumps(annotation),
headers=self.headers,
method="POST",
validate_certs=self.validate_grafana_certs,
url_username=self.grafana_user,
url_password=self.grafana_password,
http_agent=self.http_agent,
force_basic_auth=self.force_basic_auth,
)
except Exception as e:
self._display.error(u'Could not submit message to Grafana: %s' % to_text(e))
self._display.error("Could not submit message to Grafana: %s" % to_text(e))
6 changes: 3 additions & 3 deletions plugins/doc_fragments/api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# Copyright: (c) 2019, Rémi REY (@rrey)
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function

__metaclass__ = type


class ModuleDocFragment(object):

DOCUMENTATION = r'''options:
DOCUMENTATION = r"""options:
grafana_api_key:
description:
- The Grafana API key.
- If set, C(url_username) and C(url_password) will be ignored.
type: str
'''
"""
16 changes: 8 additions & 8 deletions plugins/doc_fragments/basic_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Copyright: (c) 2019, Rémi REY (@rrey)
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function

__metaclass__ = type


class ModuleDocFragment(object):

DOCUMENTATION = r'''options:
DOCUMENTATION = r"""options:
url:
description:
- The Grafana URL.
Expand All @@ -30,9 +30,9 @@ class ModuleDocFragment(object):
aliases: [ grafana_password ]
use_proxy:
description:
- If C(no), it will not use a proxy, even if one is defined in an environment variable on the target hosts.
- If C(false), it will not use a proxy, even if one is defined in an environment variable on the target hosts.
type: bool
default: yes
default: true
client_cert:
description:
- PEM formatted certificate chain file to be used for SSL client authentication.
Expand All @@ -45,8 +45,8 @@ class ModuleDocFragment(object):
type: path
validate_certs:
description:
- If C(no), SSL certificates will not be validated.
- This should only set to C(no) used on personally controlled sites using self-signed certificates.
- If C(false), SSL certificates will not be validated.
- This should only set to C(false) used on personally controlled sites using self-signed certificates.
type: bool
default: yes
'''
default: true
"""
Loading

0 comments on commit f3fdc80

Please sign in to comment.