当前位置:网站首页>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 .
边栏推荐
- RT thread learning notes (VIII) -- start the elmfat file system based on SPI flash (Part 2)
- RT-Thread 学习笔记(八)---开启基于SPI Flash的elmfat文件系统(下)
- RT thread learning notes (VII) -- open the elmfat file system based on SPI flash (middle)
- 0x00007FFD977C04A8 (Qt5Sqld.dll)处(位于 a.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000010 时发生访问冲突
- 点击el-dropdown-item/@click.native
- 7-25 0-1背包 (50分)
- Flutter 防止科学计数并去除尾数无效0
- 2021-08-14 Sanzi chess
- 微信公众号开发 获取openid时报错40029 invalid code 问题的解决
- Constructors, method overloads, object arrays, and static
猜你喜欢

Issue 8: cloud native -- how should college students learn in the workplace
![[machine learning notes] [face recognition] deeplearning ai course4 4th week programming](/img/7e/9c0e88097b90c0c24ebf86f090805b.png)
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming
![[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)](/img/94/ff52b043320b6dea5ca1238e314de8.png)
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)

RT thread learning notes (VI) -- start the elmfat file system based on SPI flash (Part 1)

242.有效的字母异位词

很多人都不清楚自己找的是Kanban软件还是看板软件

RT thread learning notes (I) -- configure RT thread development environment

按二进制数中1的个数分类

二叉树的遍历 递归+迭代

35. 搜索插入位置
随机推荐
Sword finger offer (53): a string representing a numeric value
20210807#1 C语言程序结构
鹏哥C语言20210811程序结构作业
MFC中0x003b66c3 处有未经处理的异常: 0xC000041D: 用户回调期间遇到未经处理的异常
解决org.apache.commons.codec.binary.Base64爆红问题
使用flex实现左中右布局,中间自适应
11 handle "self assignment" in operator=
鹏哥C语言第七节课总结
RT thread learning notes (VIII) -- start the elmfat file system based on SPI flash (Part 2)
[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array
Bigdecimal的加减乘除、比较大小、向上向下取整 和 Bigdecimal的集合累加、判断BigDecimal是否有小数
Flutter集成极光推送
SQL Server 之Sql语句创建数据库
Build ARM embedded development environment
MultipartFil转为File
面试过程中,面试官是如何考察Rust工程师的水平?
display-inline+calc实现左中右布局,中间自适应
Sword finger offer (twenty): stack containing min function
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
RT thread learning notes (V) -- edit, download and debug programs