czhtr 发表于 2019-1-20 07:03:23

zabbix中获取并导出图片

  之前搜了一下,几乎没有文章去说zabbix批量如何到处月报表中图片的。

通过zabbix来判断获取报表的url
  

  

  zabbix通过url来生成图片
  http://192.168.100.254/zabbix/chart_bar.php?config=3&title=%E6%8A%A5%E8%A1%A8+3&xlabel=&ylabel=&scaletype=3&avgperiod=2&showlegend=1&report_timesince=1414771200&report_timetill=1417363200&items=24690&hostids=10123&hostids=10124&hostids=10114&hostids=10119&hostids=10120&hostids=10122&hostids=10111&hostids=10112&hostids=10110&hostids=10126&hostids=10127&hostids=10121&palette=0&palettetype=0
以上链接为根据需求生成报表的时候,可以看到的连接,其中hostids【xxxx】便是主机,items【0】【itemid】=xxxxx为监控的项目。
report_timesince=1414771200&report_timetill=1417363200为开始时间和结束时间,显示为unix时间戳(以1970年1月1日0点0时0分为0开始)的形式
构建curl脚本
在windows下新建一个yuebao.bat文件,右键编辑,后开始写入脚本文件
  关键代码解释
  for /f %%i in (3.txt)do set %%i
  set a
  set b
  set"c=hostids=10123&hostids=10124&hostids=10114&hostids=10119&hostids=10120&hostids=10122&hostids=10111&hostids=10112&hostids=10110&hostids=10126&hostids=10127&hostids=10121"
curl -bcookie.txt -o cpu_idle.png -s -d"title=%E6%8A%A5%E8%A1%A8+3&xlabel=&ylabel=&scaletype=3&avgperiod=2&showlegend=1&report_timesince=%a%&report_timetill=%b%&items=24672&%c%&palette=0&palettetype=0"   http://192.168.100.254/zabbix/chart_bar.php?config=3
  for /f %%i in (3.txt)do set %%i这句为从外部3.txt文件中读取,读取内容为a和b的数字
  set a 和set b 设定两个变量来记录时间,a为起始时间,b为终止时间,windows脚本中引用变量的方式是%a%.
  设定变量c为主机群,如果需要新加主机,则在c中将新的主机的hostid写入。
  Curl –b cookie.txt 为引用cookie.txt中的内容,用来模拟登陆,不登陆是获取不到数值。
  获取cookie的方法为
  Curl –c cookie –d “request==&name=admin&password=zabbix&autologin=1&enter=Sign+in”http://192.168.100.254/zabbix/index.php
  -o xxx.png为存储图片,-d为 以post方式提出参数,最后访问的网址为http://192.168.100.254/zabbix/chart_bar.php?config=3
根据日期获取unix时间戳
  需要通过c语言编写程序,笔者使用的工具为dev-c++
  

  以下为程序源码
  #include
  #include
  #include
  #include
  using namespace std;
  int main()
  {
  FILE *fp;
  fp=fopen("D:\\3.txt","w");
  struct tm tm;
  time_t t_;
  char s;
  int x,y;
  cout
页: [1]
查看完整版本: zabbix中获取并导出图片