TOBE_COMPLETE # zabbix_midware v2.1(Don't read) ###### tags: `By_Ivan_note` zabbix_midware is a service, designed for connecting AIOPs and Zabbix. This document explains how to use the program, and shows the architecture of the midware framework. [TOC] ## Hierarchy and Architecture modules and contents: ```perl= - midware_zabbix/ # main modules : - zabbix_main.py - zabbix_query.py - zabbix_UI.py # function module, portable designed: - daemonize.py - j2c.py # config and log file: - midware.conf - .midware.log # intended output directory: - probe/ ``` Brief workflow: ![](https://i.imgur.com/1U57WXy.png) ## Usage ### Run Directly ```bash $ python3 zabbix_main.py -h usage: zabbix_main.py [-h] [options] {start,stop,restart,daemon} Transform Zabbix data to AIOPs format. positional arguments: {start,stop,restart,daemon} Instruction for the program optional arguments: -h, --help show this help message and exit -c path, --config path config file path -l path, --log path log file path -o path, --out_Dir path output directory path -p path, --pidfile path pidfile path -v logging level ``` Zabbix midware supports running in both background and foreground. If "start" was given to the argument input, the midware would then run without daemonize. The program could be stopped by keyboard interruption. ```bash $ python3 zabbix_main.py start Starting... Daemonize_off * Serving Flask app "zabbix_UI" (lazy loading) * Environment: production ... * Running on http://0.0.0.0:8880/ (Press CTRL+C to quit) ``` If "daemon" was given to the arguemnt input, Daemonize process would then activates; the program would be detached from the current user and terminal, running in the background. ```bash $ python3 zabbix_main.py daemon Starting... ``` A daemonized-midware can only be stopped by execute the main module with "stop" argument. ```bash $ python3 zabbix_main.py stop Stopping... Daemon_has_stoped ``` ### Run by systemd ```perl= # /usr/lib/systemd/system/zabbix-midware.service [Unit] Description=Midware between zabbix and AIOPs [Service] ExecStart=/home/ivan/midware_zabbix/zabbix_main.py -o /home/ivan/share2/probe start Restart=on-abnormal RestartSec=3min [Install] WantedBy=multi-user.target ``` ### Output According to AIOPs' regulation, datas should be grouped by their datetime (one group for each minute), and stored in distinct files. >zabbix_probe@${datetime}.csv The format of the datetime is set to "%Y%m%d_%H_%M" by default. ### UI Endpoints A sub-thread would be created when starting the midware, dedicated to http request handling. ``` RESTapi endpoint index: [GET] 1. ip:port/zabbix/show [POST] 2. ip:port/zabbix/update [POST] 3. ip:port/zabbix/delete ``` "Show" would return the current setting of the midware. "Update" and "Delete" would add or remove the item from the table with the "itemID" given by the form. For example: ```bash $ curl -X POST --data "itemID=32142" localhost:8880/delete {"message":"delete complete"} $ curl -X POST --data "itemID=32142" localhost:8880/update {"message":"update complete"} ``` If the given "itemID" is invalid or the item does not exist, the endpoint would then return with error code "0". ```bash {"error":{"code":0,"message":"EMPTY_RESULT:item_DNE"}} ``` ## Config Structure ```json! { "zabbix": { "host": "Zabbix ip and port", "user": "#@#@#@", "password": "@#@#@#", "UI_address": { "host": "0.0.0.0 / endpoint for", "port": 8880 } }, "probe": { "zabbix_probe": { "($dtype0)": { "($itemID)": { "name": "Item Name, defined on the zabbix webpage", "probe_server": "Defined by the name of 'Zabbix Application'" } }, "($dtype3)":{ "($itemID)": { "name":"another item", "probe_server": "another source" } } } } } ``` ## Framework Design ![](https://i.imgur.com/5U8viQk.jpg) ### Alternitive tool: Systemd ```clike [Unit] Description=Sample Application [Service] Type=simple ExecStart=/opt/test.py Restart=always [Install] WantedBy=multi-user.target ``` Benefits: 1. Stable 2. Service handling: Auto-Reboot, Status, etc 3. Proccess monitor (recording status and logs)