当前位置:网站首页>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 .
边栏推荐
猜你喜欢

PLC与伺服电机连接
![[dectectron2] follow the official demo](/img/aa/03e46897234c309415b336ac39b7d9.png)
[dectectron2] follow the official demo

一文详解Nodejs中fs文件模块与path路径模块

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

2021-08-12函数递归_和鹏哥学习C语言

20210807 1 c language program structure

Kali view IP address
![[notes on machine learning] [building a cyclic neural network and its application] deeplearning ai course5 1st week programming(keras)](/img/02/f85da2a2f2524fb034b17ed8d06692.png)
[notes on machine learning] [building a cyclic neural network and its application] deeplearning ai course5 1st week programming(keras)

35. 搜索插入位置

Disable usbjatg in Altium Designer
随机推荐
RT-Thread 学习笔记(一)---配置RT-Thread开发环境
344.反转字符串
Successfully transplanted stemwin v5.22 on Shenzhou IV development board
Sql Server 数据库之完整性约束
面试知识点
2021-08-12 function recursion_ Learn C language with brother Peng
Issue 8: cloud native -- how should college students learn in the workplace
Flutter集成极光推送
剑指Offer(二十):包含min函数的栈
Pengge C language 20210811 program structure operation
display-inline+calc实现左中右布局,中间自适应
PLC与伺服电机连接
Codepoint 58880 not found in font, aborting. flutter build apk时报错
242.有效的字母异位词
Oracle create index
Summary of the seventh class of pengge C language
剑指Offer(五十三):表示数值的字符串
剑指Offer(五十二):正则化表达式
Sword finger offer (twenty): stack containing min function
回到顶部的几种方案(js)