(Last Updated On: June 16, 2018)

Cacti is a great monitoring and Graphing tool that runs on many Unix and Linux Operating systems. We recently wrote a guide on How to Install and configure Cacti Server on Ubuntu 18.04. This guide on How to Import templates on Cacti is based on that article.

What is Cacti Templates

You can unleash the real strength of Cacti is by using templates. There are three different types of templates with the basic Cacti installation:

  • Data Templates –  A data template provides a skeleton for an actual data source
  • Graph Templates – A  graph template provides a skeleton for an actual graph
  • Host Templates – Instead of abstracting the fields of a host, a host template allows you to associate graph templates and data queries with a given host type.

How to Import templates on Cacti

Templates on Cacti are imported using import_package.php script available on /usr/share/cacti/cli/ directory.

# /usr/share/cacti/cli/import_package.php --help
Cacti Import Template Utility, Version 1.1.38, Copyright (C) 2004-2018 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.

The syntax is:

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

Downloading Cacti Templates

Cacti Templates for Host, Graph, and Data are available on https://docs.cacti.net/templates. You can download a template you want from the link to the local system where Cacti server runs. Let’s consider an example to install SNMP Generic device template

# 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    

2018-06-16 13:31:20 (242 KB/s) - ‘template:package:generic_snmp_device.xml.gz’ saved [42614/42614]

Once the package is downloaded, install it like below:

# /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 [new]

After the installation, Data Query XML files are copied  into Cacti snmp_queries directory:

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

Let’s also add Local Linux system

# 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]

Then import it using the command:

# /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]
Device Template
[success] Local Linux Machine [new]

This last package comes with the following templates –  linux, UNIX, net-snmp, load, cpu, memory, context switches, interrupts, interface, errors, disk, logins, processes, 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

Confirm that the templates have been imported on Cacti Admin interface. Login using admin user account, then go to:

Console > Templates