package controllers
// Issue: https://github.com/feiyu563/PrometheusAlert/issues/181
import (
"encoding/json"
"strconv"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
// GitlabController is a beego controller for gitlab webhook events
type GitlabController struct {
beego.Controller
}
// GitlabProject is a project section in gitlab event
type GitlabProject struct {
Name string `json:"name"`
Homepage string `json:"homepage"`
}
// GitlabRepository is a repository section in gitlab event
type GitlabRepository struct {
Name string `json:"name"`
Homepage string `json:"homepage"`
}
// GitlabUser is a user section in gitlab event
// event: Issue, Note, Merge Request, Wiki, Job, Deployment, Feature Flag
type GitlabUser struct {
Name string `json:"name"`
Username string `json:"username"`
Email string `json:"email"`
}
// GitlabAssignee is a assignee section in gitlab event
type GitlabAssignee struct {
Username string `json:"username"`
}
// GitlabCommit is a commit section in gitlab event
type GitlabCommit struct {
Message string `json:"message"`
Title string `json:"title"`
}
// GitlabWiki is a wiki section in gitlab event
type GitlabWiki struct {
WebUrl string `json:"web_url"`
}
// GitlabObjectAttributes is a object_attribute section in gitlab event
// event: Issue, Merge Request, Pipeline, Comment, Wiki
type GitlabObjectAttributes struct {
// Issue, Merge Request, Wiki
Action string `json:"action"`
Title string `json:"title"`
// Issue, Merge Request
State string `json:"state"`
Description string `json:"description"`
// Issue, Comment, Wiki
Url string `json:"url"`
// Merge Request
TargetBranch string `json:"target_branch"`
SourceBranch string `json:"source_branch"`
MergeStatus string `json:"merge_status"`
// Pipeline
Ref string `json:"ref"`
Sha string `json:"sha"`
Source string `json:"source"`
Status string `json:"status"`
// Comment
Note string `json:"note"`
NoteableType string `json:"noteable_type"`
// Wiki
Message string `json:"message"`
// Feature Flag
Name string `json:"name"`
Active bool `json:"active"`
}
// GitlabRunner is a runner section in gitlab event
type GitlabRunner struct {
Active bool `json:"active"`
RunnerType string `json:"runner_type"`
IsShared bool `json:"is_shared"`
Description string `json:"description"`
}
// GitlabEvent contains all of gitalb events
type GitlabEvent struct {
ObjectKind string `json:"object_kind"`
Ref string `json:"ref"`
CheckoutSha string `json:"checkout_sha"`
Message string `json:"message"`
Username string `json:"user_name"`
UserUsername string `json:"user_username"`
Sha string `json:"sha"`
BuildName string `json:"build_name"`
BuildStage string `json:"build_stage"`
BuildStatus string `json:"build_status"`
Status string `json:"status"`
DeploymentUrl string `json:"deployable_url"`
Environment string `json:"environment"`
Name string `json:"name"`
Url string `json:"url"`
Description string `json:"description"`
Tag string `json:"tag"`
Action string `json:"action"`
Commits []GitlabCommit `json:"commits"`
User GitlabUser `json:"user"`
Project GitlabProject `json:"project"`
Repository GitlabRepository `json:"repository"`
ObjectAttributes GitlabObjectAttributes `json:"object_attributes"`
Assignees []GitlabAssignee `json:"assignees"`
Wiki GitlabWiki `json:"wiki"`
Runner GitlabRunner `json:"runner"`
}
// GitlabWeixin sends gitlab webhook events to wx robot
func (c *GitlabController) GitlabWeixin() {
event := GitlabEvent{}
eventType := c.Ctx.Request.Header.Get("X-Gitlab-Event")
wxurl := c.GetString("wxurl")
logsign := "[" + LogsSign() + "]"
logs.Info(logsign, string(c.Ctx.Input.RequestBody))
json.Unmarshal(c.Ctx.Input.RequestBody, &event)
c.Data["json"] = sendGitlabEvent(3, event, eventType, logsign, wxurl)
logs.Info(logsign, c.Data["json"])
c.ServeJSON()
}
// GitlabDingding sends gitlab webhook events to dingtalk robot
func (c *GitlabController) GitlabDingding() {
event := GitlabEvent{}
eventType := c.Ctx.Request.Header.Get("X-Gitlab-Event")
ddurl := c.GetString("ddurl")
logsign := "[" + LogsSign() + "]"
logs.Info(logsign, string(c.Ctx.Input.RequestBody))
json.Unmarshal(c.Ctx.Input.RequestBody, &event)
c.Data["json"] = sendGitlabEvent(2, event, eventType, logsign, ddurl)
logs.Info(logsign, c.Data["json"])
c.ServeJSON()
}
// GitlabFeishu sends gitlab webhook events to feishu v2 robot
func (c *GitlabController) GitlabFeishu() {
event := GitlabEvent{}
eventType := c.Ctx.Request.Header.Get("X-Gitlab-Event")
fsurl := c.GetString("fsurl")
logsign := "[" + LogsSign() + "]"
logs.Info(logsign, string(c.Ctx.Input.RequestBody))
json.Unmarshal(c.Ctx.Input.RequestBody, &event)
c.Data["json"] = sendGitlabEvent(4, event, eventType, logsign, fsurl)
logs.Info(logsign, c.Data["json"])
c.ServeJSON()
}
func genWXtext(event GitlabEvent, eventType string) string {
var WXtext, WXbasetext, WXothertext string
// 有些payload中不同时包含project和repository信息,因此需要判断下
var name, homepage string
if event.Project.Name != "" {
name = event.Project.Name
homepage = event.Project.Homepage
} else {
name = event.Repository.Name
homepage = event.Repository.Homepage
}
WXbasetext = "[Gitlab事件通知](" + homepage + ")\n" +
"> `事件类型`: " + eventType + "\n" +
"> `仓库链接`: [" + name + "](" + homepage + ")\n"
switch eventType {
case "Push Hook":
WXothertext = "> `提交用户`: " + event.Username + "(@" + event.UserUsername + ")\n" +
"> `当前Ref`: " + event.Ref + "\n" +
"> `当前提交`: " + event.CheckoutSha + "\n"
if len(event.Commits) != 0 {
WXothertext = WXothertext + "> `提交信息`: \n" + "\n" + event.Commits[len(event.Commits)-1].Message
}
case "Tag Push Hook":
WXothertext = "> `提交用户`: " + event.Username + "(@" + event.UserUsername + ")\n" +
"> `当前Ref`: " + event.Ref + "\n" +
"> `当前提交`: " + event.CheckoutSha + "\n"
if len(event.Commits) != 0 {
WXothertext = WXothertext + "> `提交信息`: \n" + "\n" + event.Commits[0].Message
}
case "Merge Request Hook":
WXothertext = "> `提交用户`: " + event.User.Name + "(@" + event.User.Username + ")\n" +
"> `源分支`: " + event.ObjectAttributes.SourceBranch + "\n" +
"> `目标分支`: " + event.ObjectAttributes.TargetBranch + "\n" +
"> `合并请求链接`: [" + event.ObjectAttributes.Title + "](" + event.ObjectAttributes.Url + ")\n" +
"> `合并请求状态`: " + event.ObjectAttributes.Action + "\n"
if len(event.Assignees) != 0 {
WXothertext = WXothertext + "> `分配给`: @" + event.Assignees[0].Username + "\n"
}
// 描述内容可能有多行,放最后
WXothertext = WXothertext + "> `合并请求描述`:\n" + "\n" + event.ObjectAttributes.Description
case "Issue Hook":
WXothertext = "> `提交用户`: " + event.User.Name + "(@" + event.User.Username + ")\n" +
"> `议题链接`: [" + event.ObjectAttributes.Title + "](" + event.ObjectAttributes.Url + ")\n" +
"> `议题状态`: " + event.ObjectAttributes.Action + "\n"
if len(event.Assignees) != 0 {
WXothertext = WXothertext + "> `分配给`: @" + event.Assignees[0].Username + "\n"
}
WXothertext = WXothertext + "> `议题描述`:\n" + "\n" + event.ObjectAttributes.Description
case "Pipeline Hook":
WXothertext = "> `提交用户`: " + event.User.Name + "(@" + event.User.Us
没有合适的资源?快使用搜索试试~ 我知道了~
基于Prometheus的集成式运维告警中心设计源码
共1161个文件
svg:535个
js:232个
css:120个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2024-12-25
00:29:05
上传
评论
收藏 74.15MB ZIP 举报
温馨提示
该项目为基于Prometheus的集成式运维告警中心设计源码,包含1162个文件,涵盖535个SVG图形、232个JavaScript文件、120个CSS样式文件、94个PNG图片、46个Go语言源文件、43个Markdown文件、28个地图文件、15个HTML文件、9个YAML配置文件、3个Shell脚本文件。该告警中心支持与Prometheus、Zabbix、Graylog和Grafana等主流监控和日志系统集成,并能接收钉钉、微信、华为云、腾讯云、阿里云等平台的短信和电话通知,旨在提升运维监控的效率和响应速度。
资源推荐
资源详情
资源评论
收起资源包目录
基于Prometheus的集成式运维告警中心设计源码 (1161个子文件)
build.bat 127B
app-example.conf 11KB
adminlte.css 1.49MB
adminlte.min.css 1.33MB
adminlte.light.css 970KB
adminlte.light.min.css 855KB
adminlte.core.css 794KB
adminlte.core.min.css 699KB
adminlte.components.css 384KB
adminlte.components.min.css 350KB
adminlte.plugins.css 310KB
adminlte.plugins.min.css 284KB
all.css 72KB
fontawesome.css 70KB
all.min.css 58KB
fontawesome.min.css 57KB
v4-shims.css 40KB
adminlte.extra-components.css 39KB
flag-icons.css 38KB
flag-icon.css 37KB
flag-icons.min.css 34KB
adminlte.extra-components.min.css 34KB
flag-icon.min.css 33KB
v4-shims.min.css 26KB
ambiance.css 26KB
swagger-ui.css 25KB
adminlte.pages.css 19KB
adminlte.pages.min.css 16KB
icheck-bootstrap.css 14KB
icheck-bootstrap.min.css 12KB
buttons.bootstrap4.css 10KB
buttons.bootstrap4.min.css 9KB
codemirror.css 9KB
dataTables.bootstrap4.css 8KB
svg-with-js.css 8KB
abbott.css 8KB
dataTables.bootstrap4.min.css 7KB
svg-with-js.min.css 6KB
solarized.css 5KB
mdn-like.css 5KB
responsive.bootstrap4.css 5KB
responsive.bootstrap4.min.css 4KB
liquibyte.css 4KB
merge.css 3KB
yonce.css 3KB
lint.css 3KB
xq-dark.css 3KB
material-palenight.css 3KB
material-ocean.css 3KB
duotone-light.css 3KB
darcula.css 3KB
lesser-dark.css 3KB
duotone-dark.css 3KB
material-darker.css 3KB
ayu-mirage.css 2KB
material.css 2KB
icecoder.css 2KB
pastel-on-dark.css 2KB
oceanic-next.css 2KB
ttcn.css 2KB
shadowfox.css 2KB
tomorrow-night-eighties.css 2KB
ayu-dark.css 2KB
moxer.css 2KB
base16-dark.css 2KB
erlang-dark.css 2KB
xq-light.css 2KB
monokai.css 2KB
twilight.css 2KB
vibrant-ink.css 2KB
base16-light.css 2KB
mbo.css 2KB
nord.css 2KB
paraiso-light.css 2KB
paraiso-dark.css 2KB
3024-night.css 2KB
dracula.css 2KB
seti.css 2KB
zenburn.css 2KB
3024-day.css 2KB
abcdef.css 2KB
the-matrix.css 2KB
blackboard.css 2KB
gruvbox-dark.css 2KB
lucario.css 2KB
yeti.css 2KB
tern.css 2KB
midnight.css 2KB
panda-syntax.css 2KB
rubyblue.css 2KB
tomorrow-night-bright.css 2KB
night.css 2KB
cobalt.css 2KB
colorforth.css 2KB
idea.css 2KB
railscasts.css 1KB
hopscotch.css 1KB
isotope.css 1KB
bespin.css 1KB
simplescrollbars.css 1KB
共 1161 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
lly202406
- 粉丝: 3032
- 资源: 5531
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- java项目,毕业设计-企业客户信息反馈平台
- 数据分析-29-260万用户大型家电和电子产品购买分析(包含数据代码)
- 投票微信小程序完整源码+数据库(高分毕设项目)
- Design Compiler各版本User Guide
- java项目,毕业设计-人事管理系统
- opencv基于摄像头实现的人脸捕获及识别项目源代码+模型文件+使用说明
- sealos离线安装k8s集群镜像-part3
- 基于阶梯碳交易成本的含电转气-碳捕集(P2G-CCS)耦合的综合能源系统低碳经济优化调度,采用(Matlab+Yalmip+Cplex) 考虑P2G设备、碳捕集电厂、风电机组、光伏机组、CHP机组、燃
- Linux常用命令大全.zip
- 富士康PLM项目简报.pptx
- 直驱式永磁同步风力发电系统的仿真模型
- java项目,毕业设计-书籍学习平台
- PaddleTS 是一个易用的深度时序建模的Python库,它基于飞桨深度学习框架PaddlePaddle,专注业界领先的深度模型,旨在为领域专家和行业用户提供可扩展的时序建模能力和便捷易用的用户体验
- 微信投票小程序投票小程序源码(高分项目)
- 数据分析-30-7万条天猫订单数据分析
- MATLAB 给变量输入二进制 二进制与十进制转化
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功