Documentation
¶
Index ¶
- Constants
- func FormatMessage(writer io.Writer, req *NotificationRequest)
- func FormatSubject(req *NotificationRequest) string
- func PopulateDefaults(typePtr Plugin) error
- func RunPlugin(plugin Plugin)
- type Address
- type ConfigOption
- type ConfigOptions
- type Contact
- type Event
- type Incident
- type Info
- type NotificationRequest
- type Object
- type Plugin
Constants ¶
const ( MethodGetInfo = "GetInfo" MethodSetConfig = "SetConfig" MethodSendNotification = "SendNotification" )
Variables ¶
This section is empty.
Functions ¶
func FormatMessage ¶
func FormatMessage(writer io.Writer, req *NotificationRequest)
FormatMessage formats a NotificationRequest message and adds to the given io.Writer.
The created message is a multi-line message as one might expect it in an email.
func FormatSubject ¶
func FormatSubject(req *NotificationRequest) string
FormatSubject returns the formatted subject string based on the event type.
func PopulateDefaults ¶
PopulateDefaults sets the struct fields from Info.ConfigAttributes where ConfigOption.Default is set.
It should be called from each channel plugin within its Plugin.SetConfig before doing any further configuration.
Types ¶
type Address ¶
type Address struct {
// Type field matches the Info.Type, effectively being the channel plugin file name.
Type string `json:"type"`
// Address is the associated Type-specific address, e.g., an email address for type email.
Address string `json:"address"`
}
Address to receive this notification. Each Contact might have multiple addresses.
type ConfigOption ¶
type ConfigOption struct {
// Element name
Name string `json:"name"`
// Element type:
//
// string = text, number = number, bool = checkbox, text = textarea, option = select, options = select[multiple], secret = password
Type string `json:"type"`
// Element label map. Locale in the standard format (language_REGION) as key and corresponding label as value.
// Locale is assumed to be UTF-8 encoded (Without the suffix in the locale)
//
// e.g. {"en_US": "Save", "de_DE": "Speichern"}
// An "en_US" locale must be given as a fallback
Label map[string]string `json:"label"`
// Element description map. Locale in the standard format (language_REGION) as key and corresponding label as value.
// Locale is assumed to be UTF-8 encoded (Without the suffix in the locale)
//
// When the user moves the mouse pointer over an element in the web UI, a tooltip is displayed with a given message.
//
// e.g. {"en_US": "HTTP request method for the request.", "de_DE": "HTTP-Methode für die Anfrage."}
// An "en_US" locale must be given as a fallback
Help map[string]string `json:"help,omitempty"`
// Element default: bool for checkbox default value, string for other elements (used as placeholder)
Default any `json:"default,omitempty"`
// Set true if this element is required, omit otherwise
Required bool `json:"required,omitempty"`
// Options of a select element: key => value.
// Only required for the type option or options
//
// e.g., map[string]string{
// "1": "January",
// "2": "February",
// }
Options map[string]string `json:"options,omitempty"`
// Element's min option defines the minimum allowed number value. It can only be used for the type number.
Min types.Int `json:"min,omitempty"`
// Element's max option defines the maximum allowed number value. It can only be used for the type number.
Max types.Int `json:"max,omitempty"`
}
ConfigOption describes a config element.
type ConfigOptions ¶
type ConfigOptions []ConfigOption
ConfigOptions describes all ConfigOption entries.
This type became necessary to implement the database.sql.driver.Valuer to marshal it into JSON.
type Contact ¶
type Contact struct {
// FullName of a Contact as defined in Icinga Notifications.
FullName string `json:"full_name"`
// Addresses of a Contact with a type.
Addresses []*Address `json:"addresses"`
}
Contact to receive notifications for the NotificationRequest.
type Event ¶
type Event struct {
// Time when this event occurred, being encoded according to RFC 3339 when passed as JSON.
Time time.Time `json:"time"`
// Type of this event, e.g., a "state" change, "mute" or "unmute". See further ./internal/event/event.go
Type string `json:"type"`
// Username may contain a user triggering this event, depending on the event's source.
Username string `json:"username"`
// Message of this event, might be a check output when the related Object is an Icinga 2 object.
Message string `json:"message"`
}
Event indicating this NotificationRequest.
type Incident ¶
type Incident struct {
// Id is the unique identifier for this Icinga Notifications Incident, allows linking related events.
Id int64 `json:"id"`
// Url pointing to the Icinga Notifications Web module's Incident page.
Url string `json:"url"`
// Severity of this Incident.
Severity string `json:"severity"`
}
Incident of this NotificationRequest, grouping Events for this Object.
type Info ¶
type Info struct {
// Type of the channel plugin.
//
// Not part of the JSON object. Will be set to the channel plugin file name before database insertion.
Type string `db:"type" json:"-"`
// Name of this channel plugin in a human-readable value.
Name string `db:"name" json:"name"`
// Version of this channel plugin.
Version string `db:"version" json:"version"`
// Author of this channel plugin.
Author string `db:"author" json:"author"`
// ConfigAttributes contains multiple ConfigOption(s) as JSON-encoded list.
ConfigAttributes ConfigOptions `db:"config_attrs" json:"config_attrs"`
}
Info contains channel plugin information.
type NotificationRequest ¶
type NotificationRequest struct {
// Contact to receive this NotificationRequest.
Contact *Contact `json:"contact"`
// Object associated with this NotificationRequest, e.g., an Icinga 2 Service Object.
Object *Object `json:"object"`
// Incident associated with this NotificationRequest.
Incident *Incident `json:"incident"`
// Event being responsible for creating this NotificationRequest, e.g., a firing Icinga 2 Service Check.
Event *Event `json:"event"`
}
NotificationRequest is being sent to a channel plugin via Plugin.SendNotification to request notification dispatching.
type Object ¶
type Object struct {
// Name depending on its source, may be "host!service" when from Icinga 2.
Name string `json:"name"`
// Url pointing to this Object, may be to Icinga Web.
Url string `json:"url"`
// Tags defining this Object, may be "host" and "service" when from Icinga 2.
Tags map[string]string `json:"tags"`
// ExtraTags attached, may be a host or service groups when form Icinga 2.
ExtraTags map[string]string `json:"extra_tags"`
}
Object which this NotificationRequest is all about, e.g., an Icinga 2 Host or Service object.
type Plugin ¶
type Plugin interface {
// GetInfo returns the corresponding plugin *Info.
GetInfo() *Info
// SetConfig sets the plugin config, returns an error on failure.
SetConfig(jsonStr json.RawMessage) error
// SendNotification sends the notification, returns an error on failure.
SendNotification(req *NotificationRequest) error
}
Plugin defines necessary methods for a channel plugin.
Those methods are being called via the internal JSON-RPC and allow channel interaction. Within the channel's main function, the channel should be launched via RunPlugin.