实验环境:

zabbix server 172.16.1.121

访问端 172.16.1.122

55.1 说明

zabbix_manager是zabbix终端管理工具,可以在linux终端实现管理zabbix,同时

可以通过zabbix_manager实现对zabbix的一键初始化,一键导出报表(报表为excel)

等功能。

参考文档:

https://www.w3cschool.cn/zabbix_manager/zabbix_manager-z45f1zie.html

55.2 安装

在172.16.1.122节点上操作

# git clone https://github.com/BillWang139967/zabbix_manager.git

# cd zabbix_manager

# sh start.sh

55.3 配置连接zabbix server

# cat /etc/zabbix_tool/zabbix_config.ini

# 默认连接(可通过--profile选择连接的zabbix)

[zabbixserver]

# zabbix server IP

server = 172.16.1.121

# zabbix web 端口

port = 80

# zabbix web 管理员账号

user = Admin

# zabbix web 管理员密码

password = zabbix

#[bendi]

#server = 192.168.199.128

#port = 80

#user = admin

#password = zabbix

55.4 额外配置

搭建zabbix server时使用的lnmp,前端使用的apache时需要进行操作,即前端使用

nginx时则不需要进行以下操作。

将配置文件/etc/zabbix_tool/zabbix_setting.ini中的apache = False

改为apache=True

# cat /etc/zabbix_tool/zabbix_setting.ini

[web]

# lnmp(False),lamp(True)

apache = True

[report]

logo_show = True

55.5 测试

# zabbix_api hostgroup_get --table

zabbix_manager:[1.4.04]

+-------------+-----------------------------+

| hostgroupID | hostgroupName |

+-------------+-----------------------------+

| 5 | Discovered hosts |

| 7 | Hypervisors |

| 2 | Linux servers |

| 1 | Templates |

| 12 | Templates/Applications |

| 13 | Templates/Databases |

| 8 | Templates/Modules |

| 9 | Templates/Network devices |

| 10 | Templates/Operating systems |

| 16 | Templates/SAN |

| 11 | Templates/Server hardware |

| 15 | Templates/Telephony |

| 14 | Templates/Virtualization |

| 6 | Virtual machines |

| 4 | Zabbix servers |

+-------------+-----------------------------+

sum: 15

55.6 以主机群组的方式导出数据表

--hostgroupid # 选择特定主机组

--hostid # 选择特定主机

item支持模糊搜索

(1) 对监控名称进行分隔符分割后,进行完全匹配,如某个监控项名称为“CPU idle time” 则搜索CPU即可匹配,搜索CP,则不匹配

(2) --sign 设置分割符,默认以“ ”(空格)分割,如某个监控项名称为“CPU_idle_time” 则搜索CPU相关的监控项,同时加“--sign _”参数

1 在zabbix中查看主机组id号

2 创建导出excel报表的目录

# mkdir -p /test/

3 生成报表

# zabbix_api --report "ICMP loss" "2021-01-01 00:00:00" "2021-01-31 00:00:00" --table --hostgroupid 4 --table --xls /test/ICMP_LOSS.xls

zabbix_manager:[1.4.04]

主机:无

主机组:Zabbix servers

+ICMP loss-----------+-----------+-------+---------+--------+

| hostid | name | itemName | min | max | avg |

+--------+-----------+-----------+-------+---------+--------+

| 10354 | baidu.com | ICMP loss | 0.0 % | 100.0 % | 14.0 % |

+--------+-----------+-----------+-------+---------+--------+

# zabbix_api --report "ICMP ping" "2021-01-01 00:00:00" "2021-01-31 00:00:00" --table --hostgroupid 4 --table --xls /test/ICMP_PING.xls

zabbix_manager:[1.4.04]

主机:无

主机组:Zabbix servers

+ICMP ping-----------+-----------+-----+-----+-----+

| hostid | name | itemName | min | max | avg |

+--------+-----------+-----------+-----+-----+-----+

| 10354 | baidu.com | ICMP ping | 0 | 1 | 0 |

+--------+-----------+-----------+-----+-----+-----+

# zabbix_api --report "ICMP response time" "2021-01-01 00:00:00" "2021-01-31 00:00:00" --table --hostgroupid 4 --table --xls /test/ICMP_REPONSE_TIME.xls

zabbix_manager:[1.4.04]

主机:无

主机组:Zabbix servers

+ICMP response time--+--------------------+-------+------------------+----------+

| hostid | name | itemName | min | max | avg |

+--------+-----------+--------------------+-------+------------------+----------+

| 10354 | baidu.com | ICMP response time | 0.0 s | 0.258016666667 s | 0.0525 s |

+--------+-----------+--------------------+-------+------------------+----------+

# zabbix_api --report "ICMP" "2021-01-01 00:00:00" "2021-01-31 00:00:00" --table --hostgroupid 4 --table --xls /test/ICMP_RESULT.xls

zabbix_manager:[1.4.04]

主机:无

主机组:Zabbix servers

+ICMP----+-----------+--------------------+-------+------------------+----------+

| hostid | name | itemName | min | max | avg |

+--------+-----------+--------------------+-------+------------------+----------+

| 10354 | baidu.com | ICMP ping | 0 | 1 | 0 |

| 10354 | baidu.com | ICMP loss | 0.0 % | 100.0 % | 14.0 % |

| 10354 | baidu.com | ICMP response time | 0.0 s | 0.258016666667 s | 0.0525 s |

+--------+-----------+--------------------+-------+------------------+----------+

4 查看Excel报表

# sz -y /test/ICMP_RESULT.xls

5 补充

(1) 更改表头

# vim /usr/bin/zabbix_api

2558 export_xls = {"xls":"OFF",

2559 "xls_name":"ceshi.xls",

2560 "title":"OFF",

2561 "title_name":u"测试"

2562 }

(2) 给报表增加IP地址字段

# vim /usr/bin/zabbix_api

1) 如下图添加 host_info[3] 字段

2) 如下图添加相应的输出字段

2) 测试

# zabbix_api --report "ICMP" "2021-01-01 00:00:00" "2021-01-31 00:00:00" --table --hostgroupid 4 --table --xls /test/ICMP_RESULT.xls

zabbix_manager:[1.4.04]

主机:无

主机组:Zabbix servers

(u'10354', u'baidu.com', u'baidu.com', u'112.80.248.76', u'0')

(u'10084', u'Zabbix server', u'Zabbix server', u'127.0.0.1', u'1')

+ICMP----+-----------+---------------+--------------------+-------------------+-------------------+----------+

| hostid | name | hostip | itemName | min | max | avg |

+--------+-----------+---------------+--------------------+-------------------+-------------------+----------+

| 10354 | baidu.com | 112.80.248.76 | ICMP ping | 1 | 1 | 1 |

| 10354 | baidu.com | 112.80.248.76 | ICMP loss | 0.0 % | 0.0 % | 0.0 % |

| 10354 | baidu.com | 112.80.248.76 | ICMP response time | 0.0218666666667 s | 0.0446533333333 s | 0.0351 s |

+--------+-----------+---------------+--------------------+-------------------+-------------------+----------+

zabbix_manage的使用的更多相关文章

随机推荐

  1. git合并代码到主分支

    git合并login分支到master分支 1.首先查看源码状态 git status 2.添加到暂存区 git add . git status //添加到暂存区后再次查看源码状态 3.提交代码到本 ...

  2. CSS元素的盒类型

    一.css简介 CSS是Cascading Style Sheet的缩写,中文称层叠样式表.HTML中的元素都有着自己的属性和默认样式,CSS控制HTML内标签显示不同布局样式.控制对应html标签颜 ...

  3. shell脚本就是由Shell命令组成的执行文件,将一些命令整合到一个文件中,进行处理业务逻辑,脚本不用编译即可运行。它通过解释器解释运行,所以速度相对来说比较慢。

    shell脚本?在说什么是shell脚本之前,先说说什么是shell. shell是外壳的意思,就是操作系统的外壳.我们可以通过shell命令来操作和控制操作系统,比如Linux中的Shell命令就包 ...

  4. /etc/ssh/sshd_config ssh自动断 cent7

    vim /etc/ssh/sshd_config ClientAliveInterval 60ClientAliveCountMax 8630000 ClientAliveInterval 30Cli ...

  5. 2.7循环_while

    循环 目标 程序的三大流程 while 循环基本使用 break 和 continue while 循环嵌套 01. 程序的三大流程 在程序开发中,一共有三种流程方式: 顺序 -- 从上向下,顺序执行 ...

  6. Synchronize 和 volatile 的区别

    1. 在应用层面来讲 a. volatile是线程同步的轻量级实现,所以volatile的性能要比synchronize好: volatile只能用于修饰变量,synchronize可以用于修饰方法. ...

  7. Python3.x 基础练习题100例(71-80)

    练习71: 题目: 编写input()和output()函数输入,输出5个学生的数据记录. 程序: N = 5 # stu # num : string # name : string # score ...

  8. 达梦数据库产品支持技术学习分享_Week2

    本周主要从以下几个方面进行本人对达梦数据库学习的分享,学习进度和学习情况因人而异,仅供参考. 一.文本命令行工具使用的方法(Disql和dmfldr) 二.数据库备份 三.定时作业功能 四.系统表和动 ...

  9. [leetcode] 874. 行走机器人模拟(周赛)

    874. 行走机器人模拟 模拟 描述方向时有个技巧:int[][] dx = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; 分别存储机器人向上.右.下.左走时,坐标应该如何变 ...

  10. python中的时间戳和格式化之间的转换

    import time #把格式化时间转换成时间戳 def str_to_timestamp(str_time=None, format='%Y-%m-%d %H:%M:%S'): if str_ti ...