本篇文章主要讲如何在开启了kerberos的kafka环境中配置kafka-eagle,并开启邮件报警和企业微信报警。
首先展示system-config.properties的配置:
######################################
# multi zookeeper&kafka cluster list 配置zk的信息,这里可以加多个集群
######################################
kafka.eagle.zk.cluster.alias=512ProductionCluster
512ProductionCluster.zk.list=zk-ip1:2181,zk-ip2:2181,zk-ip3:2181
######################################
# zk client thread limit
######################################
kafka.zk.limit.size=25
######################################
# kafka eagle webui port
######################################
kafka.eagle.webui.port=10002
######################################
# kafka offset storage 配置kafka的offset信息存在哪里,zk中还是kafka中,需要根据具体的kafka版本来确定
######################################
# Whether the Kafka performance monitoring diagram is enabled
512ProductionCluster.kafka.eagle.offset.storage=kafka
kafka.eagle.metrics.charts=true
# If offset is out of range occurs, enable this property -- Only suitable for kafka sql
#kafka.eagle.sql.fix.error=true
# alarm email configure 配置邮件报警的信息
######################################
kafka.eagle.mail.enable=true
kafka.eagle.mail.sa=***
kafka.eagle.mail.username=***@163.com
kafka.eagle.mail.password=***
kafka.eagle.mail.server.host=smtp.163.com
kafka.eagle.mail.server.port=25
######################################
# alarm im configure
######################################
#kafka.eagle.im.dingding.enable=true
#kafka.eagle.im.dingding.url=https://oapi.dingtalk.com/robot/send?access_token=
#配置微信报警信息
kafka.eagle.im.wechat.enable=true
kafka.eagle.im.wechat.url=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=巴拉巴拉一大串(这个access_token需要根据你们的企业微信自己去获取,稍后分享如何获取)
#要发给哪些用户,一般都是根据企业微信的应用做限制,用户配置成@all,想让哪些人看就把哪些人拉到这个应用中
kafka.eagle.im.wechat.touser=@all
#应用的id
kafka.eagle.im.wechat.agentid=1000002
######################################
# delete kafka topic token删除topic需要输入的口令
######################################
kafka.eagle.topic.token=keadmin
######################################
# kafka sasl authenticate 启用kerberos
######################################
kafka.eagle.sasl.enable=true
kafka.eagle.sasl.protocol=SASL_PLAINTEXT
kafka.eagle.sasl.mechanism=GSSAPI
#kafka的jaas.conf
kafka.eagle.sasl.client=/data3/kafka-eagle/conf/kafka_client_jaas.conf
######################################
# kafka jdbc driver address元数据放在什么数据库中
######################################
kafka.eagle.driver=com.mysql.jdbc.Driver
kafka.eagle.url=jdbc:mysql://******
kafka.eagle.username=****
kafka.eagle.password=****
上面用到的/data3/kafka-eagle/conf/kafka_client_jaas.conf:
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
renewTicket=true
serviceName="kafka"
keyTab="/data3/kafka-eagle/conf/kafka.keytab"
principal="kafka/***.***.com@HAIER.COM";
};
获取企业微信access_token的python程序(一个简单的通过企业微信发报警信息的程序,将打印出来的url复制粘贴到配置文件中即可):
import requests
import sys
import json
import os
def get_token () :
url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
values = {'corpid': '企业微信的id',
'corpsecret': '应用的秘钥',
}
req = requests.post(url, params=values)
data = json.loads(req.text)
return data["access_token"]
def send_msg(str1):
url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + get_token()
values = """{"touser":"@all",
"msgtype":"text",
"agentid":应用的id,
"text":{
"content": "%s"
},
"safe":"0"
}""" %(str(str1))
requests.post(url, values)
print(url)
if __name__ == '__main__':
send_msg(sys.argv[1])