Skip to content

Conversation

yhabteab
Copy link
Member

@yhabteab yhabteab commented Aug 6, 2025

This PR introduces a new notifications package to our Icinga Go library. The package is designed to handle common
Icinga Notifications related tasks, that can be used by any Icinga Notifications source. It provides a set of functions and types that simplify and centralize the interaction with Icinga Notifications API. Within the root of this package, you will find the following files:

  • client.go: This file contains the actual client implementation with a custom HTTP round tripper that handles
    the necessary authentication before sending the final request to the Icinga API.
  • config.go: This file defines the configuration structure that every Icinga Notifications source is required to provide.
  • xhttp_headers.go: This file contains our custom HTTP header constants only that should be used by the Icinga
    Notifications sources to ensure consistency and compatibility with the Icinga API. Currently, it includes only
    X-Icinga-Rules-Version header, which is used to specify the version of the rules that are being used by the source and
    X-Icinga-Rules-Id header, which is used to specify the unique identifier of the rules that are being used by the source.
    Of course, in order to be consistent with the HTTP header naming conventions in Icinga Web 2, both custom headers
    are prefixed with X-Icinga-.

The event package within the notifications package contains common event related types and utilities that should
be used by any Icinga Notifications source as well as by the Icinga Notifications daemon itself.

The change list appears to be quite big, but don't be fooled by it :). Most of them are just unit tests and autogenerated
code. The actual code changes are quite minimal and focused on the new functionality described above.

Oops, did I say autogenerated code? Yes, I did ;)! The notifications package makes use of the Go stringer tool to implement the String() method for the event.Type and event.Severity types in an efficient manner. So, don't be surprised to see the autogenerated files in the event package.

Oh, and one more thing: most of the work was done by Alvar in the Icinga DB repository, so I just had to outsource it to the Icinga Go library with some minor adjustments. So, credit goes to him for the majority of the work.

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Aug 6, 2025
@yhabteab yhabteab force-pushed the notifications branch 2 times, most recently from 609ec3f to 82eff34 Compare August 6, 2025 16:06
@julianbrost
Copy link
Contributor

I'm not sure if this is the right place to add this. The reasoning probably is similar to Icinga/icinga-notifications#304. One thing to consider here: do we expect external projects using this eventually? In this case, this would create dependency updates for them even though if nothing relevant to them changed. So I think having a separate repository with independent versioning for this is also worth considering.

@yhabteab yhabteab force-pushed the notifications branch 2 times, most recently from e4215c5 to 55c038b Compare August 7, 2025 15:16
@lippserd
Copy link
Member

I'm not sure if this is the right place to add this. The reasoning probably is similar to Icinga/icinga-notifications#304. One thing to consider here: do we expect external projects using this eventually? In this case, this would create dependency updates for them even though if nothing relevant to them changed. So I think having a separate repository with independent versioning for this is also worth considering.

I like this idea. How about a MIT licensed go-icinga-notifications project with this code, and the channel base?

@oxzi oxzi added this to the 0.8.0 milestone Aug 28, 2025
@oxzi
Copy link
Member

oxzi commented Sep 2, 2025

After today's discussion to keep these changes in the IGL, I have skimmed the PR once again. In general, it looks good to me. However, it should be merged together with its sibling PRs as otherwise fix-up PRs would follow here.

Rules map[int64]RuleResp // Rules is a map of rule IDs to their corresponding RuleResp objects.
}

// Iter returns an iterator over the rules in the SourceRulesInfo.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Iter returns an iterator over the rules in the SourceRulesInfo.
// Iter returns an iterator over the rules in the RulesInfo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code won't last long though ;)! When sources start to manage their own event rules config by their own, this will become obsolete.

yhabteab and others added 5 commits September 5, 2025 13:08
Moved from Icinga Notifications with some enhancements made.
This is analogous to the `MakeInt` and `MakeString` functions but for Bool.
Alvar did most of the work here in the Icinga DB repo, I'm just trying
to outsource the basic functionality to this library, so that they can
also be used by other projects.

Co-Authored-By: Alvar Penning <[email protected]>
@yhabteab
Copy link
Member Author

yhabteab commented Sep 5, 2025

Changed the tabular test cases to use testutils.TestCase instead of a custom one!

oxzi added a commit to Icinga/icingadb that referenced this pull request Sep 5, 2025
- Bump IGL to latest changes in Icinga/icinga-go-library#145.
- Allow specifying which pipeline keys are relevant, ignore others.
- Allow specifying which pipeline key should be parsed in which type.
- Create history.DowntimeHistoryMeta as a chimera combining
  history.DowntimeHistory and history.HistoryDowntime to allow access
  event_type, distinguishing between downtime_start and downtime_end.
- Trace times for submission steps in the worker. Turns out, the single
  threaded worker blocks roughly two seconds for each
  Client.ProcessEvent method call. This might sum up to minutes if lots
  of events are processed at once. My current theory is that the delay
  results in the expensive bcrypt hash comparison on Notifications.
oxzi added a commit to Icinga/icingadb that referenced this pull request Sep 5, 2025
- Bump IGL to latest changes in Icinga/icinga-go-library#145.
- Allow specifying which pipeline keys are relevant, ignore others.
- Allow specifying which pipeline key should be parsed in which type.
- Create history.DowntimeHistoryMeta as a chimera combining
  history.DowntimeHistory and history.HistoryDowntime to allow access
  event_type, distinguishing between downtime_start and downtime_end.
- Trace times for submission steps in the worker. Turns out, the single
  threaded worker blocks roughly two seconds for each
  Client.ProcessEvent method call. This might sum up to minutes if lots
  of events are processed at once. My current theory is that the delay
  results in the expensive bcrypt hash comparison on Notifications.
oxzi added a commit to Icinga/icinga-notifications that referenced this pull request Sep 5, 2025
Synchronize codebase against latest version of
Icinga/icinga-go-library#145, containing package changes.
oxzi added a commit to Icinga/icingadb that referenced this pull request Sep 5, 2025
- Bump IGL to latest changes in Icinga/icinga-go-library#145.
- Allow specifying which pipeline keys are relevant, ignore others.
- Allow specifying which pipeline key should be parsed in which type.
- Create history.DowntimeHistoryMeta as a chimera combining
  history.DowntimeHistory and history.HistoryDowntime to allow access
  event_type, distinguishing between downtime_start and downtime_end.
- Trace times for submission steps in the worker. Turns out, the single
  threaded worker blocks roughly two seconds for each
  Client.ProcessEvent method call. This might sum up to minutes if lots
  of events are processed at once. My current theory is that the delay
  results in the expensive bcrypt hash comparison on Notifications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants