Giter Site home page Giter Site logo

kubewatch-qyweapp-webhook's Introduction

kubewatch-qyweapp-webhook

这是一个可以让kubewatch 推送webhook给 企业微信群机器人 的python3脚本。

example

特性

  • 支持kubewatch接收到POD状态变更为createdupdated时,进行企业微信群机器人markdown消息发送
  • 还会发一条世界经典格言

文件目录介绍

.
├── README.md                       # 本文件
├── Dockerfile                      # kubernetes 服务部署配置脚本
├── deployment.yaml                 # Dockerfile
├── requirements.txt                # 所需资源文本
├── main.py                         # 主运行程序脚本

使用方法

1.在main.py中指定kubernetes命名空间

kubernetes的namespaces应该具有命名规范,比如一个叫做趣味畅玩的游戏项目,有验收环境(staging)和正式生产环境(production),那么namespaces可以是fun-game-stagingfun-game-production

识别环境字符串所使用的是string.split('-')[-1]

这样做的好处是脚本能够识别出各个环境的演示网址,并拼接在markdown中进行企业微信机器人消息推送。

接下来请修改main.py中的project变量:

projects = {
    # struct is regular(string) => dict
    'projectA-namespace':{
        # 企业微信群聊机器人token
        'token':'AAAAAA-1234-7890-000-123456789000',
        #环境演示项目的地址 假如只有2个环境,则只需要填写2个演示地址
        'staging_url':'https://staging.exampleA.com',
        'production_url':'https://www.exampleA.com'
    },
    'projectB-namespace':{
        'token':'BBBBBB-1234-7890-000-123456789000',
        'testing_url':'https://testing.exampleB.com',
        'other_url':'https://other.exampleC.com'
    }
}

2. 设置格言API key

修改main.py中的tianApiKey

这里使用天行数据的名言警句接口,每天有100次免费API额度。

如果不需要格言功能,可以修改getMotto()方法返回你需要的文本内容。

3. 部署服务

docker build -t webhook/qyweapp-kubewatch:latest . 

docker push webhook/qyweapp-kubewatch:latest #建议推送到自己的私有镜像中心

vim deployment.yaml #请先修改脚本中的镜像地址

kubectl  apply -f deployment.yaml

M1芯片必须使用docker buildx build 和参数 --platforms linux/amd64

4.测试运行效果

测试用kube-watch 格式JSON

{"eventmeta": {"kind": "pod", "name": "project-example-com-staging/backend-xxxx-yyy", "namespace": "project-example-com-staging", "reason": "created"}, "text": "A `pod` in namespace `project-example-com-staging` has been `created`:\n`project-example-com-staging/backend-xxxx-yyy`", "time": "2021-02-26T08: 12: 08.758617965Z"}

使用curl发送:

curl -H "Content-Type: application/json" -X POST -d '{"eventmeta": {"kind": "pod", "name": "project-example-com-staging/backend-xxxx-yyy", "namespace": "project-example-com-staging", "reason": "created"}, "text": "A `pod` in namespace `project-example-com-staging` has been `created`:\n`project-example-com-staging/backend-xxxx-yyy`", "time": "2021-02-26T08: 12: 08.758617965Z"}' "http://wechat-webhook:8080"

修改markdown内容

参考企业微信机器人配置说明

调整kube-watch内容

参考Go webhook代码

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

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.