Loading

zabbix_manage的使用

实验环境:

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 |

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

 

 

posted @ 2021-04-24 22:59  云起时。  阅读(404)  评论(0编辑  收藏  举报