Skip to content

Commit

Permalink
CA-9156: Add ansible test and linting workflows (#35)
Browse files Browse the repository at this point in the history
* CA-9156: add workflow for Ansible tests

* CA-9156: drop duplicate empty line

* CA-9156: add linting workflow

* CA-9156: add newlines

* CA-9156: add linebreak

* CA-9156: address more linter violations

* CA-9156: address more linter violations

* CA-9156: fix linter issues in tests

* CA-9156: fix ansible sanity tests

* CA-9156: fix one more sanity test

* CA-9156: add requirements for python

* CA-9156: add working directory

* CA-9156: change install requirements command

* CA-9156: add integration tests

* CA-9156: change port in integration test

* CA-9156: add debug log level

* CA-9156: fix log-cli-level

* CA-9156: remove integration tests

* CA-9156: add ansibl lint config with production profile

* CA-9156: initialize changelog

* CA-9156: add changelog fragment

* CA-9156: fix fragment

* CA-9156: adapt README

* CA-9156: fix typo

* CA-9156: add code of conduct

* CA-9156: change description and add docs link

* CA-9156: fix linter problems

---------

Co-authored-by: Dietmar <dietmar.schnitzer@dynatrace.com>
  • Loading branch information
MrManny and dietmar-91 authored Apr 22, 2024
1 parent eebc75f commit 1fdb83e
Show file tree
Hide file tree
Showing 25 changed files with 323 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .ansible-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# .ansible-lint configuration

profile: production # null, min, basic, moderate,safety, shared, production

warn_list:
- experimental
2 changes: 1 addition & 1 deletion .github/workflows/ah_token_refresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
with:
environment: release
secrets:
ah_token: ${{ secrets.AH_TOKEN }}
ah_token: ${{ secrets.AH_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/ansible_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Run Ansible linter
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
name: Ansible Lint # Naming the build is important to use it as a status check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ansible-lint
uses: ansible/ansible-lint@main # or version tag instead of 'main'
45 changes: 45 additions & 0 deletions .github/workflows/ansible_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run Ansible tests
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- "3.10"
- "3.9"

defaults:
run:
working-directory: ansible_collections/

steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: ansible_collections/ansible/eda

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install test requirements
run: |
pip install -U pip
pip install -r test_requirements.txt
working-directory: ansible_collections/ansible/eda

- name: Run sanity tests
run: ansible-test sanity
working-directory: ansible_collections/ansible/eda

- name: Run unit tests
run: ansible-test units --venv -v --num-workers 1
working-directory: ansible_collections/ansible/eda
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
environment: release
secrets:
ah_token: ${{ secrets.AH_TOKEN }}
ansible_galaxy_api_key: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
ansible_galaxy_api_key: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
4 changes: 2 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
- name: Install deps
run: python -m pip install tox
- name: Move to tox conf file and run tox
run: |
run: |
cd .github/workflows
python -m tox -- ../..
python -m tox -- ../..
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ tests/output
.tox
releases/*
vars.yml
*__pycac
*__pycac

# Antsibull-changelog
changelogs/.plugin-cache.yaml
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Dynatrace\.Event\_Driven\_Ansible Release Notes
132 changes: 132 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

- The use of sexualized language or imagery, and sexual attention or advances of
any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email address,
without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official email address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
opensource@dynatrace.com. All complaints will be reviewed and investigated
promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Dynatrace + Red Hat Event Driven Ansible: Auto-Remediation
# Dynatrace + Red Hat Event Driven Ansible

This collection contains the following Event-Driven Ansible source plugins:

* dt_webhook
* dt_esa_api

## Auto-Remediation (dt_esa_api)

This Event source plugin from Dynatrace captures all problems from your Dynatrace tenant and in conjunction with Ansible EDA rulebooks helps to enable auto-remediation in your environment.

## Requirements
### Requirements

* Dynatrace SaaS or Managed environment
* Dynatrace API Token with the following scopes: `Read problems` and `Write problems`
* Ansible Automation Platform with EDA Controller instance

## Example rulebook
### Example rulebook

```yaml
---
Expand Down Expand Up @@ -43,6 +50,31 @@ This Event source plugin from Dynatrace captures all problems from your Dynatrac
name: dt-update-comments.yml
```
## dt_webhook
The dt_webhook event-source plugin is capable of receiving events from Dynatrace via the "Send event to Event-Driven Ansible" workflow action of the [Red Hat Ansible for Workflows integration](https://docs.dynatrace.com/docs/platform-modules/automations/workflows/actions/redhat).
### Example rulebook
```yaml
---
- name: Listen for events on dt_webhook
hosts: all
sources:
- dynatrace.event_driven_ansible.dt_webhook:
host: 0.0.0.0
port: 5000
token: '{{ <token_variable_name> }}'

rules:
- name: API Endpoint not available
condition: event.payload.eventData["event.name"] is match ("Monitoring not available")
action:
run_job_template:
name: "Trigger test playbook"
organization: "Default"
```
## Licensing
We are using Apache License 2.0 as our default.
Expand Down
34 changes: 34 additions & 0 deletions changelogs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
changelog_filename_template: ../CHANGELOG.md
changelog_filename_version_depth: 0
changes_file: changelog.yaml
changes_format: combined
ignore_other_fragment_extensions: true
keep_fragments: false
mention_ancestor: true
new_plugins_after_name: removed_features
notesdir: fragments
output_formats:
- md
prelude_section_name: release_summary
prelude_section_title: Release Summary
sanitize_changelog: true
sections:
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
title: Dynatrace.Event_Driven_Ansible
trivial_section_name: trivial
use_fqcn: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Set up ansible-lint and ansible-test for collection.
3 changes: 2 additions & 1 deletion docs/dt_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Steps to do:

* Checkout the GitHub repository

* Create a vars.yml file in the rulebooks directory and configure the variable var_eda_token. This “token variable” will then be used when running the rulebook and passed to the event-source plugin. Hint: Currently the token configuration is done by setting a variable. This will be changed in the future.
* Create a vars.yml file in the rulebooks directory and configure the variable var_eda_token. This "token variable" will then be used when running the
rulebook and passed to the event-source plugin. Hint: Currently the token configuration is done by setting a variable. This will be changed in the future.

```
var_eda_token: <your-test-token>
Expand Down
1 change: 1 addition & 0 deletions extensions/eda/plugins/event_source/dt_esa_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async def updatedtproblem(prob_id: str, dtapihost: str, dtapitoken: str,
except aiohttp.ClientError:
logging.exception("aiohttp client Exception")


async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
"""Process the problem information.
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/dt_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Description:
This is an event source plugin for receiving events via a webhook
from the "send-event-to-eda" action of Dynatrace Workflows.
from the "send-event-to-eda" action of the Red Hat Ansible for Workflows integration.
The payload must be a valid JSON object.
Usage in a rulebook:
Expand Down
11 changes: 7 additions & 4 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ readme: README.md
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
# @nicks:irc/im.site#channel'
authors:
- Dynatrace <support@dynatrace.com>
- Dynatrace <support@dynatrace.com>


### OPTIONAL but strongly recommended
# A short summary description of the collection
description: This Event source plugin from Dynatrace captures all problems from your Dynatrace tenant and in conjunction with Ansible EDA rulebooks helps to enable auto-remediation in your environment.
description: |
This collection contains two event source plugins from Dynatrace. The dt_esa_api plugin captures all problems from your Dynatrace tenant
and in conjunction with Ansible EDA rulebooks helps to enable auto-remediation in your environment. The dt_webhook plugin listens for
events sent by the Red Hat Ansible for workflows integration from Dynatrace.
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
license:
- Apache-2.0
- Apache-2.0

# The path to the license file for the collection. This path is relative to the root of the collection. This key is
# mutually exclusive with 'license'
#license_file: ''
# license_file: ''

# Must also include one of the following: application, cloud, database, infrastructure, linux, monitoring, networking, security, storage, tools, windows
tags: [dynatrace, eda, monitoring, tools, cloud]
Expand Down
2 changes: 1 addition & 1 deletion inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ all:
hosts:
localhost:
ansible_connection: local
ansible_python_interpreter: /usr/bin/python3
ansible_python_interpreter: /usr/bin/python3
Loading

0 comments on commit 1fdb83e

Please sign in to comment.