zoukankan      html  css  js  c++  java
  • 自学Zabbix9.4 zabbix low-level discover底层发现(zabbix批量部署必备)

    点击返回:自学Zabbix之路

    点击返回:自学Zabbix4.0之路

    点击返回:自学zabbix集锦

    自学Zabbix9.4 zabbix low-level discover底层发现(zabbix批量部署必备)

    1、Low level discovery介绍

      在配置Items的过程中,有时需要对类似的Items进行添加,这些Items具有一些共同的特性,表现为某些特定的参数是变量,而其他设置都是一样的。例如,一个程序有多个端口,需要对端口而皮质Items,再如磁盘分区、网卡的名称等,由于具有不确定性,故配置固定的Items出现无法通用的问题,因为在Zabbix2.0以后版本增加了Low level discovery功能。 

      Low level discovery的key可以对网卡、文件系统、SNMP OIDS进行自动发现,除此之外,还支持自定义功能。

    2、使用Low level discover实现自动发现tcp端口并监控

     2.1  定义发现脚本,输出结果需要是json格式

     1 [root@zabbix alertscripts]# cat port_discovery.py
     2 #!/usr/bin/env python
     3 __author__ = 'chuck'
     4 import os
     5 import json
     6 data = {}
     7 tcp_list = []
     8 port_list = []
     9 command = os.popen("netstat -lntp|egrep -v 'tcp6|snmp|ssh|10050'|awk -F '[ :]+' 'NR>=3 {print $5}'")
    10 for port in command:
    11 port_list.append(port.strip())
    12 for port in list(set(port_list)):
    13 port_dict = {}
    14 port_dict['{#TCP_PORT}'] = port
    15 tcp_list.append(port_dict)
    16 data['data'] = tcp_list
    17 jsonStr = json.dumps(data, sort_keys=True, indent=4)
    18 print jsonSt

        执行发现脚本,获取当前使用的tcp端口

     1 [root@zabbix alertscripts]# python port_discovery.py
     2 {
     3 "data": [
     4 {
     5 "{#TCP_PORT}": "3306"
     6 },
     7 {
     8 "{#TCP_PORT}": "4505"
     9 },
    10 {
    11 "{#TCP_PORT}": "4506"
    12 },
    13 {
    14 "{#TCP_PORT}": "10051"
    15 },
    16 {
    17 "{#TCP_PORT}": "25"
    18 }
    19 ]
    20 }

     2.2  配置端口发现的配置文件

        此步操作需要在agent主配置文件打开UserParameter=1

    1 [root@zabbix alertscripts]# cat ../zabbix_agentd.d/all_port.conf
    2 UserParameter=tcpportlisten,sudo python /etc/zabbix/alertscripts/port_discovery.py

     2.3  使用zabbix_get远程获取自动发现结果

     1 [root@zq-salt-zabbix alertscripts]# zabbix_get -s 10.4.200.2 -k tcpportlisten
     2 {
     3 "data": [
     4 {
     5 "{#TCP_PORT}": "3306"
     6 },
     7 {
     8 "{#TCP_PORT}": "4505"
     9 },
    10 {
    11 "{#TCP_PORT}": "4506"
    12 },
    13 {
    14 "{#TCP_PORT}": "10051"
    15 },
    16 {
    17 "{#TCP_PORT}": "25"
    18 }
    19 ]
    20 }

    2.4 问题提示

     此时可能出现you must have a tty to run sudo报错提示,将zabbix用户加入到sudo管理中,注释Defaults requiretty即可。 

    2.5 zabbix主界面添加自动发现模板

     Configuration ==》create template 

     
    选择Discovert rules==》create Discovert rules 
     

    2.6 zabbix主界面创建Item prototypes

    选择Item prototypes==》创建Item prototypes 

    2.7 zabbix主界面创建Trigger prototypes

    创建Trigger prototypes ==》create Trigger prototypes 

  • 相关阅读:
    73. Set Matrix Zeroes
    289. Game of Live
    212. Word Search II
    79. Word Search
    142. Linked List Cycle II
    141. Linked List Cycle
    287. Find the Duplicate Number
    260. Single Number III
    137. Single Number II
    Oracle EBS中有关Form的触发器的执行顺序
  • 原文地址:https://www.cnblogs.com/yaoyaojcy/p/8127424.html
Copyright © 2011-2022 走看看