Code Monkey home page Code Monkey logo

falcon-message's Introduction

falcon-message

open-falcon alarm 发送消息组件,注意这个是基于2.0版本新增的im功能定制。

现在实现了钉钉群消息和微信消息

注意,需要修改mysql 中 uic库中的user表,把im字段的大小改为4000(防止钉钉token溢出截断,不生效)

微信

需要在通讯录的人员名单中的IM配置处配置微信名字。 配置说明请参考 https://github.com/Yanjunhui/chat 这里,代码也是从这里复制粘贴,进行了适当修改,以适应当前程序。

钉钉群

  1. 钉钉消息是发送到某个群,而不是针对单个人发送,所以需要在这个群中设置一个机器人,定义的时候,选择自定义机器人,然后将webhook链接中access_token的值拷贝出来,以备待用。
  2. 在falcon dashaboar 用户管理中心新建一个用户,填写email,然后在 IM 处填写 [ding]:access_token,这里的access_token就是上面的access_token,如果相同消息要发送给多个机器人,则access_token之间用英文分号;分隔,保存用户信息。
  3. 在dashboard的群组管理中心新建一个群组,把上面的这个用户加入到这个群组。
  4. 在要告警的地方把上面的这个群组加入即可。
  5. 修改alarm组件中 api 下,增加 配置:"im": "http://localhost:23329/api/v1/message",端口按照本项目配置文件中的进行修改。
  6. 启动本项目即可。

模板

默认模板文件是 message-template.md,可以使用的参数如下:

  • 告警等级: {{.Level}}
  • 告警类型: {{.Type}}
  • 告警指标: {{.Condition}}
  • 告警主机: {{.Endpoint}}
  • 告警时间: {{.Time}}
  • 告警说明: {{.Desc}}
  • 次数:{{.Count}}
  • 表达式中的连续次数 {{.TriggerCount}}

如果参数配置错误会导致模板渲染失败无法发送。

默认模板中有如下表达式:

{{with elapse .Count 60 .TriggerCount 300}}{{divide . 60}}{{end}}

其中 60 是数据上报周期,默认是60s,如果修改了默认值,需要修改这里的值。

300 是告警之间推迟时间,默认5分钟。

{{divide . 60}} 是除以60s,得到分钟

falcon-message's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

falcon-message's Issues

怎么修改钉钉告警模板

现在是

P2
PROBLEM
sh-test-master1

 all(#3) mem.memused.percent  81.08559>=80
O1 2019-07-15 14:17:00

想改成这样:

告警等级: P2
告警类型: problem
告警指标:  all(#3) mem.memused.percent  81.08559>=80
告警主机: sh-test-master1
告警IP:  192.168.100.100
告警时间: 2019-7-15 14:17:00
告警说明: 内存使用率超过80%,已持续3分钟
告警链接:
告警联系人:

收不到钉钉报警

您好,我在测试使用钉钉报警的时候发现群组的机器人接收不到报警信息,服务启动正常,查看日志都正常,我单独对钉钉机器人发送信息也正常,不知是哪里出现问题,还请指教。
alarm日志:
image

message日志:
image

您好,我在编译后运行时出现如下信息,请问如何解决,先谢谢了

刚接触open-falcon监控,希望实现钉钉消息推送,在按照说明配置后,运行时出现如下信息:
{"time":"2018-03-10T09:59:37.738326163+08:00","level":"ERROR","prefix":"echo","file":"echo.go","line":"286","message":"code=404, message=Not Found"}
相关的alarm日志是这样的:
time="2018-03-10T09:59:37+08:00" level=debug msg="write im to queue, im:<Tos:[ding]:ff6945e588a3e89a61da0dd9575f561c75b9f682e8e669161e5f8168b37783fa, Content:[P0][OK][02-2c2g][][ all(#3) cpu.user 0.5<0][O1 2018-03-10 09:59:00]>, queue:/im"

time="2018-03-10T09:59:37+08:00" level=debug msg="send im:<Tos:[ding]:ff6945e588a3e89a61da0dd9575f561c75b9f682e8e669161e5f8168b37783fa, Content:[P0][OK][02-2c2g][][ all(#3) cpu.user 0.5<0][O1 2018-03-10 09:59:00]>, resp:{"message":"Not Found"}, url:http://127.0.0.1:23329/api/v1"

请问可以帮我分析一下嘛,表示非常感谢!

只发送成功了一次告警,返回errmsg":"token is not exist","errcode":300001,请问是否是协议头问题?

2018/08/30 22:41:26 message comming
2018/08/30 22:41:26 tos: [ding]:b10deee3d9e2dbc21ce57eb9f80da23a643ebe83154dd6b086486da2c833acb6,b10deee3d9e2dbc21ce57eb9f80da23a643ebe83154dd6b086486da2c833acb6 content: [P0][PROBLEM][root][][CPU空闲率大于%50 all(#1) cpu.idle 98.96907>=0.9][O4 2018-08-30 22:41:00]
2018/08/30 22:41:26 message: {"at":{"atMobiles":null,"isAtAll":false},"msgtype":"text","text":{"content":"P0\nPROBLEM\nroot\n\nCPU空闲率大于%50 all(#1) cpu.idle 98.96907\u003e=0.9\nO4 2018-08-30 22:41:00"}}
2018/08/30 22:41:26 response result: {"errmsg":"token is not exist","errcode":300001}
2018/08/30 22:41:26 {false token is not exist 300001}
2018/08/30 22:41:26 token: b10deee3d9e2dbc21ce57eb9f80da23a643ebe83154dd6b086486da2c833acb6,b10deee3d9e2dbc21ce57eb9f80da23a643ebe83154dd6b086486da2c833acb6

发送告警时出现runtime error: slice bounds out of range的问题

下载的编译好的v0.0.4版本的包,配置完成后测试报警,发现有报错,app.log如下
2019/09/09 17:11:44 listening on localhost:23329
2019/09/09 17:14:15 message comming
2019/09/09 17:14:15 tos: [ding]:xxx content: [P0][PROBLEM][SITserver][][开发测试服务器硬盘占用率过高(>80%) all(#3) df.statistics.used.percent 54.46472>=40][O2 2019-09-09 17:14:10]
2019/09/09 17:14:15 {true ok 0}
2019/09/09 17:24:14 tos: [ding]:xxx content: [P0][PROBLEM][SITserver][][开发测试服务器硬盘占用率过高(>80%) lookup(#3,5) df.statistics.used.percent 54.50835>=40][O1 2019-09-09 17:24:10] {"time":"2019-09-09T17:24:14.90493896+08:00","level":"-","prefix":"echo","file":"panic.go","line":"522","message":"[PANIC RECOVER] runtime error: slice bounds out of range goroutine 66 [running]:\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1.1(0x8fd178, 0x1000, 0xc000090000, 0x990760, 0xc00013a000)\n\t/Users/du/Library/Gopath/src/github.com/labstack/echo/middleware/recover.go:71 +0xf1\npanic(0x867b20, 0xc8b510)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/runtime/panic.go:522 +0x1b5\ngithub.com/sdvdxl/falcon-message/util.HandleContent(0xc0003565a0, 0x9a, 0x4, 0xc0003565a0, 0x9a)\n\t/Users/du/Library/Gopath/src/github.com/sdvdxl/falcon-message/util/util.go:55 +0x93a\nmain.main.func5(0x990760, 0xc00013a000, 0xc000292330, 0xc00009bc00)\n\t/Users/du/Library/Gopath/src/github.com/sdvdxl/falcon-message/main.go:93 +0x376\ngithub.com/labstack/echo.(*Echo).Add.func1(0x990760, 0xc00013a000, 0x8fd178, 0x1000)\n\t/Users/du/Library/Gopath/src/github.com/labstack/echo/echo.go:477 +0x87\ngithub.com/labstack/echo/middleware.RecoverWithConfig.func1.1(0x990760, 0xc00013a000, 0x0, 0x0)\n\t/Users/du/Library/Gopath/src/github.com/labstack/echo/middleware/recover.go:78 +0xd5\ngithub.com/labstack/echo.(*Echo).ServeHTTP.func1(0x990760, 0xc00013a000, 0xc00023e058, 0x8d9c20)\n\t/Users/du/Library/Gopath/src/github.com/labstack/echo/echo.go:574 +0x105\ngithub.com/labstack/echo.(*Echo).ServeHTTP(0xc00023e000, 0x984d20, 0xc000416380, 0xc000140000)\n\t/Users/du/Library/Gopath/src/github.com/labstack/echo/echo.go:583 +0x1ed\nnet/http.serverHandler.ServeHTTP(0xc0002385b0, 0x984d20, 0xc000416380, 0xc000140000)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/http/server.go:2774 +0xa8\nnet/http.(*conn).serve(0xc000360000, 0x9856e0, 0xc0000b4080)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/http/server.go:1878 +0x851\ncreated by net/http.(*Server).Serve\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/http/server.go:2884 +0x2f4\n\ngoroutine 1 [IO wait]:\ninternal/poll.runtime_pollWait(0x7f394048aff8, 0x72, 0x0)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/runtime/netpoll.go:182 +0x56\ninternal/poll.(*pollDesc).wait(0xc00013ff98, 0x72, 0x0, 0x0, 0x8e0a37)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/internal/poll/fd_poll_runtime.go:87 +0x9b\ninternal/poll.(*pollDesc).waitRead(...)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/internal/poll/fd_poll_runtime.go:92\ninternal/poll.(*FD).Accept(0xc00013ff80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/internal/poll/fd_unix.go:384 +0x1ba\nnet.(*netFD).accept(0xc00013ff80, 0x42ad7f, 0xc000000008, 0x8fdea0)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/fd_unix.go:238 +0x42\nnet.(*TCPListener).accept(0xc0000a0798, 0x8fdea0, 0xc0002206a0, 0xc000220640)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/tcpsock_posix.go:139 +0x32\nnet.(*TCPListener).Accept(0xc0000a0798, 0xc000341a50, 0x18, 0xc000000180, 0x6b7cb4)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/tcpsock.go:260 +0x48\nnet/http.(*Server).Serve(0xc0002385b0, 0x984a60, 0xc0000a0798, 0x0, 0x0)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/net/http/server.go:2859 +0x22d\ngithub.com/tylerb/graceful.(*Server).Serve(0xc000220640, 0x984a60, 0xc0000a0798, 0x984a60, 0xc0000a0798)\n\t/Users/du/Library/Gopath/src/github.com/tylerb/graceful/graceful.go:309 +0x2f2\ngithub.com/tylerb/graceful.(*Server).ListenAndServe(0xc000220640, 0x2, 0x2)\n\t/Users/du/Library/Gopath/src/github.com/tylerb/graceful/graceful.go:147 +0xa1\nmain.main()\n\t/Users/du/Library/Gopath/src/github.com/sdvdxl/falcon-message/main.go:128 +0x73d\n\ngoroutine 18 [syscall, 9 minutes]:\nos/signal.signal_recv(0x0)\n\t/usr/local/Cellar/go/1.12.7/libexec/src/runtime/sigqueue.go:139 +0x9c\nos/signal.loop()\n\t/usr/local/Cellar/go/1.12.7/libexec/src/os/signal/signal_unix.go:23 +0x22\ncreated by os/signal.init.0\n\t/usr/local/Cellar/go/1.12.7/libexec/src/os/signal/signal_unix.go:29 +0x41\n\ngoroutine 21 [select]:\ngithub.com/tylerb/graceful.(*Server).manageConnections(0xc000220640, 0xc00007e720, 0xc00007e780, 0xc00007e7e0, 0xc00007e840, 0xc00007e8a0, 0xc00007e900)\n\t/Users/du/Library/Gopath/src/github.com/tylerb/graceful/graceful.go:366 +0x2da\ncreated by github.com/tylerb/graceful.(*Server).Serve\n\t/Users/du/Library/Gopath/src/github.com/tylerb/graceful/graceful.go:297 +0x220\n\ngoroutine 33 [chan receive, 9 minutes]:\ngithub.com/t\n"} {"time":"2019-09-09T17:24:14.90525154+08:00","level":"ERROR","prefix":"echo","file":"context.go","line":"548","message":"runtime error: slice bounds out of range"}

发现表达式采用all(#3)的就能成功发送告警,用lookup(#3,5)这个表达式的就会报错runtime error: slice bounds out of range
但某些场景的告警是需要使用lookup表达式的,希望能解决下这个问题

配置好后,一直报这个错

"level":"ERROR","prefix":"echo","file":"echo.go","line":"284","message":"code=404, message=Not Found
请问这个是什么问题呢

打包报错

$ glide rebuild
[WARN] The rebuild command is deprecated and will be removed in a future version
[WARN] Use the go install command instead
[WARN] The name listed in the config file (github.com/sdvdxl/falcon-message) does not match the current location (falcon-message)
[INFO] Building dependencies.
[INFO] Running go build github.com/labstack/echo/middleware
[INFO] Running go build github.com/tylerb/graceful
[INFO] Running go build golang.org/x/sys
[WARN] Failed to run 'go install' for golang.org/x/sys: can't load package: package falcon-message/vendor/golang.org/x/sys: no Go files in /root/workspace/src/falcon-message/vendor/golang.org/x/sys

[INFO] Running go build golang.org/x/crypto
[WARN] Failed to run 'go install' for golang.org/x/crypto: can't load package: package falcon-message/vendor/golang.org/x/crypto: no Go files in /root/workspace/src/falcon-message/vendor/golang.org/x/crypto

而文件是存在的
$ ls /root/workspace/src/falcon-message/vendor/golang.org/x/crypto
acme bcrypt blake2s bn256 chacha20poly1305 CONTRIBUTING.md cryptobyte ed25519 LICENSE nacl openpgp PATENTS pkcs12 README salsa20 sha3 tea xtea
AUTHORS blake2b blowfish cast5 codereview.cfg CONTRIBUTORS curve25519 hkdf md4 ocsp otr pbkdf2 poly1305 ripemd160 scrypt ssh twofish xts

执行control build提示下列错误

./control build
/root/go/src/github.com/sdvdxl/falcon-message/sender/wexin.go:18:2: cannot find package "github.com/sdvdxl/go-tools/encrypt" in any of:
/usr/lib/golang/src/github.com/sdvdxl/go-tools/encrypt (from $GOROOT)
/root/go/src/github.com/sdvdxl/go-tools/encrypt (from $GOPATH)
main.go:15:2: cannot find package "github.com/tylerb/graceful" in any of:
/usr/lib/golang/src/github.com/tylerb/graceful (from $GOROOT)
/root/go/src/github.com/tylerb/graceful (from $GOPATH)
/root/go/src/github.com/sdvdxl/dinghook/dinghook.go:15:2: cannot find package "gopkg.in/go-playground/validator.v9" in any of:
/usr/lib/golang/src/gopkg.in/go-playground/validator.v9 (from $GOROOT)
/root/go/src/gopkg.in/go-playground/validator.v9 (from $GOPATH)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.