Automatic zabbix monitoring processing method and device and medium
By using the go program and ansible tool in the zabbix monitoring system to realize automatic processing and recovery of alarm information, the problem of low alarm processing efficiency in the existing technology is solved, and the operation and maintenance efficiency and standardized operation level are improved.
Patent Information
- Application Number
- CN202411569234.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-01-24
AI Technical Summary
The existing technology cannot realize automated alarm processing during zabbix monitoring. It requires operation and maintenance to manually view alarm information and perform script recovery, which is inefficient, time-consuming and error-prone.
By creating a Go program, the program automatically draws the alarm information after the Zabbix alarm, write it to the TXT file, and use Ansible automation tool to perform the recovery script to achieve the automation recovery of the alarm.
It greatly improves the work efficiency of operation and maintenance personnel, reduces the working time of operation and maintenance personnel, improves the standardization operation level of operation and maintenance, and reduces the risk and error rate of manual operation.
Smart Images

Figure CN119363564A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of network operation and maintenance, and specifically relates to an automated zabbix monitoring processing method, device and medium. Background Art
[0002] Zabbix is an enterprise-level open source solution that provides distributed system monitoring and network monitoring functions based on a web interface. It can monitor various network parameters, ensure the safe operation of the server system, and provide a flexible notification mechanism for system administrators to quickly locate / solve various existing problems. With the help of Zabbix, it is easy to reduce the heavy server management tasks of operation and maintenance personnel and achieve continuous operation of business systems.
[0003] During the monitoring by Zabbix, the alarms initiated by Zabbix cannot be automatically processed. The operation and maintenance personnel need to check the alarm information and then execute script recovery or manual recovery on the corresponding server. The current method is inefficient and time-consuming, and manual operation is risky and error-prone. Summary of the invention
[0004] The object of the present invention is to provide an automated zabbix monitoring processing method to solve the technical problems existing in the prior art.
[0005] In order to achieve the above object, the technical solution adopted by the present invention is as follows: An automated zabbix monitoring processing method comprises the following steps: Step S1: Create a go program, which contains the alarm information obtained in Zabbix, the constants required for program operation, and parses JSON data; Step S2: upload the go program to the target server; Step S3: Run the go program on the target server: Zabbix outputs the alarm information after the alarm, and the go program pulls the alarm information and writes it into a txt file; Step S4: Run the recovery script: The go program detects whether the txt file has changed. If there is no change, it proves that the recovery script cannot handle it, and the alarm is manually processed. If there is a change, check whether the return value recorded in the txt file is the alarm to be restored by the recovery script. If so, the go program pulls the value in the file and uses the ansible automation tool to execute the recovery script on the corresponding server. The recovery script restores the alarm on the corresponding server according to the value in the file.
[0006] Preferably, the execution process of the go program is as follows: Step S3.1: Define the structure of the host slice and zabbix alarm information to be obtained, and map the defined structure fields with JSON keys; Step S3.2: Define constants in the main function. The constants include the URL, USER, PASS, and file path of the zabbix client. Step S3.3: Create a valid request payload and specify the operation you want to perform and the data required; Step S3.4: Send API request: reference the http.NewRequest function to send the request and pass in the request body; Step S3.5: Set the username and password, and reference the http.Client function to send a request to the zabbix client to obtain the response information returned by the zabbix client; Step S3.6: After the zabbix client returns the value, it parses the JSON value and returns the parsed value; Step S3.7: Reference the OS function to create a txt file and write the return value into the txt file.
[0007] Preferably, the host includes two values: one is the ID of the monitoring alarm, and the other is the IP of the monitoring alarm.
[0008] In order to achieve the above-mentioned object, the present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program is executed by a processor to implement the automated zabbix monitoring processing method.
[0009] In order to achieve the above-mentioned purpose, the present invention also provides a device for automated zabbix monitoring and processing, comprising: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the device for automated zabbix monitoring and processing performs the automated zabbix monitoring and processing method.
[0010] Compared with the prior art, the present invention has the following beneficial effects: The present invention realizes a method for automatically restoring an alarm after a zabbix alarm through a GO program, thereby solving the disadvantages of low efficiency, time consumption, risk and error-proneness in the existing manual operation for handling alarms, greatly improving the work efficiency of operation and maintenance personnel, reducing the working time of operation and maintenance personnel, and improving the standardized operation level of operation and maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 This is a schematic diagram of the principle of Example 1 of the present invention.
[0012] Figure 2 This is a principle block diagram of Example 3 of the present invention. DETAILED DESCRIPTION
[0013] In order to enable those skilled in the art to have a clearer understanding and knowledge of the present invention, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described below are only used to explain the present invention, and are convenient for understanding. The technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.
[0014] It should be noted that the illustrations provided in the following embodiments are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the form, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0015] Example 1 like Figure 1 As shown, this embodiment provides an automated zabbix monitoring and processing method, which realizes automatic recovery of alarms according to the zabbix alarm method and the output alarm information. Without modifying the zabbix source code, the GO program is used to collect the key alarm information of the zabbix client, and the corresponding recovery alarm script is executed according to the information therein.
[0016] In this embodiment, the automated zabbix monitoring processing method specifically includes the following steps: 1. Step S1: Create a go program The go program contains the alarm information obtained in zabbix, as well as the constants required for program operation and parsing JSON data; The go program includes the following functions: define the structure of hostid, ip and zabbix alarm information that need to be obtained; define constants in the main function; before sending an API request, create a valid request payload (PayLoad) to specify the operation you want to perform and the required data; after setting the username and password, send a request to the zabbix client and get a response; return the required JSON value and parse it, and return the parsed value; create a txt file and write the return value to the file.
[0017] 2. Step S2: Upload the go program to the target server In order for the script to run normally, it is necessary to check whether there is a go program running environment on the server. The target server should have a go program running environment so that the go program can run normally.
[0018] Step 3: Run the program on the target server, the program receives the value and stores it in a file In this step, Zabbix outputs the alarm information after the alarm, and the go program pulls the alarm information and writes it to a txt file. In this embodiment, the execution process of the go program is as follows: Step S3.1: Define the structure of the host slice and zabbix alarm information that need to be obtained, map the defined structure fields with the JSON key, and the obtained host includes two values: one is the ID of the monitoring alarm, and the other is the IP of the monitoring alarm; Step S3.2: Define constants in the main function, and the contents of the constants include the URL, USER, PASS, and file path of the zabbix client; Step S3.3: Create a valid request payload and specify the operation you want to perform and the required data; Step S3.4: Send an API request: reference the http.NewRequest function to send a request and pass in the request body; Step S3.5: Set the username and password, and reference the http.Client function to send a request to the zabbix client, and obtain the response information returned by the zabbix client; Step S3.6: After the zabbix client returns the value, parse the JSON value and return the parsed value; Step S3.7: Reference the OS function to create a txt file and write the return value to the txt file.
[0019] Step S4: Restore Script After the go program is executed, the go program detects whether the txt file has changed. If there is no change, it proves that the recovery script cannot handle it, and the alarm is manually processed. If there is a change, check whether the return value recorded in the txt file is the alarm to be restored by the recovery script. If so, the go program pulls the value in the file and uses the ansible automation tool to execute the recovery script on the corresponding server. The recovery script restores the alarm on the corresponding server according to the value in the file.
[0020] This embodiment uses the go program to realize automatic recovery of Zabbix alarms, reduces the dependence on the operation of operation and maintenance personnel under the existing architecture, and reduces the workload of operation and maintenance.
[0021] Example 2 This embodiment provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the automated zabbix monitoring processing method provided in Example 1. A person of ordinary skill in the art can understand that all or part of the steps of implementing the method provided in Example 1 can be completed by hardware related to the computer program, and the above-mentioned computer program can be stored in a computer-readable storage medium, and when the program is executed, the steps of the method provided in Example 1 are executed; and the above-mentioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.
[0022] Example 3 like Figure 2 As shown, this embodiment provides an automated zabbix monitoring processing device, including: a processor and a memory; the memory is used to store a computer program; the processor is connected to the memory, and is used to execute the computer program stored in the memory, so that the automated zabbix monitoring processing device executes the automated zabbix monitoring processing method provided in Example 1.
[0023] Specifically, the memory includes: ROM, RAM, disk, USB flash drive, memory card or CD and other media that can store program codes.
[0024] Preferably, the processor can be a general-purpose processor, including a central processing unit, a network processor, etc.; it can also be a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component.
[0025] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. An automated zabbix monitoring processing method, characterized in that: The following steps are involved: Step S1: Create a go program, which contains the alarm information obtained in Zabbix, the constants required for program operation, and parses JSON data; Step S2: upload the go program to the target server; Step S3: Run the go program on the target server: Zabbix outputs the alarm information after the alarm, and the go program pulls the alarm information and writes it into a txt file; Step S4: Run the recovery script: The go program detects whether the txt file has changed. If there is no change, it proves that the recovery script cannot handle it, and the alarm is manually processed. If there is a change, check whether the return value recorded in the txt file is the alarm to be restored by the recovery script. If so, the go program pulls the value in the file and uses the ansible automation tool to execute the recovery script on the corresponding server. The recovery script restores the alarm on the corresponding server according to the value in the file.
2. The automated zabbix monitoring processing method according to claim 1, characterized in that: The execution process of the go program is as follows: Step S3.1: Define the structure of the host slice and zabbix alarm information to be obtained, and map the defined structure fields with JSON keys; Step S3.2: Define constants in the main function. The constants include the URL, USER, PASS, and file path of the zabbix client. Step S3.3: Create a valid request payload, decode the payload, and process the required data; Step S3.4: Send API request: reference the http.NewRequest function to send the request and pass in the request body; Step S3.5: Set the username and password, and reference the http.Client function to send a request to the zabbix client to obtain the response information returned by the zabbix client; Step S3.6: After the zabbix client returns the value, it parses the JSON value and returns the parsed value; Step S3.7: Reference the OS function to create a txt file and write the return value into the txt file.
3. The automated zabbix monitoring processing method according to claim 2, characterized in that: The host includes two values: one is the ID of the monitoring alarm, and the other is the IP of the monitoring alarm.
4. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is executed by a processor to implement the automated zabbix monitoring processing method as described in any one of claims 1 to 3.
5. A device for automated zabbix monitoring processing, characterized in that: include: Processor and memory; The memory is used to store computer programs; The processor is connected to the memory and is used to execute a computer program stored in the memory so that the device for automated zabbix monitoring and processing performs the automated zabbix monitoring and processing method as described in any one of claims 1 to 3.