hangouts_chat

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTemplateAlertmanger = message_template.MessageTemplate{
	Type: message_template.Jsonnet,
	Template: `
local input = std.extVar('input');

local alerts = input.alerts;
local graphIconUrl = 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/graph.png';
local bookIconUrl = 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/book.png';
local alertFiringIconUrl = 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/alert_firing.png';
local alertResolvedIconUrl = 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/alert_resolved.png';
local prometheusAlertManagerIconUrl = 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/prometheus_logo.png';

local iconsForLabelsAndAnnotations = {
  severity: 'BOOKMARK',
  message: 'DESCRIPTION',
  alertname: 'TICKET',
};

local findIconForLabelOrAnnoation(key) = if std.objectHas(iconsForLabelsAndAnnotations, key)
then iconsForLabelsAndAnnotations[key]
else 'STAR';

local makeKVWidget(name, content) = [{
  keyValue: {
    topLabel: name,
    content: content,
    icon: findIconForLabelOrAnnoation(name),
  },
}];

local makeLongWidget(name, content) = [
  {
    keyValue: {
      content: name,
      icon: findIconForLabelOrAnnoation(name),
    },
  },
  {
    textParagraph: {
      text: content,
    },
  },
];

local makeWidgets(resources) = std.flattenArrays([
  if std.length(resources[name]) > 40
  then makeLongWidget(name, resources[name])
  else makeKVWidget(name, resources[name])
  for name in std.objectFields(resources)
]);

local subtitle(annotations) =
  if std.objectHas(annotations, 'summary') then annotations.summary
  else if std.objectHas(annotations, 'message') then annotations.message
  else '';

local makeOpenGraphButton(alert) =
  if std.objectHas(alert, 'generatorURL') then [
    {
      imageButton: {
        name: 'Open Graph (Prometheus)',
        iconUrl: graphIconUrl,
        onClick: {
          openLink: {
            url: alert.generatorURL,
          },
        },
      },
    },
  ] else [];

local makeOpenRunbookButton(alertAnnotations) =
  if std.objectHas(alertAnnotations, 'runbook_url') then [
    {
      imageButton: {
        name: 'Open Runbook (Documentation)',
        iconUrl: bookIconUrl,
        onClick: {
          openLink: {
            url: alertAnnotations.runbook_url,
          },
        },
      },
    },
  ] else [];

{
  cards: [
    {
      name: alert.labels.alertname,
      header: {
        title: alert.labels.alertname + ' (' + alert.labels.severity + ')',
        subtitle: subtitle(alert.annotations),
        imageUrl: prometheusAlertManagerIconUrl,
      },
      sections: [
        {
          header: 'Labels',
          widgets: makeWidgets(alert.labels),
        },
        {
          header: 'Annotations',
          widgets: makeWidgets(alert.annotations),
        },
        {
          widgets: [
            {
              keyValue: {
                topLabel: 'Status',
                content: alert.status,
                iconUrl: if alert.status == 'resolved' then alertResolvedIconUrl else alertFiringIconUrl,
              },
            },
            {
              keyValue: {
                topLabel: 'Fired at',
                content: alert.startsAt,
                icon: 'FLIGHT_DEPARTURE',
              },
            },
          ] + (
            if alert.status == 'resolved' then [
              {
                keyValue: {
                  topLabel: 'Resolved at',
                  content: alert.endsAt,
                  icon: 'FLIGHT_ARRIVAL',
                },
              },
            ] else []
          ),
        },
      ] + (
        if std.objectHas(alert.annotations, 'runbook_url') || std.objectHas(alert, 'generatorURL') then [
          {
            widgets: [{
              buttons: makeOpenGraphButton(alert) + makeOpenRunbookButton(alert.annotations),
            }],
          },
        ] else []
      ),
    }
    for alert in alerts
  ] + [{
    sections: [{
      widgets: [{
        buttons: [{
          textButton: {
            text: 'Open alertmanager',
            onClick: {
              openLink: {
                url: input.externalURL,
              },
            },
          },
        }],
      }],
    }],
  }],
}
`,
}
View Source
var DefaultTemplateFabfuelECSDeploy = message_template.MessageTemplate{
	Type: message_template.Jsonnet,
	Template: `
local input = std.extVar('input');

local iconsForLabelsAndAnnotations = {
  Cluster: 'BOOKMARK',
  Service: 'DESCRIPTION',
  Duration: 'CLOCK',
  Tag: 'MAP_PIN',
  Revision: 'MAP_PIN',
};

local findIconForLabelOrAnnoation(key) = if std.objectHas(iconsForLabelsAndAnnotations, key)
then iconsForLabelsAndAnnotations[key]
else 'STAR';

local toString(value) =
  if !std.isString(value)
  then '' + value
  else value;

local makeKVWidget(name, content) = [{
  keyValue: {
    topLabel: name,
    content: toString(content),
    icon: findIconForLabelOrAnnoation(name),
  },
}];

local makeLongWidget(name, content) = [
  {
    keyValue: {
      content: toString(content),
      icon: findIconForLabelOrAnnoation(name),
    },
  },
  {
    textParagraph: {
      text: content,
    },
  },
];

local makeWidgets(resources) = std.flattenArrays([
  if std.isString(resources[name]) && std.length(resources[name]) > 40
  then makeLongWidget(name, resources[name])
  else makeKVWidget(name, resources[name])
  for name in std.objectFields(resources)
]);

local attachment = input.attachments[0];
local fieldsMap = std.foldl(function(x, y) x { [y.title]: y.value }, attachment.fields, {});

{
  cards: [
    {
      name: input.username,
      header: {
        title: attachment.pretext,
        imageUrl: 'https://miquido.github.io/alertmanager-webhook-forwarder/icons/aws_ecs.png',
      },
      sections: [
        {
          header: 'Details',
          widgets: makeWidgets(fieldsMap),
        },
      ],
    },
  ],
}
`,
}

DefaultTemplateFabfuelECSDeploy Hangouts Chat Message Template See:

View Source
var DefaultTemplateGoTemplateText = message_template.MessageTemplate{
	Type:     message_template.GoTemplateText,
	Template: "{{ .Text }}",
}
View Source
var DefaultTemplateGoTemplateYaml = message_template.MessageTemplate{
	Type: message_template.GoTemplateYAML,
	Template: `
cards:
- name: card-name-yaml
  header:
    subtitle: Some alerts have occurred!
    title: AlertManager
  sections:
  - header: Section Header
    widgets:
    - keyValue:
        bottomLabel: BottomLabel
        content: Content
        icon: DOLLAR
        topLabel: TopLabel
text: {{ .Text | toYaml | indent 4 }}
text2:
{{ .Text | indent 8 }}
`,
}
View Source
var DefaultTemplateJsonnet = message_template.MessageTemplate{
	Type: message_template.Jsonnet,
	Template: `
local cardName = 'Jsonnet Rulez';

{
  cards: [{
    name: cardName,
    header: {
      subtitle: 'Some alerts have occurred!',
      title: 'sometitle',
    },
    sections: [{
      header: std.join(' ', [$.cards[0].header.title, 'Section Header']),
      widgets: [{
        keyValue: { bottomLabel: 'BottomLabel', content: 'Content', icon: 'DOLLAR', topLabel: 'TopLabel' },
      }],
    }],
  }],
  text: std.extVar('input').text,
}
`,
}

Functions

func IncomingWebHookApiKeyOption

func IncomingWebHookApiKeyOption(k string) googleapi.CallOption

func IncomingWebHookTokenOption

func IncomingWebHookTokenOption(t string) googleapi.CallOption

func NewChatSpacesMessagesService

func NewChatSpacesMessagesService() (service *chat.SpacesMessagesService, err error)

func ParseMessageTemplate

func ParseMessageTemplate(input interface{}, template *message_template.MessageTemplate) (message *chat.Message, err error)

func SendIncomingWebHookMessage

func SendIncomingWebHookMessage(service *chat.SpacesMessagesService, message *chat.Message, config *IncomingWebHookConfig) (*chat.Message, error)

Types

type HangoutsChatForwarder

type HangoutsChatForwarder struct {
	SpacesMessageService *chat.SpacesMessagesService
}

func NewHangoutsChatForwarder

func NewHangoutsChatForwarder() (forwarder *HangoutsChatForwarder, err error)

func (*HangoutsChatForwarder) Forward

func (f *HangoutsChatForwarder) Forward(input interface{}, template *message_template.MessageTemplate, forwardChannel *forward_channel.ForwardChannel) (err error)

type IncomingWebHookConfig

type IncomingWebHookConfig struct {
	ApiKey   string `json:"key"`
	Token    string `json:"token"`
	SpaceId  string `json:"spaceId"`
	ThreadId string `json:"threadId,omitempty"`
	Version  string `json:"version"`
}

func NewIncomingWebHookConfigFromForwardChannel

func NewIncomingWebHookConfigFromForwardChannel(forwardChannel *forward_channel.ForwardChannel) (incomingWebHookConfig *IncomingWebHookConfig, err error)

func (*IncomingWebHookConfig) Configure

func (config *IncomingWebHookConfig) Configure(message *chat.Message)

func (*IncomingWebHookConfig) Parent

func (config *IncomingWebHookConfig) Parent() string

func (*IncomingWebHookConfig) ThreadName

func (config *IncomingWebHookConfig) ThreadName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL