ZABBIX docking flight book for alarm notification

Flybook provides a rich api for message notification, including text messages, picture messages, rich text messages. This introduction uses Flybook api to send text messages, the following is the implementation ideas
Flying Book API address:

Ideas for implementation

1. Three authorization credentials are required

  • app_access_token: Access the App resource related interface.
  • tenant_access_token: Accesses the enterprise resource-related interface.
  • user_access_token: Accesses the user resource related interface.

2. Obtain the user_id from the phone number of the recipient of the zabbix alarm, which can be used for @ the responsible person in the group behind, or sent directly to a responsible person
3.chat_id is used to send to a specified group. Here I provide two ways to get chat_id, which will be described later
4. Incoming zabbix alarm message, and the person in charge of Aite sent to the flying books group or individuals

Obtain Authorization Certificate

1. Get App ID and App Secret

Log in to the developer background and create your own enterprise application on the My Apps page.Go to the Enterprise Build-in Application Details page to get the App ID and App Secret.

2. Get tenant_access_token

One way is through enterprise-built apps, the other is through app store apps, where I use the first method to create apps directly

3. Once the application is created, it can be obtained from the APP ID and App Secret construction requests

def gettenant_access_token():

    return response

Get user_id

User_id can be obtained from a registered phone number or mailbox, defined in zabbix, and passed in a parameter to get user_id

def getuserid(tenant_access_token):
    headers={"Authorization":"Bearer %s"%tenant_access_token}
    return response

Get chat_id

Here I provide two ways to get chat_id, one is to join a robot in a group to get chat_id from the group information, the other is to create a group chat by a robot to get the group information, and of course there are other ways, which I will only cover here, I will use the first method to get chat_id

First join the robot to group chat

Construct request to get chat_id

def getchatid(tenant_access_token):
    #Get chatid
    headers={"Authorization":"Bearer %s"%tenant_access_token,"Content-Type":"application/json"}
    return response

Send messages to Flying Books or Flying Books users

There are three parameters required, one is user_id, one is chat_id, and the other is tenant_access_token, which can be sent by passing in an alarm message

def sendmes(user_id,chat_id,tenant_access_token):
    #Send a message to the group
    headers={"Authorization":"Bearer %s"%tenant_access_token,"Content-Type":"application/json"}
            "text":"%s<at user_id=\"%s\">test</at>"%(messages,user_id)
    #Send a message to an individual
    # data={"user_id":user_id,
    #     "msg_type":"text",
    #     "content":{
    #         "text":"%s<at user_id=\"%s\">test</at>"%(messages,user_id)
    #     }
    # },headers=headers,json=data)

Configure alarm action and receiver on ZABBIX

Configure alarm media types

Note that the order of parameters should not be confused

Configure user's receiving information

That is, the mobile number of the user registering for Flybook

Configure Actions

Alarm test

Here I disable one of the windows agent s for testing

Alarm with picture information will be added later, complete code please visit github organization shade notes

Welcome to the personal bulletin "Master Chen without Stories"

Tags: Linux JSON Zabbix github Mobile

Posted on Wed, 19 Feb 2020 12:25:15 -0500 by moe