Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHCLOUD-22813] Handle provided context.host_url in integration templates #3221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jessicarod7
Copy link
Member

Jira issue

https://issues.redhat.com/browse/RHCLOUD-22813

Description

Currently, URLs in PagerDuty and Camel notifications are constructed by the PagerDutyTransformer, or one of three Qute templates, respectively. Each one has a slightly different way of handling URLs, and the Camel templates are not the ones currently shown in this repo.

This PR creates a new class, InsightsUrlsBuilder, which provides consistent construction of the two URLs for all integrations:

  • data.inventory_url represents a link to the specific host, cluster, or inventory item in the Console that generated the message. If data.context.host_url is provided, it will be used here.
  • data.application_url links back to the application that generated the event.

The PR will also make it easy to modify the URL format in a followup issue.

Database migration

A new migration file (V1.109.0) has been added. It takes the current templates used in the Notifications database, and updates them to use the new URLs.

Note

One change has been made to the existing format: Camel messages no longer contain a leading \n. This caused unexpected failures while testing the Slack processor, and weirdly did not fail with the Teams processor when it should have.

Testing

  • Updated connector-pagerduty tests to emulate the new URL builder on the engine side.
  • Updated CamelProcessorTest implementers to use the new URLs in their Qute templates
  • Added a new test for PagerDuty and Camel to verify that data.context.host_url will always be used if present

Example

Using the following trimmed output from BaseTransformer:

{
  "bundle": "rhel",
  "application": "advisor",
  "event_type": "new-recommendation",
  "timestamp": "2024-12-19T15:21:45.129372",
  // trimmed
  "context": {
    "inventory_id": "6eaaa39c-55f7-4f45-81a9-84c75b1475d6",
    "hostname": "my-computer-jrodri",
    "display_name": "my-computer-jrodri",
    "host_url": "https://console.redhat.com/insights/inventory/some-unique-host-url-path",
    "tags": []
  },
  "events": [
    {
      // one event, trimmed
    },
    {
      // another event, trimmed
    }
  ],
  "source": {
    "application": {"display_name": "Advisor"},
    "bundle": {"display_name": "Red Hat Enterprise Linux"}
  }
  "environment_url": "https://console.redhat.com"
}

And the new Microsoft Teams template:

{"text":"{#if data.context.display_name??}[{data.context.display_name}]({data.inventory_url}) triggered {data.events.size()} event{#if data.events.size() \u003e 1}s{/if}{#else}{data.events.size()} event{#if data.events.size() \u003e 1}s{/if} triggered{/if} from {data.source.application.display_name} - {data.source.bundle.display_name}. [Open {data.source.application.display_name}]({data.application_url})"}

We generate this message:

[my-computer-jrodri](https://console.redhat.com/insights/inventory/some-unique-host-url-path) triggered 2 events from Advisor - Red Hat Enterprise Linux. [Open Advisor](https://console.redhat.com/insights/advisor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant