当前位置:网站首页>Capture ZABBIX performance monitoring chart with selenium
Capture ZABBIX performance monitoring chart with selenium
2022-07-26 10:48:00 【Software testing wood wood】
Summary
As usual, let's start with an overview , Because the company has always used enterprise wechat , Just two days ago, all zabbix The alarm information of is received on wechat , I always feel that I'm not that good , Just think about adding a performance monitoring chart to the high-level alarm , In this way, we can probably understand the problem only by looking at the alarm information , No need to log in to zabbix Then look for information , Just because of this idea, I fell into the pit and stayed all day , Suddenly looking back, it's still too delicious , Next, post it for use Python Sign in zabbix And get the code of the corresponding alarm item monitoring diagram , After that, the complete code will be posted github in , Put the link on the simple book ~
Realize crawling
The following are the foundations :
1、 Sending of alarm information message in , Can send zabbix Macro variable for Item ID Information .
2、 according to Item ID, You can use special URL carry Item ID Information acquisition corresponding monitoring screenshot .
The following is the complete code to get the screenshot :
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# name image.py
from selenium import webdriver
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def get_item_graph(itemid,flag,eventid):
temp_name = "/tmp/"+eventid+".png"
#save_screenshot Only... Can be saved png Format picture , Therefore, the file name definition needs to be in png ending
driver = webdriver.PhantomJS("
/usr/local/zabbix-agent-ops/phantomjs-2.1.1/bin/phantomjs",service_log_path=os.path.devnull)
# Use PhantomJS Can simulate browser Visit
driver.get("http://127.0.0.1/zabbix/")
driver.set_window_size(640,480)
driver.find_element_by_id("name").send_keys("armo")
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_id("enter").click()
# Simulated access url, In the corresponding element element Enter the user name and password at click land
if flag:
driver.get("
http://127.0.0.1/zabbix/history.php?action=showgraph&fullscreen=1&itemids[]="+itemid)
else:
driver.get("
http://127.0.0.1/zabbix/history.php?action=showvalues&fullscreen=1&itemids[]="+itemid)
#flag If it is 1, It corresponds to Item There are corresponding graph obtain ; If it is 0, Then get the value of the latest period
driver.save_screenshot(temp_name)
# Save web content as png picture
driver.close()
driver.quit()
if __name__ == "__main__":
if len(sys.argv) > 1:
itemid = sys.argv[1] # The first parameter passed by the script Item ID
flag = sys.argv[2] # The second parameter passed by the script Flag, from zabbix database item and graph Corresponding table query of item Whether there is a corresponding graph, If so, pass 1 To script , No delivery 0
eventid = sys.argv[3] # The third parameter passed by the script Alarm information Event ID, Used to name png picture
get_item_graph(itemid,flag,eventid)
# The above three parameters are pre call script analysis zabbix After sending the message, get , It will be updated later article in
Problems encountered
1、 first session and cookies The preservation of , If you don't bring it after logging in cookies You cannot access the corresponding monitoring page , In the beginning, I chose requests modular , It feels relatively difficult , For me who just started, it's still selenium More appropriate , Don't have to consider session and cookies The problem of .
2、 Script in test The environment runs very well , The screenshot information is also very accurate , But there is something wrong with the online server .

It is obvious that the online environment returns , The previous paragraph is actually garbled . Checked all environments , Finally, it was found that the problem was that the online server was not installed and zabbix On the problem of font adaptation , Very helpless , Actually, I have to consider the problem of fonts , Alibaba cloud's servers are really lazy .
边栏推荐
猜你喜欢

如何组装一个注册中心?
![Error[Pe147]: declaration is incompatible with '错误问题](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[Pe147]: declaration is incompatible with '错误问题

在神州IV开发板上成功移植STemWin V5.22

在神州IV开发板上为STemWin 5.22加入触屏驱动

0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突

RT thread learning notes (VII) -- open the elmfat file system based on SPI flash (middle)
![[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits](/img/de/62fca587cde95110c2a967ca93eea5.png)
[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits

349. 两个数组的交集

Anaconda is used on vscode (the environment has been configured)

用两个栈实现队列
随机推荐
微信公众号消息通知 “errcode“:40164,“errmsg“:“invalid ip
RT-Thread 学习笔记(七)---开启基于SPI Flash的elmfat文件系统(中)
27.移除元素
[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array
MySQL速学-2021-09-01
C#halcon用户控件崩溃的一种处理方法
$router和$route的区别
使用flex实现左中右布局,中间自适应
c 语言中宏参数的字符串化跟宏参数的连接
剑指Offer(十):矩形覆盖
Anaconda is used on vscode (the environment has been configured)
MySQL quicklearn-2021-09-01
Constructors, method overloads, object arrays, and static
PLC与伺服电机连接
2021-08-13和鹏哥学C语言-数组
鹏哥C语言20210811程序结构作业
35. 搜索插入位置
RT thread learning notes (V) -- edit, download and debug programs
RT-Thread 学习笔记(五)---编辑、下载、调试程序
二叉树的遍历 递归+迭代