Documentation
¶
Overview ¶
Package source implements an Icinga Notifications source to send events to the Icinga Notifications API.
To create a new source, start by creating a new Client. Then, for each event you want to forward to Icinga Notifications, call Client.ProcessEvent. This method forwards the event to the Icinga Notifications API and reports further information, such as outdated rules.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRulesOutdated = stderrors.New("rules version is outdated")
ErrRulesOutdated implies that the rules version between the submitted event and Icinga Notifications mismatches.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a common interface to interact with the Icinga Notifications API.
It stores the configuration for the API endpoint and holds a reusable HTTP client for requests. To create a Client, the NewClient function should be used.
func NewClient ¶
NewClient creates a new Client instance with the provided configuration.
The clientName argument is used as the User-Agent header in HTTP requests sent by this Client and should represent the project using this client, e.g., "Icinga DB v1.5.0".
It may return an error if the API base URL cannot be parsed.
func (*Client) ProcessEvent ¶
ProcessEvent submits an event.Event to the Icinga Notifications /process-event API endpoint.
For a successful submission, this method returns (nil, nil).
It may return an ErrRulesOutdated error, implying that the provided ruleVersion does not match the current rules version in the Icinga Notifications daemon. Only in this case, it will also return the current rules specific to this source and their version as RulesInfo, allowing to retry submitting an event after reevaluating it.
For the Event to be submitted, Event.RulesVersion and Event.RuleIds should be set. If no appropriate values are known, they can be left empty. This will return ErrRulesOutdated - unless there are no rules configured that need to be evaluated by the source -, which can be handled as described above to retrieve information and resubmit the event.
If the request fails or the response is not as expected, it returns an error.
type Config ¶
type Config struct {
// Url points to the Icinga Notifications API, e.g., http://localhost:5680
Url string `yaml:"url" env:"URL"`
// Username is the API user for the Icinga Notifications API.
Username string `yaml:"username" env:"USERNAME"`
// Password is the API user's password for the Icinga Notifications API.
Password string `yaml:"password" env:"PASSWORD,unset"` // #nosec G117 -- exported password field
PasswordFile string `yaml:"password_file" env:"PASSWORD_FILE"`
}
Config defines all configuration for the Icinga Notifications API Client.
type RulesInfo ¶
type RulesInfo struct {
// Version of the event rules fetched from the API.
Version string
// Rules is a map of rule IDs to their corresponding object filter expression.
Rules map[string]string
}
RulesInfo holds information about the event rules for a specific source.
A Client can fetch RulesInfo from the Icinga Notifications API via Client.ProcessEvent.
The Version represents the current rules version for this Client. This value should be stored by a caller and set to event.Event.EventVersion when being passed to Client.ProcessEvent, as described there. This allows detecting outdated source rules.
Rules is a map of rule IDs to object filter expressions. These object filter expressions are source-specific. For example, Icinga DB expects an SQL query.