author:headsen chen
date: 2018-11-10 10:08:38
背景:zabbix的硬件監控架構已經部署完成,接下來就是創建主機這一步,2400台主機如果采用一台台的創建和關聯模板就太慢了。硬件監控不用於agent方式,agent的方式可以采用添加自動發現的規則來自動注冊。
硬件監控采用 server端通過SNMP服務去各個物理機的管理卡上去抓相應的硬件信息。所以無法通過自動發現規則來添加主機
1,手動添加一台主機,導出該主機的xml配置信息:
<zabbix_export>
<version>
4.0
</version>
<date>
2018
-
11
-09T11:
12
:04Z</date>
<groups>
<group>
<name>Linux servers</name>
</group>
<group>
<name>北京dell服務器組</name>
</group>
</groups>
<hosts>
<host>
<host>
1.1
.
1.1
</host>
<name>
1.1
.
1.1
</name>
<description/>
<proxy>
<name>
10
-
20
-
42
-
2
</name>
</proxy>
<status>
0
</status>
<ipmi_authtype>-
1
</ipmi_authtype>
<ipmi_privilege>
2
</ipmi_privilege>
<ipmi_username/>
<ipmi_password/>
<tls_connect>
1
</tls_connect>
<tls_accept>
1
</tls_accept>
<tls_issuer/>
<tls_subject/>
<tls_psk_identity/>
<tls_psk/>
<templates>
<template>
<name>Template Dell iDrac SNMPV2</name>
</template>
</templates>
<groups>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<
interface
>
<
default
>
1
</
default
>
<type>
2
</type>
<useip>
1
</useip>
<ip>
1.1
.
1.1
</ip>
<dns/>
<port>
161
</port>
<bulk>
1
</bulk>
<interface_ref>if1</interface_ref>
</
interface
>
</interfaces>
<applications/>
<items/>
<discovery_rules/>
<httptests/>
<macros/>
<inventory/>
</host>
</hosts>
</zabbix_export>
|
2,分析該xml文件,解析結構分為以下幾個標簽
<zabbix_export>
<version>
4.0
</version>
<date>
2018
-
11
-09T11:
12
:04Z</date>
<groups>
<group> ...
</group>
</groups>
<hosts>
...
</hosts>
</zabbix_export>
|
其中:hosts 標簽就每台添加的主機的信息,我們每次添加的主機,都是再寫一個 <hosts> 標簽
3,將2400台主機的IP寫入dell-ip-list 文件里,並放入centos6.8的系統里,以便通過shell進行操作
4,構思:利用for循環實現生成2400台主機的xml文件
第一步:文件頭部不動的部分:
# cat >> dell.xml <<EOF
<?xml version=
"1.0"
encoding=
"UTF-8"
?>
<zabbix_export>
<version>
4.0
</version>
<date>
2018
-
11
-09T11:
12
:04Z</date>
<groups>
<group>
<name>Linux servers</name>
</group>
<group>
<name>北京dell服務器組</name>
</group>
</groups>
<hosts>
EOF
|
第二步:寫一個單 <hosts>標簽的模板文件:
# cat >> plate.xml <<
<host>
<host>
1.1
.
1.1
</host>
<name>
1.1
.
1.1
</name>
<description/>
<proxy>
<name>
10
-
20
-
42
-
2
</name>
</proxy>
<status>
0
</status>
<ipmi_authtype>-
1
</ipmi_authtype>
<ipmi_privilege>
2
</ipmi_privilege>
<ipmi_username/>
<ipmi_password/>
<tls_connect>
1
</tls_connect>
<tls_accept>
1
</tls_accept>
<tls_issuer/>
<tls_subject/>
<tls_psk_identity/>
<tls_psk/>
<templates>
<template>
<name>Template Dell iDrac SNMPV2</name>
</template>
</templates>
<groups>
<group>
<name>Linux servers</name>
</group>
</groups>
<interfaces>
<
interface
>
<
default
>
1
</
default
>
<type>
2
</type>
<useip>
1
</useip>
<ip>
1.1
.
1.1
</ip>
<dns/>
<port>
161
</port>
<bulk>
1
</bulk>
<interface_ref>if1</interface_ref>
</
interface
>
</interfaces>
<applications/>
<items/>
<discovery_rules/>
<httptests/>
<macros/>
<inventory/>
</host>
EOF
|
第三步:利用for循環生成2400個物理機的hosts標簽文件的腳本: xml.sh
第四步:運行該腳本,生成dell.xml 的文件
# sh xml.sh
|
5,將dell.xml文件導入
靜等15分鍾。之后刷新頁面,得到如下頁面證明配置成功: