graylog2-server icon indicating copy to clipboard operation
graylog2-server copied to clipboard

Fix PagerDuty integration URL encoding

Open clementsen opened this issue 1 year ago • 1 comments

Description

Update to integrations/pagerduty/MessageFactory.java method buildStreamWirthUri to properly URL encode the query parameter to avoid URISyntaxException.

Motivation and Context

We were experiencing this integration not working because of this exception:

java.lang.IllegalStateException: Error when building the stream link URL.
	at org.graylog.integrations.pagerduty.client.MessageFactory.buildStreamWithUrl(MessageFactory.java:130)
	at org.graylog.integrations.pagerduty.client.MessageFactory.lambda$createTriggerMessage$0(MessageFactory.java:85)
...
Caused by: java.net.URISyntaxException: Illegal character in query at index 98: https://graylog.tgtg.ninja/streams/6501ad968f39a04c9b0cd13a/search?q=hour:[06 TO 14] AND weekday:[1 TO 5]
	at java.base/java.net.URI$Parser.fail(Unknown Source)
	at java.base/java.net.URI$Parser.checkChars(Unknown Source)
	at java.base/java.net.URI$Parser.parseHierarchical(Unknown Source)
	at java.base/java.net.URI$Parser.parse(Unknown Source)
	at java.base/java.net.URI.<init>(Unknown Source)
	at org.graylog.integrations.pagerduty.client.MessageFactory.buildStreamWithUrl(MessageFactory.java:128)
	... 25 more

How Has This Been Tested?

  • [x] We can successfully build the project using mvn compile
  • [x] Deployed it in our setup and the fix works
  • [x] otherwise only tested running effected code in isolation:
        var streamPath = "https://graylog.tgtg.ninja/streams/6501ad968f39a04c9b0cd13a";
        URIBuilder uriBuilder = new URIBuilder(streamPath);
        String query = "hour:[06 TO 14] AND weekday:[1 TO 5]";
        uriBuilder.addParameter("q", query);
        var url = uriBuilder.build().toURL();
        System.out.println(url);

outputs

https://graylog.tgtg.ninja/streams/6501ad968f39a04c9b0cd13a/search?q=hour%3A%5B06+TO+14%5D+AND+weekday%3A%5B1+TO+5%5D

Output URL works on Graylog 7.0.0+a788678.

Screenshots (if appropriate):

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Refactoring (non-breaking change)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have requested a documentation update.
  • [x] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.

clementsen avatar Nov 27 '25 11:11 clementsen

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 27 '25 11:11 CLAassistant