-
Notifications
You must be signed in to change notification settings - Fork 52
Add google chat to alert provider #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add google chat to alert provider #97
Conversation
This commit introduces a new alerting provider for Google Chat, allowing you to receive incident notifications in your Google Chat spaces. Key changes include: - Addition of `GoogleChatProvider` in `pkg/common/googlechat.go` to handle message construction and sending via webhooks. - A new message template `config/googlechat_message.tmpl` using Google Chat's Cards V2 format, adapted from the Slack template to support various alert sources and include an 'Acknowledge' button. - Configuration updates in `config/config.yaml` and `pkg/config/config.go` to define settings for the Google Chat provider (webhook URL, template path, enable flag, message properties). - Integration into `pkg/common/factory_alert.go` to make the Google Chat provider available. - Documentation updates in `README.md` and `src/userguide/configuration.md` explaining how to configure and use the new integration. - Comprehensive unit tests in `pkg/common/googlechat_test.go` for the `GoogleChatProvider`, covering successful alert sending for resolved and unresolved incidents, as well as error handling for HTTP and template issues. The Google Chat integration supports rich formatting and interactive acknowledgment buttons, providing feature parity with the existing Slack integration.
This commit introduces a new alerting provider for Google Chat, allowing you to receive incident notifications in your Google Chat spaces. Key changes include: - Addition of `GoogleChatProvider` in `pkg/common/googlechat.go` to handle message construction and sending via webhooks. - A new message template `config/googlechat_message.tmpl` using Google Chat's Cards V2 format, adapted from the Slack template to support various alert sources and include an 'Acknowledge' button. - Configuration updates in `config/config.yaml` and `pkg/config/config.go` to define settings for the Google Chat provider (webhook URL, template path, enable flag, message properties). - Integration into `pkg/common/factory_alert.go` to make the Google Chat provider available. - Documentation updates in `README.md` and `src/userguide/configuration.md` explaining how to configure and use the new integration. - Comprehensive unit tests in `pkg/common/googlechat_test.go` for the `GoogleChatProvider`. This commit also includes: - Implementation of a simple logger in `pkg/utils/logger.go` and refactoring of `GoogleChatProvider` to use this centralized logger. - Addition of JSON helper functions (`escapeJsonString`, `buildJsonArray`, `buildJsonObjectMembers`) to `pkg/utils/func_maps.go` to ensure robust JSON generation in templates. - Updates to unit tests to verify these new utility functions and logging. The Google Chat integration supports rich formatting and interactive acknowledgment buttons, providing feature parity with the existing Slack integration.
|
Hi @Hemaphat. Thank you for this PR. However, could you please show me an image of the Google Chat result? I have not used Google Chat before, so I am unsure how it looks with the template. |
|
Could you please review this pull request and test it? @nghiadaulau |
|
Hi @hoalongnatsu it look like this from example payload in readme.
|
Oke, let's me check |
|
Hi @Hemaphat Next, I see you have implemented a logger in utils. I think the logger you should implement in the /pkg/logger folder. In this folder, the interface for the logger will be implemented in a separate file. Then, other loggers will be created to implement the logger interface (There are many types of loggers such as Go's default logger, ZapLogger, GrayLogger,...) Next I found in your logger you are using I suggest you use zaplogger for better future. Example interface: package logger
type Fields = map[string]interface{}
type LogLevel int
const (
LogLevelDebug LogLevel = iota
LogLevelInfo
LogLevelWarning
LogLevelError
LogLevelFatal
)
func (l LogLevel) String() string {
switch l {
case LogLevelDebug:
return "debug"
case LogLevelInfo:
return "info"
case LogLevelWarning:
return "warning"
case LogLevelError:
return "error"
case LogLevelFatal:
return "fatal"
default:
return "info"
}
}
type Logger interface {
Debugf(message string, args ...interface{})
Infof(message string, args ...interface{})
Warnf(message string, args ...interface{})
Errorf(message string, args ...interface{})
Fatalf(message string, args ...interface{})
// add more field to log
With(key string, value interface{}) Logger
Withs(Fields) Logger
GetLevel() string
Sync()
}
|
|
It's even better if when you init the logger, you can pass in the log level and enable, to control when to log the entire body and when not. func New...(level LogLevel, enable bool) Logger {
///
...
} |


This PR was created by Google Jules and tested locally
This commit introduces a new alerting provider for Google Chat,
allowing you to receive incident notifications in your Google Chat spaces.
Key changes include:
GoogleChatProviderinpkg/common/googlechat.goto handlemessage construction and sending via webhooks.
config/googlechat_message.tmplusing Google Chat'sCards V2 format, adapted from the Slack template to support various
alert sources and include an 'Acknowledge' button.
config/config.yamlandpkg/config/config.goto define settings for the Google Chat provider (webhook URL, template
path, enable flag, message properties).
pkg/common/factory_alert.goto make the Google Chatprovider available.
README.mdandsrc/userguide/configuration.mdexplaining how to configure and use the new integration.
This commit also includes:
pkg/utils/logger.goand refactoringof
GoogleChatProviderto use this centralized logger.escapeJsonString,buildJsonArray,buildJsonObjectMembers) topkg/utils/func_maps.goto ensure robustJSON generation in templates.