You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

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

[pastacode lang=”bash” manual=”%23%20wget%20https%3A%2F%2Fdocs.cacti.net%2F_media%2Ftemplate%3Apackage%3Ageneric_snmp_device.xml.gz%0A–2018-06-16%2013%3A31%3A19–%20%20https%3A%2F%2Fdocs.cacti.net%2F_media%2Ftemplate%3Apackage%3Ageneric_snmp_device.xml.gz%0AResolving%20docs.cacti.net%20(docs.cacti.net)…%20104.28.9.127%2C%20104.28.8.127%2C%202400%3Acb00%3A2048%3A1%3A%3A681c%3A97f%2C%20…%0AConnecting%20to%20docs.cacti.net%20(docs.cacti.net)%7C104.28.9.127%7C%3A443…%20connected.%0AHTTP%20request%20sent%2C%20awaiting%20response…%20200%20OK%0ALength%3A%2042614%20(42K)%20%5Bapplication%2Foctet-stream%5D%0ASaving%20to%3A%20%E2%80%98template%3Apackage%3Ageneric_snmp_device.xml.gz%E2%80%99%0A%0Atemplate%3Apackage%3Ageneric_snmp_device.xml.g%20100%25%5B%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3E%5D%20%2041.62K%20%20%20242KB%2Fs%20%20%20%20in%200.2s%20%20%20%20%0A%0A2018-06-16%2013%3A31%3A20%20(242%20KB%2Fs)%20-%20%E2%80%98template%3Apackage%3Ageneric_snmp_device.xml.gz%E2%80%99%20saved%20%5B42614%2F42614%5D%0A%0A” message=”” highlight=”” provider=”manual”/]

Once the package is downloaded, install it like below:

[pastacode lang=”bash” manual=”%23%20%2Fusr%2Fshare%2Fcacti%2Fcli%2Fimport_package.php%20–filename%3D.%2Fgeneric_snmp_device.xml.gz%0ARead%2042614%20bytes%20of%20Package%20data%0AImport%20Results%0ACacti%20has%20imported%20the%20following%20items%20for%20the%20Package%3A%0APackage%20Files%0A%2Fusr%2Fshare%2Fcacti%2Fsite%2Fresource%2Fsnmp_queries%2Finterface.xml%20%5Bwritten%5D%0ACDEF%0A%5Bsuccess%5D%20Turn%20Bytes%20into%20Bits%20%5Bunchanged%5D%0AGPRINT%20Preset%0A%5Bsuccess%5D%20Normal%20%5Bunchanged%5D%0AData%20Input%20Method%0A%5Bsuccess%5D%20Unix%20-%20Ping%20Host%20%5Bupdated%5D%0ATable%3A%20data_input%2C%20Column%3A%20input_string%2C%20New%20Value%3A%20%26%23039%3Bperl%20%26lt%3Bpath_cacti%26gt%3B%2Fscripts%2Fping.pl%20%26lt%3Bhostname%26gt%3B%26%23039%3B%2C%20Old%20Value%3A%20%26%23039%3Bperl%20%26lt%3Bpath_cacti%26gt%3B%2Fscripts%2Fping.pl%20%26lt%3Bip%26gt%3B%26%23039%3B%0ATable%3A%20data_input_fields%2C%20Column%3A%20data_name%2C%20New%20Value%3A%20%26%23039%3Bhostname%26%23039%3B%2C%20Old%20Value%3A%20%26%23039%3Bip%26%23039%3B%0A%5Bsuccess%5D%20Get%20SNMP%20Data%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Get%20SNMP%20Data%20(Indexed)%20%5Bupdated%5D%0ATable%3A%20data_input_fields%2C%20Column%3A%20allow_nulls%2C%20New%20Value%3A%20%26%23039%3Bon%26%23039%3B%2C%20Old%20Value%3A%20%26%23039%3B%26%23039%3B%0AData%20Template%0A%5Bsuccess%5D%20Unix%20-%20Ping%20Host%20%5Bnew%5D%0A%5Bsuccess%5D%20SNMP%20-%20Generic%20OID%20Template%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Errors%2FDiscards%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Unicast%20Packets%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Non-Unicast%20Packets%20%5Bnew%5D%0AGraph%20Template%0A%5Bsuccess%5D%20Unix%20-%20Ping%20Latency%20%5Bnew%5D%0A%5Bsuccess%5D%20SNMP%20-%20Generic%20OID%20Template%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20(bits%2Fsec)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Errors%2FDiscards%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Unicast%20Packets%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Non-Unicast%20Packets%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20(bytes%2Fsec)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20(bits%2Fsec%2C%2095th%20Percentile)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20(bits%2Fsec%2C%20Total%20Bandwidth)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Traffic%20(bytes%2Fsec%2C%20Total%20Bandwidth)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Multicast%20Packets%20(Legacy)%20%5Bnew%5D%0A%5Bsuccess%5D%20Interface%20-%20Broadcast%20Packets%20(Legacy)%20%5Bnew%5D%0AData%20Query%0A%5Bsuccess%5D%20SNMP%20-%20Interface%20Statistics%20%5Bnew%5D%0ADevice%20Template%0A%5Bsuccess%5D%20Generic%20SNMP%20Device%20%5Bnew%5D” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”bash” manual=”%23%20wget%20https%3A%2F%2Fdocs.cacti.net%2F_media%2Ftemplate%3Apackage%3Alocal_linux_machine.xml.gz%20-O%20local_linux_machine.xml.gz%0A–2018-06-16%2014%3A09%3A08–%20%20https%3A%2F%2Fdocs.cacti.net%2F_media%2Ftemplate%3Apackage%3Alocal_linux_machine.xml.gz%0AResolving%20docs.cacti.net%20(docs.cacti.net)…%20104.28.9.127%2C%20104.28.8.127%2C%202400%3Acb00%3A2048%3A1%3A%3A681c%3A87f%2C%20…%0AConnecting%20to%20docs.cacti.net%20(docs.cacti.net)%7C104.28.9.127%7C%3A443…%20connected.%0AHTTP%20request%20sent%2C%20awaiting%20response…%20200%20OK%0ALength%3A%2019511%20(19K)%20%5Bapplication%2Foctet-stream%5D%0ASaving%20to%3A%20%E2%80%98local_linux_machine.xml.gz%E2%80%99%0A%0Alocal_linux_machine.xml.gz%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20100%25%5B%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3E%5D%20%2019.05K%20%20%20109KB%2Fs%20%20%20%20in%200.2s%20%20%20%20%0A%0A2018-06-16%2014%3A09%3A08%20(109%20KB%2Fs)%20-%20%E2%80%98local_linux_machine.xml.gz%E2%80%99%20saved%20%5B19511%2F19511%5D%0A” message=”” highlight=”” provider=”manual”/]

Then import it using the command:

[pastacode lang=”bash” manual=”%23%20%2Fusr%2Fshare%2Fcacti%2Fcli%2Fimport_package.php%20–filename%3Dlocal_linux_machine.xml.gz%0ARead%2019511%20bytes%20of%20Package%20data%0AImport%20Results%0ACacti%20has%20imported%20the%20following%20items%20for%20the%20Package%3A%0APackage%20Files%0A%2Fusr%2Fshare%2Fcacti%2Fsite%2Fresource%2Fscript_queries%2Funix_disk.xml%20%5Bwritten%5D%0A%2Fusr%2Fshare%2Fcacti%2Fsite%2Fscripts%2Fquery_unix_partitions.pl%20%5Bwritten%5D%0ACDEF%0A%5Bsuccess%5D%20Total%20All%20Data%20Sources%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Multiply%20by%201024%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Total%20All%20Data%20Sources%2C%20Multiply%20by%201024%20%5Bunchanged%5D%0AGPRINT%20Preset%0A%5Bsuccess%5D%20Normal%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Exact%20Numbers%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Load%20Average%20%5Bupdated%5D%0ATable%3A%20graph_templates_gprint%2C%20Column%3A%20gprint_text%2C%20New%20Value%3A%20%26%23039%3B%254.2lf%26%23039%3B%2C%20Old%20Value%3A%20%26%23039%3B%258.2lf%26%23039%3B%0AData%20Input%20Method%0A%5Bsuccess%5D%20Unix%20-%20Get%20System%20Processes%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Unix%20-%20Get%20Load%20Average%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Unix%20-%20Get%20Logged%20In%20Users%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Linux%20-%20Get%20Memory%20Usage%20%5Bunchanged%5D%0A%5Bsuccess%5D%20Get%20Script%20Data%20(Indexed)%20%5Bunchanged%5D%0AData%20Template%0A%5Bsuccess%5D%20Unix%20-%20Processes%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Load%20Average%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Logged%20in%20Users%20%5Bnew%5D%0A%5Bsuccess%5D%20Linux%20-%20Memory%20-%20Free%20%5Bnew%5D%0A%5Bsuccess%5D%20Linux%20-%20Memory%20-%20Free%20Swap%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Hard%20Drive%20Space%20%5Bnew%5D%0AGraph%20Template%0A%5Bsuccess%5D%20Unix%20-%20Processes%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Load%20Average%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Logged%20in%20Users%20%5Bnew%5D%0A%5Bsuccess%5D%20Linux%20-%20Memory%20Usage%20%5Bnew%5D%0A%5Bsuccess%5D%20Unix%20-%20Available%20Disk%20Space%20%5Bnew%5D%0AData%20Query%0A%5Bsuccess%5D%20Unix%20-%20Get%20Mounted%20Partitions%20%5Bnew%5D%0ADevice%20Template%0A%5Bsuccess%5D%20Local%20Linux%20Machine%20%5Bnew%5D%0A” message=”” highlight=”” provider=”manual”/]

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

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF