如何在Cacti上导入模板

时间:2020-02-23 14:30:33  来源:igfitidea点击:

Cacti是一个出色的监视和绘图工具,可在许多Unix和Linux操作系统上运行。

本指南有关如何在Cacti上导入模板。

什么是Cacti模板

我们可以使用模板来发挥Cacti的真正优势。基本的Cacti安装有三种不同类型的模板:数据模板数据模板为实际的数据源提供框架图形模板图表模板为实际的图源提供框架主机模板主机模板不是抽象主机的字段允许我们将图形模板和数据查询与给定的主机类型相关联。

如何在Cacti上导入模板

使用可在/usr/share/cacti/cli /目录中使用的import_package.php脚本导入Cacti上的模板。

# /usr/share/cacti/cli/import_package.php --help
Cacti Import Template Utility, Version 1.1.38, Copyright (C) 2004-2016 The Cacti Group

usage: import_package.php --filename=[filename] [--remove-orphans] [--with-profile] [--profile-id=N

A utility to allow signed Cacti Packages to be imported from the command line.

Required:
--filename The name of the gziped package file to import

Optional:
--preview Preview the Template Import, do not import
--with-profile Use the default system Data Source Profile
--profile-id=N Use the specific profile id when importing
--remove-orphans If importing a new version of the template, old
elements will be removed, if they do not exist
in the new version of the template.

语法为:

# /usr/share/cacti/cli/import_package.php --filename=[filename]

下载Cacti模板

可以在https://docs.cacti.net/templates上获得用于主机,图形和数据的Cacti模板。我们可以从链接下载所需的模板到运行Cacti服务器的本地系统。让我们以安装SNMP通用设备模板的示例为例

# wget https://docs.cacti.net/_media/template:package:generic_snmp_device.xml.gz
2018-06-16 13:31:19  https://docs.cacti.net/_media/template:package:generic_snmp_device.xml.gz
Resolving docs.cacti.net (docs.cacti.net) 104.28.9.127, 104.28.8.127, 2400:cb00:2048:1::681c:97f,
Connecting to docs.cacti.net (docs.cacti.net)|104.28.9.127|:443 connected.
HTTP request sent, awaiting response 200 OK
Length: 42614 (42K) [application/octet-stream]
Saving to: Template:package:generic_snmp_device.xml.gz鈥?
template:package:generic_snmp_device.xml.g 100%[======================================================================================>]  41.62K   242KB/s    in 0.2s

下载软件包后,按如下所示安装它:

# /usr/share/cacti/cli/import_package.php filename=./generic_snmp_device.xml.gz
Read 42614 bytes of Package data
Import Results
Cacti has imported the following items for the Package:
Package Files
/usr/share/cacti/site/resource/snmp_queries/interface.xml [written]
CDEF
[success] Turn Bytes into Bits [unchanged]
GPRINT Preset
[success] Normal [unchanged]
Data Input Method
[success] Unix - Ping Host [updated]
Table: data_input, Column: input_string, New Value: 'perl <path_cacti>/scripts/ping.pl <hostname>', Old Value: 'perl <path_cacti>/scripts/ping.pl <ip>'
Table: data_input_fields, Column: data_name, New Value: 'hostname', Old Value: 'ip'
[success] Get SNMP Data [unchanged]
[success] Get SNMP Data (Indexed) [updated]
Table: data_input_fields, Column: allow_nulls, New Value: 'on', Old Value: ''
Data Template
[success] Unix - Ping Host [new]
[success] SNMP - Generic OID Template [new]
[success] Interface - Traffic [new]
[success] Interface - Errors/Discards [new]
[success] Interface - Unicast Packets [new]
[success] Interface - Non-Unicast Packets [new]
Graph Template
[success] Unix - Ping Latency [new]
[success] SNMP - Generic OID Template [new]
[success] Interface - Traffic (bits/sec) [new]
[success] Interface - Errors/Discards [new]
[success] Interface - Unicast Packets [new]
[success] Interface - Non-Unicast Packets [new]
[success] Interface - Traffic (bytes/sec) [new]
[success] Interface - Traffic (bits/sec, 95th Percentile) [new]
[success] Interface - Traffic (bits/sec, Total Bandwidth) [new]
[success] Interface - Traffic (bytes/sec, Total Bandwidth) [new]
[success] Interface - Multicast Packets (Legacy) [new]
[success] Interface - Broadcast Packets (Legacy) [new]
Data Query
[success] SNMP - Interface Statistics [new]
Device Template
[success] Generic SNMP Device

安装之后,将数据查询XML文件复制到Cacti snmp_queries目录中:

# ls -1 /usr/share/cacti/resource/snmp_queries/
host_disk.xml
index.php
interface.xml
net-snmp_devio.xml
net-snmp_disk.xml

我们还添加本地Linux系统

# wget https://docs.cacti.net/_media/template:package:local_linux_machine.xml.gz -O local_linux_machine.xml.gz
2018-06-16 14:09:08 https://docs.cacti.net/_media/template:package:local_linux_machine.xml.gz
Resolving docs.cacti.net (docs.cacti.net) 104.28.9.127, 104.28.8.127, 2400:cb00:2048:1::681c:87f, 
Connecting to docs.cacti.net (docs.cacti.net)|104.28.9.127|:443 connected.
HTTP request sent, awaiting response 200 OK
Length: 19511 (19K) [application/octet-stream]
Saving to: ‘local_linux_machine.xml.gz’

local_linux_machine.xml.gz 100%[======================================================================================>] 19.05K 109KB/s in 0.2s 

2018-06-16 14:09:08 (109 KB/s) - ‘local_linux_machine.xml.gz’ saved [19511/19511]

然后使用以下命令将其导入:

# /usr/share/cacti/cli/import_package.php filename=local_linux_machine.xml.gz
Read 19511 bytes of Package data
Import Results
Cacti has imported the following items for the Package:
Package Files
/usr/share/cacti/site/resource/script_queries/unix_disk.xml [written]
/usr/share/cacti/site/scripts/query_unix_partitions.pl [written]
CDEF
[success] Total All Data Sources [unchanged]
[success] Multiply by 1024 [unchanged]
[success] Total All Data Sources, Multiply by 1024 [unchanged]
GPRINT Preset
[success] Normal [unchanged]
[success] Exact Numbers [unchanged]
[success] Load Average [updated]
Table: graph_templates_gprint, Column: gprint_text, New Value: '%4.2lf', Old Value: '%8.2lf'
Data Input Method
[success] Unix - Get System Processes [unchanged]
[success] Unix - Get Load Average [unchanged]
[success] Unix - Get Logged In Users [unchanged]
[success] Linux - Get Memory Usage [unchanged]
[success] Get Script Data (Indexed) [unchanged]
Data Template
[success] Unix - Processes [new]
[success] Unix - Load Average [new]
[success] Unix - Logged in Users [new]
[success] Linux - Memory - Free [new]
[success] Linux - Memory - Free Swap [new]
[success] Unix - Hard Drive Space [new]
Graph Template
[success] Unix - Processes [new]
[success] Unix - Load Average [new]
[success] Unix - Logged in Users [new]
[success] Linux - Memory Usage [new]
[success] Unix - Available Disk Space [new]
Data Query
[success] Unix - Get Mounted Partitions [new]

最后一个软件包带有以下模板linux,UNIX,net-snmp,load,cpu,内存,上下文切换,中断,接口,错误,磁盘,登录名,进程,iops

# wget https://docs.cacti.net/_media/template:package:netsnmp_device.xml.gz -O netsnmp_device.xml.gz
# /usr/share/cacti/cli/import_package.php --filename=./netsnmp_device.xml.gz

确认模板已在Cacti Admin界面上导入。使用管理员用户帐户登录,然后转到:

控制台>模板