Cacti supports a number of command line scripts. You will find them in the
./cli directory. The CLI scripts fall into multiple categories, they include:
- Automation - Utilities to help automate adding objects to Cacti
- Maintenance - Utilities to help keep Cacti healthy
- Repair - Utilities to help with repairing Cacti database components
- Repair/Migration - Utilities to help with repairing or migrating Cacti components
- Install/Upgrade - Utilities to help with installing and upgrading Cacti
In the table below, each of the CLI scripts are categories and explained briefly.
| Script | Category | Description |
|---|---|---|
| add_device.php | Automation | Allows adding a Device to Cacti. Most device options are included. Some plugin options may not. |
| change_device.php | Automation | Allows editing device details such as IP/Poller association |
| add_data_query.php | Automation | Allows adding a Data Query to Cacti. |
| add_graph_template.php | Automation | Allows adding a Graph Template to Cacti. |
| add_graphs.php | Automation | Allows adding a Graph to Cacti. |
| add_perms.php | Automation | Allows adding permissions to Cacti. |
| add_tree.php | Automation | Allows adding tree's tree branches and objects to Cacti Trees. |
| copy_user.php | Maintenance | Allows creating new users from Templates |
| add_datasource.php | Automation | Allows adding a Data Source to a Device from a Data Template. |
| add_group.php | Automation | Allows adding a user group, or group permissions, to Cacti. |
| add_group_perms.php | Automation | Allows adding group permissions to graphs, trees, devices or graph templates. |
| add_site.php | Automation | Allows adding a Site with its address, timezone and GPS details, geocoding the address if asked, and mapping matching Devices to it. |
| apply_automation_rules.php | Automation | Executes Cacti automation rules for Devices selected by id, hostname or description. |
| clone_device_template.php | Automation | Clones parts of a Device Template so that the clone does not interfere with the Device Template it was based on. |
| host_update_template.php | Automation | Updates Cacti Devices with the latest Device Template. |
| remove_device.php | Automation | Allows removing Devices selected by description, IP address or id. |
| remove_graphs.php | Automation | Allows removing Graphs, selected by Graph Template and optionally Device Template, Device, Graph or Graph name regular expression. |
| Script | Category | Description |
|---|---|---|
| input_whitelist.php | Maintenance | To onboard new Data Input Methods when using Cacti in a high security environment where new Data Input Methods must always be vetted before enabling for general use. |
| poller_graphs_reapply_names.php | Maintenance | Allows selecting re-running of Cacti's suggested values engine for Graphs |
| poller_reindex_hosts.php | Maintenance | Batch method to re-index Cacti Devices |
| analyze_database.php | Maintenance | Analyzes all Cacti tables rebuilding their index cardinality. Important to run after having added large numbers of Devices and Graphs to Cacti. |
| audit_graph_template_inputs.php | Maintenance | Reports graph template input integrity findings without changing database state. |
| batchgapfix.php | Maintenance | Fills gaps in Graphs over a time range. |
| float_rrdfiles.php | Maintenance | Floats a range in selected Graphs using the RRDtool dump and import utility. |
| poller_data_sources_reapply_names.php | Maintenance | Recalculates Data Source names for the selected Data Templates. |
| poller_replicate.php | Maintenance | Fully synchronizes Remote Data Collectors. |
| refresh_csrf.php | Maintenance | Deprecated. It no longer rotates anything and is kept only so that scripts that call it keep working. |
| removespikes.php | Maintenance | Removes spikes from an RRDfile. Defaults are taken from the Cacti database when no options are given. |
| reorder_data_query.php | Maintenance | Re-orders Cacti Data Queries for a Device or the whole system in batch mode. |
| rrdresize.php | Maintenance | Analyses and reassigns Data Template settings into RRDfiles, backing up the original RRDfiles. |
| show_perms.php | Maintenance | Audits database permissions by scanning the Cacti database and reporting the permissions it finds. |
| update_heartbeat.php | Maintenance | Updates RRDfile heartbeats and the Cacti database to match. |
| Script | Category | Description |
|---|---|---|
| poller_output_empty.php | Repair | Processes the rows left in Cacti's poller output table and writes them to the RRDfiles. Deprecated. |
| rebuild_poller_cache.php | Repair | Batch process to re-populate Cacti's poller cache. NOTE: This script can run for a very long time on large systems. |
| repair_database.php | Repair | Utility to look for common problems with old Cacti databases where objects were removed while still in use. Also rapairs all tables after a system crash. |
| repair_graphs.php | Repair | Utility to repair Cacti Graphs whose structure is damaged due to legacy Cacti behavior. |
| repair_templates.php | Repair | Utility to repair Cacti Templates whose structure was damaged due to legacy Cacti behavior. |
| push_out_hosts.php | Repair | Deprecated. Use rebuild_poller_cache.php. |
| remove_broken_graphs.php | Repair | Removes broken Graphs, which are Graphs that lack Data Sources. |
| Script | Category | Description |
|---|---|---|
| audit_database.php | Repair/Migration | Script to audit your Cacti schema, and repair any tables that don't match the stock Cacti schema. It will also upgrade the Cacti schema and run plugin upgrade functions. This is a good migration tool to move database from old versions of Cacti. |
| convert_tables.php | Repair/Migration | Convert all tables from their current form to the Cacti preferred table type, collation and charset |
| splice_rrd.php | Migration | Utility that allows two RRDfiles to be merged, and also assists with resampling an old RRDfile to a new RRA configuration, for example moving a Cacti system from 5 minute polling to 1 minute polling. |
| fix_mediumint.php | Repair/Migration | Increases the size of key Cacti columns for systems with over a million graphs that have been in service for years. |
| migrate_poller.php | Repair/Migration | Moves Devices off a given Data Collector to another one. |
| Script | Category | Description |
|---|---|---|
| import_package.php | Install/Upgrade | Import a signed Cacti package from a gzipped file. |
| install_cacti.php | Install/Upgrade | Script to install Cacti from a raw schema. Used primarily by distribution maintainers. |
| md5sum.php | Install/Upgrade | Utility to verify the MD5SUM of a file. |
| sqltable_to_php.php | Install/Upgrade | Utility for Plugin Developers to create an object for creating tables in plugins. |
| structure_rra_paths.php | Install/Upgrade | Utility to convert a system from a flat directory path to a heirarchial one. Important for certain file systems that don't perform well when there are tens or hundreds of thousands of files in a single directory. |
| upgrade_database.php | Install/Upgrade | Utility to upgrade a Cacti database from a point in time to the current release. Or even rerun the database upgrade from a point in the past to catch up with changes. This script should be used in conjunction with the audit_database.php --repair --upgrade option. |
| fetch_plugins.php | Install/Upgrade | Gathers the latest official plugins from the Cacti Group GitHub site and prepares them for loading and install. |
| genkey.php | Install/Upgrade | Generates a Package Author certificate and key information based upon an ssh key pair. |
| genmanifest.php | Install/Upgrade | Generates a Package Author manifest.properties file for a directory of Package files. |
| import_template.php | Install/Upgrade | Imports Cacti Templates from an XML file. |
| plugin_manage.php | Install/Upgrade | Installs, enables, disables or uninstalls one or more Cacti plugins. |
| version.php | Install/Upgrade | Shows version information, including the development upgrade version. |
NOTE: Package maintainers may wish to utilize the CLI methods of install_cacti.php and upgrade_database.php to perform in place installations and upgrades.
In the sub-sections below, we will demonstrate the use of a few of these CLI scripts.
Caution: In the following examples, several numbers are shown as output from various scripts. They will vary between different installations. So don't bother, if your numbers will vary.
The poller cache holds all commands that cacti will issue during the polling
process in an internal format. It is possible, to review the current contents of
the poller cache by visiting System Utilities, View Poller Cache. It is
possible to apply filters to this view; it will show up like
Localhost - Hard Drive Space Script Server: /var/www/html/cacti/scripts/ss_host_disk.php ss_host_disk 127.0.0.1 1 1:161:500:somesecret:::::: get total 6
RRD: /var/www/html/cacti/rra/localhost_hdd_total_61.rrd
Localhost - Load Average Script: /usr/bin/perl /var/www/html/cacti/scripts/loadavg_multi.pl
RRD: /var/www/html/cacti/rra/localhost_load_1min_5.rrd
Localhost - Logged in Users Script: /usr/bin/perl /var/www/html/cacti/scripts/unix_users.pl
RRD: /var/www/html/cacti/rra/localhost_users_6.rrd
Localhost - Memory - Free Script: /usr/bin/perl /var/www/html/cacti/scripts/linux_memory.pl MemFree:
RRD: /var/www/html/cacti/rra/localhost_mem_buffers_3.rrd
Localhost - Memory - Free Swap Script: /usr/bin/perl /var/www/html/cacti/scripts/linux_memory.pl SwapFree:
RRD: /var/www/html/cacti/rra/localhost_mem_swap_4.rrd
Localhost - mtaReceivedMessages SNMP Version: 1, Community: somesecret, OID: .1.3.6.1.2.1.28.1.1.1.1
RRD: /var/www/html/cacti/rra/localhost_mtareceivedmessages_47.rrd
Localhost - mtaReceivedVolume SNMP Version: 1, Community: somesecret, OID: .1.3.6.1.2.1.28.1.1.4.1
RRD: /var/www/html/cacti/rra/localhost_mtareceivedvolume_49.rrdThere are several circumstances, that may result in the poller cache being out
of sync. An example would be a change of the name of a script used in a
Data Input Method. This change is not automatically propagated to the poller
cache. It is required, to run php -q rebuild_poller_cache.php manually.
Calling the script with the parameter --help yields
shell>php -q rebuild_poller_cache.php --help
Cacti Rebuild poller cache Tool, Version 1.3.0 Copyright (C) 2004-2026 The Cacti Group
usage: rebuild_poller_cache.php [--host-id=N] [--host-template-id=N] [--data-template-id=N] [--debug]
Cacti's repopulate poller cache tool. This CLI script will
repopulate poller cache for all or specified hosts.
This utility will run in parallel with the given number of threads.
If threads argument is not specified, value is derived from the number of processor cores.
In case of a detection problem, 2 threads are used.
Optional:
--threads=N - The number of threads to use to repopulate
--host-id=N - Run for a specific Device
--host-template-id=N - Run for a specific Device Template
--data-template-id=N - Run for a specific Data Template
--debug - Display verbose output during execution
System Controlled:
--type - The type and subtype of the rebuild poller cache process
--child - The thread id of the child processDebug mode lists the data sources items that are worked upon.
shell>php -q rebuild_poller_cache.php -d
WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time
DEBUG: There are '38' data source elements to update.
DEBUG: Data Source Item '1' of '38' updated
DEBUG: Data Source Item '2' of '38' updated
DEBUG: Data Source Item '3' of '38' updated
DEBUG: Data Source Item '4' of '38' updated
....Without any parameter, some dots are shown as progress indicators.
shell>php -q rebuild_poller_cache.php
WARNING: Do not interrupt this script. Rebuilding the Poller Cache can take quite some time
......................................
shell>Caution
Rebuilding the poller cache interferes with the poller operation. Make sure that the poller is not running and will not start during a rebuild operation
Re-Indexing is required only for SNMP/Script Data Queries. Remember, that when
applying a Data Query to a Host, a Re-Index Method has to be chosen. This
reindex method governs the automatic re-indexing based on specific events.
| Re-Index Method | Description |
|---|---|
| Uptime Goes Backwards | Refers to a system reboot |
| Index Count Changed | Refers to a change of the number of indexed items |
| Verify All Fields | The sort field value of each index is checked for changes |
If the method is set to Uptime Goes Backwards, Cacti will detect if the target
has been rebooted by querying sysUptime (.1.3.6.1.2.1.1.3.0). If the current
value for the uptime is lower than the previous one (uptime goes backwards), a
reboot is assumed and a re-index is performed
If the method is set to Index Count Change, e.g. the number of interfaces,
without checking sysUptime. It is of particular interest in cases, where indexed
entries may change without the need of a reboot. As modern operating systems
seldom require reboots for system configuration changes, you may want to
consider this setting for many cases (e.g. creating of a new filesystem without
a reboot). The index to be considered is defined by the according XML file.
If the method is set to Verify All Fields, the value of the data query's sort
field is checked for every index. This is of particular interest e.g. in cases,
where the index is non-numeric (e.g. a MAC address). It should be noted that in
the 1.0 and 1.1 releases, this method was found to be broken and has been
corrected since 1.2.
If you feel the need for manual re-indexing, you may run it from CLI. Calling
the script with the parameter --help yields
shell>php -q poller_reindex_hosts.php --help
Cacti Reindex hosts Tool, Version 1.3.0 Copyright (C) 2004-2026 The Cacti Group
usage: poller_reindex_hosts.php --id=[host_id|all] [--qid=[ID|all]]
This utility will run in parallel with the given number of threads.
If threads argument is not specified, value is derived from the number of processor cores.
In case of a detection problem, 2 threads are used.
Optional:
[--host-descr=[description]] [--debug]
--id=host_id - The host_id to have data queries reindexed or 'all' to reindex all hosts
--qid=query_id - Only index on a specific data query id; defaults to 'all'
--host-descr=description - The host description to filter by (SQL filters acknowledged)
--threads=N - The number of threads to use to repopulate
--force - Force Graph and Data Source Suggested Name Re-mapping for all items
--debug - Display verbose output during execution
System Controlled:
--type - The type and subtype of the rebuild poller cache process
--child - The thread id of the child processRunning it in debug mode for the host with id=2 may yield
shell>php -q poller_reindex_hosts.php -id=2 -d
WARNING: Do not interrupt this script. Reindexing can take quite some time
DEBUG: There are '1' data queries to run
DEBUG: Data query number '1' host: '2' SNMP Query Id: '1' starting
DEBUG: Data query number '1' host: '2' SNMP Query Id: '1' endingA silent run for all devices is issued by
shell>php -q poller_reindex_hosts.php -id=All
WARNING: Do not interrupt this script. Reindexing can take quite some time
.....shell>You may run this script against a specific data query id using
--qid=[data query id] like
shell>php -q poller_reindex_hosts.php --id=All --qid=1 -d
WARNING: Do not interrupt this script. Reindexing can take quite some time
DEBUG: There are '3' data queries to run
DEBUG: Data query number '1' host: '1' SNMP Query Id: '1' starting
DEBUG: Data query number '1' host: '1' SNMP Query Id: '1' ending
DEBUG: Data query number '2' host: '2' SNMP Query Id: '1' starting
DEBUG: Data query number '2' host: '2' SNMP Query Id: '1' ending
DEBUG: Data query number '3' host: '15' SNMP Query Id: '1' starting
DEBUG: Data query number '3' host: '15' SNMP Query Id: '1' endingIt is possible, to select a host based on its host description using
--host-descr=[host description]. It is allowed to apply an SQL filter
expression for the description like --host-descr=some%descr. Use this
parameter in conjunction with either --id=[host id] or --qid=[data query id]
or both:
shell>php -q poller_reindex_hosts.php --id=All --qid=1 --host-descr=ga%f -d
WARNING: Do not interrupt this script. Reindexing can take quite some time
DEBUG: There are '1' data queries to run
DEBUG: Data query number '1' host: '2' SNMP Query Id: '1' starting
DEBUG: Data query number '1' host: '2' SNMP Query Id: '1' endingCaution
Re-Indexing interferes with the poller operation. Make sure that the poller is not running and will not start during a reindex operation
During normal poller operation, all retrieved results are intermediately stored in the table named poller_output After execution of cmd.php or Spine, this table holds all results. The poller.php finally issues all rrdtool update operations. Thus, after polling has completed, the table should be empty.
Conditions may arise, where the table is not (completely) emptied. The most
often known issue is lack of php memory. In those cases, the table is bigger
than the php memory size, thus not all items are handled correctly. If that
issue occurs, you may save all pending updates after increasing PHP memory
appropriately by running this very script. Calling the script with the
parameter --help yields
shell>php -q poller_output_empty.php --help
Cacti Process Poller Output Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: poller_output_empty.php
A utility to process the poller output table. This tool is deprecated but should work.You see, no parameter is required for operating successfully. Under normal circumstances, running this script should yield
shell>php -q poller_output_empty.php
There were 0 RRD updates made this pass
shell>In case, you hit the poller process or if the table was really not fully processed, you may find
shell>php -q poller_output_empty.php
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.04
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.00 r:0.05
OK u:0.00 s:0.01 r:0.06
There were 21 RRD updates made this pass
shell>If logging level verbosity was switched to DEBUG you may find additional debug
messages that usually show up in cacti.log
For a general understanding of suggested names used with data queries, please
see ?. Be aware, that changes to the Suggested Names section of a data query
will not automatically be propagated to all existing graphs. This is, where
poller_graphs_reapply_names.php drops in. Calling the script with the parameter
--help yields
shell>php -q poller_graphs_reapply_names.php --help
Cacti Reapply graph Names Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: poller_graphs_reapply_names.php --host-id=[id|all][N1,N2,...] [--filter=[string] [--debug]
A utility to reapply Cacti Graph naming rules to existing Graphs in bulk.
Required:
--host-id=id|all|N1,N2,... - The devices id, 'all' or a comma delimited list of id's
Optional:
--filter=string - A Graph Template name or Graph Title to search for
--debug - Display verbose output during executionAssume a situation, where the suggested names where changed for the standard
data query named SNMP - Get Mounted Partitions. In this case, you will want to
rework all graphs for this data query only. A verbose run will yield
shell>php -q poller_graphs_reapply_names.php -id=All -d -s="Used space"
WARNING: Do not interrupt this script. Interrupting during rename can cause issues
DEBUG: There are '6' Graphs to rename
DEBUG: Graph Name 'Localhost - Used Space - Memory Buffers' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - Memory Buffers'
DEBUG: Graph Name 'Localhost - Used Space - Real Memory' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - Real Memory'
DEBUG: Graph Name 'Localhost - Used Space - Swap Space' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - Swap Space'
DEBUG: Graph Name 'Localhost - Used Space - /' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - /'
DEBUG: Graph Name 'Localhost - Used Space - /sys' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - /sys'
DEBUG: Graph Name 'Localhost - Used Space - /boot' starting
DEBUG: Graph Rename Done for Graph 'Localhost - Used Space - /boot'Notice the miss-spelling of the word “Space”. The -s= option is not case
sensitive.
For use and understanding the limitation of this script, it is of importance to read User Management
Calling the script with the parameter --help yields
shell>php -q copy_user.php --help
Cacti Copy User Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: copy_user.php [-h|-v] [-e=<email>] [-f=<full name>] [-l=<yes/no>] [-p=<salt>]
[-r=<yes/no>] [-t=<secret>] <template user> <new user>
A utility to copy on local Cacti user and their settings to a new one.
NOTE: It is highly recommended that you use the web interface to copy users as
this script will only copy Local Cacti users.
Required options:
<template user> the user id to copy
<new user> the user id to create
Optional:
-e=<email address> the email address to set
-f=<full name> the full name to set
-l=<yes/no> whether new user should be locked
-p=<salt> the salt to prefix to hashed username
-r=<yes/no> whether new password must be changed
-t=<secret> the secret to use for TFA
NOTE: When copying a user using this script, TFA is automatically disabledNow let's create a new user Harry Potter as follows
shell>php -q copy_user.php guest "Harry Potter"
Template User..: guest
New User.......: Harry Potter
Copying User...: <N> extra option(s)
Salt...: <salt>
User copied successfullyFind the results of this program call at User Management
| User Name** | Full Name | Enabled | Realm | Default Graph Policy | Last Login |
|---|---|---|---|---|---|
| admin | Administrator | Yes | Local | ALLOW | Sunday, October 07, 2007 14:59:32 |
| guest | Guest Account | Yes | Local | ALLOW | N/A |
| Harry Potter | Guest Account | Yes | Local | ALLOW | N/A |
While it is an easy task to add a new device from the panels, this would be a
tedious task for creating dozens of hundreds of devices in one turn. This is,
where the script add_device.php comes in. First, let's have a look at the
whole list of features it provides. Calling the script with the parameter
--help yields
shell>php -q add_device.php --help
Cacti Add Device Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_device.php --description=[description] --ip=[IP] --template=[ID] [--notes="[]"] [--disable]
[--poller=[id]] [--site=[id] [--external-id=[S]] [--proxy] [--threads=[1]
[--avail=[ping]] --ping_method=[icmp] --ping_port=[N/A, 1-65534] --ping_timeout=[N] --ping_retries=[2]
[--version=[0|1|2|3]] [--community=] [--port=161] [--timeout=500] [--retries=3] [--options=0]
[--username= --password=] [--authproto=] [--privpass= --privproto=] [--context=] [--engineid=]
[--quiet]
Required:
--description the name that will be displayed by Cacti in the graphs
--ip self explanatory (can also be a FQDN)
Optional:
--proxy if specified, allows adding a second host with same ip address
--template 0, is a number (read below to get a list of templates)
--location '', The physical location of the Device.
--notes '', General information about this host. Must be enclosed using double quotes.
--external-id '', An external ID to align Cacti devices with devices from other systems.
--disable 0, 1 to add this host but to disable checks and 0 to enable it
--poller 0, numeric poller id that will perform data collection for the device.
--site 0, numeric site id that will be associated with the device.
--threads 1, numeric number of threads to poll device with.
--avail pingsnmp, [ping][none, snmp, pingsnmp, pingorsnmp]
--ping_method tcp, icmp|tcp|udp
--ping_port '', 1-65534
--ping_retries 2, the number of time to attempt to communicate with a host
--ping_timeout N, the ping timeout in milliseconds. Defaults to database setting.
--version 1, 0|1|2|3, snmp version. 0 for no snmp
--community '', snmp community string for snmpv1 and snmpv2. Leave blank for no community
--port 161
--timeout 500, The default snmp timeout
--retries 3, The number of snmp retries
--options 0, The SNMP Recovery Template Options set to use
--security-level '', noAuthNoPriv|authNoPriv|authPriv, security level for snmpv3
--username '', snmp username for snmpv3
--password '', snmp password for snmpv3
--authproto '', [None]|MD5|SHA|SHA224|SHA256|SHA392|SHA512$, snmp authentication protocol for snmpv3
--privpass '', snmp privacy passphrase for snmpv3
--privproto '', [None]|DES|AES|AES128|AES192|AES192C|AES256|AES256C$, snmp privacy protocol for snmpv3
--context '', snmp context for snmpv3
--engineid '', snmp engineid for snmpv3
--max_oids 10, 1-60, the number of OIDs that can be obtained in a single SNMP Get request
--bulk_walk -1, 1-60, the bulk walk chunk size that will be used for bulk walks. Use -1 for auto-tune.
List Options:
--list-host-templates
--list-communities
--quiet - batch mode value returnWow, that's quite a lot of options. To better understand it's use, let's first stick to the listing options
shell>php -q add_device.php --list-host-templatesThe command lists the templates installed in your database. Use those IDs rather than assuming the IDs from another installation.
Why are those Host Templates of such importance for this script? Well, when
using this script to add a new device, there are 2 required parameters. The
description and the device ip address are of course left to you. But for
assigning the correct Host Template Id, you should first know the correct id
of that very parameter. For the purpose of this chapter we assume to add a
device that will be associated to a ucd/net SNMP Host, so the id of 3 is
required.
If you do not want to associate the host to any Host Template Id, known as
host template None, provide the parameter --template=0. If you omit this
parameter, the Template set in the Device Defaults settings is used.
shell>php -q add_device.php --list-communities
Known SNMP Communities: (community)
public
snmp-getOf course, your list will vary
Now, let's set up the most basic command to add a new device. The description
shall be "Device Add Test", the ip will be given as a FQDN,
router.mydomain.com. As a SNMP enabled device, surely a community string has
to be provided; in this case given as public. In total, this makes the
following command
shell>php -q add_device.php --description="Device Add Test" --ip="router.mydomain.com" --template=3 --community="public"
Adding Device Add Test (router.mydomain.com) as "ucd/net SNMP Host" using SNMP v1 with community "public"
Success - new device-id: (11)Go to Devices to see the result:
| Description** | Graphs | Data Sources | Status | Hostname | Current (ms) | Average (ms) | Availability |
|---|---|---|---|---|---|---|---|
| Device Add Test | 0 | 0 | Unknown | router.mydomain.com | 0 | 0 | 100 |
Use any other combination of parameters in the same way as via the web browser
console. You may want to remember the new device id, 11 in this case, for the
next steps.
It is recommended to maintain data query associations by maintaining host templates. Each time, a data query is added to a host template, it will automatically associated with all hosts related to that very host template. The data query will be executed as well; this way the snmp cache will be filled with all values related to that query.
Nevertheless, it is sometimes suitable to manually associate a certain data
query with a single host only without changing any host template. This is, where
the script add_data_query.php comes in. First, let's have a look at the whole
list of features it provides. Calling the script with the parameter --help
yields
shell>php -q add_data_query.php --help
Cacti Add Data Query Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_data_query.php --host-id=[ID] --data-query-id=[dq_id] --reindex-method=[method] [--quiet]
Required Options:
--host-id the numerical ID of the host
--data-query-id the numerical ID of the data_query to be added
--reindex-method the reindex method to be used for that data query
0|None = no reindexing
1|Uptime = Uptime goes Backwards
2|Index = Index Count Changed
3|Fields = Verify all Fields
List Options:
--list-hosts
--list-data-queries
--quiet - batch mode value return
If the data query was already associated, it will be reindexed.Let's first stick to the listing options
shell>php -q add_data_query.php --list-hosts
Known Devices: (id, hostname, template, description)
1 127.0.0.1 8 Localhost
11 router 3 router.mydomain.comshell>php -q add_data_query.php --list-data-queries
Known SNMP Queries: (id, name)
1 SNMP - Interface Statistics
2 ucd/net - Get Monitored Partitions
3 Karlnet - Wireless Bridge Statistics
4 Netware - Get Available Volumes
6 Unix - Get Mounted Partitions
7 Netware - Get Processor Information
8 SNMP - Get Mounted Partitions
9 SNMP - Get Processor Informationshell>php -q add_data_query.php --host-id=11 --data-query-id=1 --reindex-method=fields
Success - Host (11: router.mydomain.com) data query (1: SNMP - Interface Statistics) reindex method (3: Verify All Fields)This example shows the use of a string "fields" for specifying the reindex
method. As given by the help text, the use of the numeric value of "3" would
have given the exact same result. When visiting the device edit panel, you will
find non-zero values for the data query status column, e.g. Success [41 Items,
5 Rows].
It is recommended to maintain graph template associations by maintaining host templates. Each time, a graph template is added to a host template, it will automatically associated with all hosts related to that very host template.
Nevertheless, it is sometimes suitable to manually associate a certain graph
template with a single host only without changing any host template. This is,
where the script add_graph_template.php comes in. First, let's have a look at
the whole list of features it provides. Calling the script with the parameter
--help yields
shell>php -q add_graph_template.php --help
Cacti Add Graph Template Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_graph_template.php --host-id=[ID] --graph-template-id=[ID]
[--quiet]
Required:
--host-id the numerical ID of the host
--graph-template-id the numerical ID of the graph template to be added
List Options:
--list-hosts
--list-graph-templates
--quiet - batch mode value returnLet's first stick to the listing options
shell>php -q add_graph_template.php --list-hosts
Known Devices: (id, hostname, template, description)
1 127.0.0.1 8 Localhost
11 router 3 router.mydomain.comshell>php -q add_graph_template.php --list-graph-templates
Known Graph Templates: (id, name)
2 Interface - Traffic (bits/sec)
3 ucd/net - Available Disk Space
4 ucd/net - CPU Usage
5 Karlnet - Wireless Levels
6 Karlnet - Wireless Transmissions
7 Unix - Ping Latency
8 Unix - Processes
9 Unix - Load Average
10 Unix - Logged in Users
11 ucd/net - Load Average
...shell>php -q add_graph_template.php --host-id=11 --graph-template-id=7
Success: Graph Template associated for host: (11: router) - graph-template: (7: Unix - Ping Latency)You won't stop now as you've just created a device from cli. Surely, the task of
setting up graphs is the next step. This is done using add_graphs.php. Calling
the script with the parameter --help yields
shell>php -q add_graphs.php
Cacti Add Graphs Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_graphs.php --graph-type=[cg|ds] --graph-template-id=[ID]
--host-id=[ID] [--graph-title=title] [graph options] [--force] [--quiet]
Cacti utility for creating graphs via a command line interface. This utility can
create both Data Query (ds) type Graphs as well as Graph Template (cg) type graphs.
For Non Data Query (cg) Graphs:
[--input-fields='[data-template-id:]field-name=value ...'] [--force]
--input-fields If your data template allows for custom input data, you may specify that
here. The data template id is optional and applies where two input fields
have the same name.
--force If you set this flag, then new cg graphs will be created, even though they
may already exist
For Data Query (ds) Graphs:
--snmp-query-id=[ID] --snmp-query-type-id=[ID] --snmp-field=[SNMP Field]
--snmp-value=[SNMP Value] | --snmp-value-regex=[REGEX]
[--graph-title=S] Defaults to what ever is in the Graph Template/Data Template.
[--reindex-method=N] The reindex method to be used for that data query.
NOTE: If Data Query is already associated, the reindex method will NOT be changed.
--snmp-field-exclude=[SNMP Field] | --snmp-value-exclude=[REGEX]
Optionally used to exclude specific word/s in adding graphs
Valid --reindex-methods include
0|None = No reindexing
1|Uptime = Uptime goes Backwards (Default)
2|Index = Index Count Changed
3|Fields = Verify all Fields
NOTE: You may supply multiples of the --snmp-field and --snmp-value | --snmp-value-regex arguments.
NOTE2: You may supply multiples of the --snmp-field-exclude and --snmp-value-exclude arguments.
List Options:
--list-hosts
--list-graph-templates [--host-template-id=[ID]]
--list-input-fields --graph-template-id=[ID]
--list-snmp-queries
--list-query-types --snmp-query-id [ID]
--list-snmp-fields --host-id=[ID] [--snmp-query-id=[ID]]
--list-snmp-values --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Field]Like the graph creation from the console, this task is split into two different ones:
-
Associated Graph Templates: These are named
cggraph_type for this script. -
Associated Data Queries: These are named
dsgraph_type for this script. Additional SNMP parameters are required to define those graphs.
Caution
When running this cli script, caution must be taken to avoid typos. Sometimes, list options take an ending “s”, where the option for graph creation comes without “s”. Error messages are not issued to indicate this typo; instead you will see the general help screen.
The first list option, --list-hosts, is required only if you do not know the
id of the device you want to add graphs for. It will produce output as follows
shell>php -q add_graphs.php --list-hosts
Known Devices: (id, hostname, template, description)
...
11 router.mydomain.com 3 Device Add TestYou surely recognize the device we've just added?
The next list option, --list-graph-templates, is required to identify the
number of an Associated Graph Templates.
shell>php -q add_graphs.php --list-graph-templates
Known Graph Templates: (id, name)
2 Interface - Traffic (bits/sec)
3 ucd/net - Available Disk Space
4 ucd/net - CPU Usage
5 Karlnet - Wireless Levels
6 Karlnet - Wireless Transmissions
7 Unix - Ping Latency
8 Unix - Processes
9 Unix - Load Average
...We will need the graph template id of the ucd/net - CPU Usage template later.
So note the number 4 for it.
It is possible to reduce the listing to the graph templates associated with a
specific host template by using
--list-graph-templates --host-template-id=[id]. For a "ucd/net SNMP Host" this
yields
shell>php -q add_graphs.php --list-graph-templates --host-template-id=3
Known Graph Templates: (id, name)
4 ucd/net - CPU Usage
11 ucd/net - Load Average
13 ucd/net - Memory Usage...First task is to find all id's for available data queries.
shell>php -q add_graphs.php --host-id=2 --list-snmp-queries
Known SNMP Queries: (id, name)
1 SNMP - Interface Statistics
2 ucd/net - Get Monitored Partitions
3 Karlnet - Wireless Bridge Statistics
4 Netware - Get Available Volumes
6 Unix - Get Mounted Partitions
7 Netware - Get Processor Information
8 SNMP - Get Mounted Partitions
9 SNMP - Get Processor InformationFor standard interface statistics, we note the id of 1
Next task is to find the query_type as done by issuing
shell>php -q add_graphs.php --snmp-query-id=1 --list-query-types
Known SNMP Query Types: (id, name)
2 In/Out Errors/Discarded Packets
3 In/Out Non-Unicast Packets
4 In/Out Unicast Packets
9 In/Out Bytes (64-bit Counters)
13 In/Out Bits
14 In/Out Bits (64-bit Counters)
16 In/Out Bytes
20 In/Out Bits with 95th Percentile
21 In/Out Bits with Total Bandwidth
22 In/Out Bytes with Total Bandwidth
23 In/Out Bits 1 min
24 In/Out Bits 1 min (64-bit Counters)For a standard In/Out Bits type, we note the id of 13
Next issue is to select the SNMP Field that shall be used for a new graph.
shell>php -q add_graphs.php --host-id=11 --list-snmp-fields
Known SNMP Fields for host-id 11: (name)
ifAlias
ifDescr
ifHwAddr
ifIndex
ifIP
ifName
ifOperStatus
ifSpeed
ifTypeFor our graph, we will use the field ifOperStatus to select the correct
interfaces.
In general, you will next determine the values available for the SNMP Field,
in our case ifOperStatus. This is done by
shell>php -q add_graphs.php --host-id=11 --snmp-field=ifOperStatus --list-snmp-values
Known SNMP Values for Field ifOperStatus and host-id 11: (name)
Down
UpThis is no surprise, of course. Now, all parameters required for creating a new graph are determined.
We will create a graph for ucd/net - CPU Usage. Above, we've identified the
graph template it to be 4. In total, that makes up for the following command
shell>php -q add_graphs.php --host-id=11 --graph-type=cg --graph-template-id=4
Graph Added - Graph[39] - DS[63]Find the result when visiting Graph Management
| Graph Title** | Template Name | Size |
|---|---|---|
| Device Add Test - CPU Usage | ucd/net - CPU Usage | 120x500 |
If the graph template was not associated with that host before, it is now added to the list of Associated Graph Templates.
First, let's sum up the id's of all resources required for this task:
| Object | Value | Description |
|---|---|---|
| Graph Template Id | 2 | Interface - Traffic (bits/sec) |
| SNMP Query Id | 1 | SNMP - Interface Statistics |
| SNMP Query Type Id | 13 | In/Out Bits |
| SNMP Field | ifOperStatus | Field name |
| SNMP Value | Up | Field value |
This will make up for the following command
shell>php -q add_graphs.php --host-id=11 --graph-type=ds --graph-template-id=2 --snmp-query-id=1 --snmp-query-type-id=13 --snmp-field=ifOperStatus --snmp-value=Up
Graph Added - Graph[40] - DS[65]Find the result when visiting Graph Management
| Graph Title** | Template Name | Size |
|---|---|---|
| Device Add Test - CPU Usage | ucd/net - CPU Usage | 120x500 |
| Device Add Test - Traffic - lo | Interface - Traffic (bits/sec) | 120x500 |
If the data query was not associated with that host before, it is now added to
the list of Associated Graph Templates. In this case, the Re-Index Method of
Uptime Goes Backwards is defaulted if not given otherwise. You may provide a
different Re-Index Method by entering the optional parameter --reindex-method.
Now, that we've created some nice graphs, they should be put the graph trees.
This is done using add_tree.php. As you will notice soon, it is possible to
even add header items, hosts and graphs to a tree as well as adding a new tree
itself. But let us first see the help output. Calling the script with the
parameter --help yields
shell>php -q add_tree.php --help
Cacti Add Tree Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_tree.php --type=[tree|node] [type-options] [--quiet]
Tree options:
--name=[Tree Name]
--sort-method=[manual|alpha|natural|numeric]
Node options:
--node-type=[header|site|host|graph]
--tree-id=[ID]
[--parent-node=[ID] [Node Type Options]]
Header node options:
--name=[Name]
Site node options:
--site-id=[ID]
Host node options:
--host-id=[ID]
[--host-group-style=[1|2]]
(host group styles:
1 = Graph Template,
2 = Data Query Index)
Graph node options:
--graph-id=[ID]
List Options:
--list-sites
--list-hosts
--list-trees
--list-nodes --tree-id=[ID]
--list-graphs --host-id=[ID]The first try is dedicated to the list option --list-hosts. It goes like
shell>php -q add_tree.php --list-hosts
Known Devices: (id, hostname, template, description)
1 127.0.0.1 8 Localhost
2 gandalf 3 gandalf
...
11 router.mydomain.com 3 Device Add TestNow, let us --list-trees. It goes like
shell>php -q add_tree.php --list-trees
Known Trees: (id, sort method, name)
1 Manual Ordering (No Sorting) Default TreeListing all existed node of a given tree is done by
shell>php -q add_tree.php --list-nodes --tree-id=1
Known Tree Nodes: (type, id, parentid, title, attribs)
Device 7 N/A 127.0.0.1 Graph Template
Device 9 N/A gandalf Graph Template
Device 12 N/A gandalf Graph TemplateTo be able to add a Graph, the id of that very graph is required. Thus, a
--list-graphs --host-id=[id] option was implemented
shell>php -q add_tree.php --list-graphs --host-id=1
Known Device Graphs: (id, name, template)
1 Localhost - Memory Usage Linux - Memory Usage
2 Localhost - Load Average Unix - Load Average
3 Localhost - Logged in Users Unix - Logged in Users
4 Localhost - Processes Unix - Processes
5 Localhost - Traffic - eth0 Interface - Traffic (bits/sec, 95th Percentile)
33 Localhost - Used Space - Memory Buffers Host MIB - Available Disk Space
34 Localhost - Used Space - Real Memory Host MIB - Available Disk Space
35 Localhost - Used Space - Swap Space Host MIB - Available Disk Space
36 Localhost - Used Space - / Host MIB - Available Disk Space
37 Localhost - Used Space - /sys Host MIB - Available Disk Space
38 Localhost - Used Space - /boot Host MIB - Available Disk SpaceCacti comes with a single tree, named Default Tree. Console entry Trees is
used to add more trees. With add_tree.php, you may now do so from command line
as well:
shell>php -q add_tree.php --type=tree --name="Test Tree Add" --sort-method=manual
Tree Created - tree-id: (6)Verify this from console, Trees to find
Default Tree
Test Tree Addas expected.
Now, that a new tree has been created, you may want to add a new header to that very tree. Use
shell>php -q add_tree.php --type=node --node-type=header --tree-id=6 --name="Header Test"
Added Node node-id: (21)You will want to save the id returned if willing to add further nodes to exactly this new Header Node
Please note that it is currently not possible to add another header with the same options even if this is possible from console
But it is possible to add a subheader to an already defined header. Even in this
case, the name has to be unique
shell>php -q add_tree.php --type=node --node-type=header --tree-id=6 --parent-node=21 --name="SubHeader Test"
Added Node node-id: (22)We will distinguish several options adding a host to a tree. First, let's add a
Host directly to a tree. For this example, we use the tree id returned from
adding our own Test Tree Add known with id=6
shell>php -q add_tree.php --type=node --node-type=host --tree-id=6 --host-id=1
Added Node node-id: (23)As no --parent-node was given, this host is directly added to the tree itself.
If you wish to add a host to a (sub)header specify as follows
shell>php -q add_tree.php --type=node --node-type=host --tree-id=6 --parent-node=21 --host-id=1
Added Node node-id: (24)Both example come without a --host-group-style option. For those cases,
Graph Template host group style is default. Here's an example for providing a
host group option of Data Query Index instead
shell>php -q add_tree.php --type=node --node-type=host --tree-id=6 --parent-node=22 --host-id=1 --host-group-style=2
Added Node node-id: (25)Like above, instead of hosts it is possible to add a single graph to a tree or a
(sub)header of any tree. Of course, you again will require the id of the tree
and optionally of the header. This results in
shell>php -q add_tree.php --type=node --node-type=graph --tree-id=6 --graph-id=5
Added Node node-id: (26)Like above, this graph now was added directly to the tree itself. To add a graph to a header, proceed as follows
shell>php -q add_tree.php --type=node --node-type=graph --tree-id=6 --parent-node=21 --graph-id=5
Added Node node-id: (27)This script is used to specify special graph permissions to users. The list of
parameters is displayed as usual when calling the script with the parameter
--help
shell>php -q add_perms.php --help
Cacti Add Permissions Utility, Version 1.3.0 (DB: v1.3.0), Copyright (C) 2004-2026 The Cacti Group
usage: add_perms.php [ --user-id=[ID] ]
--item-type=[graph|tree|host|graph_template]
--item-id [--quiet]
Where item-id is the id of the object of type item-type
List Options:
--list-users
--list-trees
--list-graph-templates
--list-graphs --host-id=[ID]The list of users is retrieved by calling the script with the parameter
--list-users. It goes like
shell>php -q add_perms.php --list-users
Known Users: (id, username, full_name)
1 admin Administrator
3 guest Guest AccountThe list of trees is retrieved by calling the script with the parameter
--list-trees. It goes like
shell>php -q add_perms.php --list-trees
Known Trees: (id, sort method, name)
1 Manual Ordering (No Sorting) Default TreeThe list of available graph templates is retrieved by calling the script with
the parameter --list-graph-templates. It goes like
shell>php -q add_perms.php --list-graph-templates
Known Graph Templates: (id, name)
2 Interface - Traffic (bits/sec)
3 ucd/net - Available Disk Space
4 ucd/net - CPU Usage
5 Karlnet - Wireless Levels
6 Karlnet - Wireless Transmissions
7 Unix - Ping Latency
8 Unix - Processes
9 Unix - Load Average
...To be able to add a permissions to a specific Graph, the id of that very graph
is required. Thus, a --list-graphs --host-id=[id] option was implemented
shell>php -q add_perms.php --list-graphs --host-id=1
Known Device Graphs: (id, name, template)
1 Localhost - Memory Usage Linux - Memory Usage
2 Localhost - Load Average Unix - Load Average
3 Localhost - Logged in Users Unix - Logged in Users
4 Localhost - Processes Unix - Processes
5 Localhost - Traffic - eth0 Interface - Traffic (bits/sec, 95th Percentile)
33 Localhost - Used Space - Memory Buffers Host MIB - Available Disk Space
34 Localhost - Used Space - Real Memory Host MIB - Available Disk Space
35 Localhost - Used Space - Swap Space Host MIB - Available Disk Space
36 Localhost - Used Space - / Host MIB - Available Disk Space
37 Localhost - Used Space - /sys Host MIB - Available Disk Space
38 Localhost - Used Space - /boot Host MIB - Available Disk SpaceThere are various ways to define graph permissions to specific users. First, we
will add graph permissions for a given host. This is done using the parameter
--item-type=host as follows
shell>php -q add_perms.php --user-id=4 --item-type=host --item-id=1--user-id=4 must specify an existing users. Else, an error message will be
printed. As --item-type=host is given, --item-id=1 must specify a valid
host. Again, if no host with this specific id exists, an error message will be
printed. No output is produced on successful operations.
Next, we will add graph permissions for a given tree. This is done using the
parameter --item-type=tree as follows
shell>php -q add_perms.php --user-id=4 --item-type=tree --item-id=1--user-id=4 must specify an existing users. Else, an error message will be
printed. As --item-type=tree is given, --item-id=1 must specify a valid tree
(the Default Tree in this case). Again, if no tree with this specific id exists,
an error message will be printed. No output is produced on successful
operations.
Adding graph permissions for a given graph template is done using the parameter
--item-type=graph_template as follows
shell>php -q add_perms.php --user-id=4 --item-type=graph_template --item-id=25--user-id=4 must specify an existing users. Else, an error message will be
printed. As --item-type=graph_template is given, --item-id=1 must specify a
valid graph_template (the Interface - Traffic (bytes/sec) in this case). Again,
if no graph template with this specific id exists, an error message will be
printed. No output is produced on successful operations.
Last but not least we add graph permissions for a given graph by using the
parameter --item-type=graph as follows
shell>php -q add_perms.php --user-id=4 --item-type=graph --item-id=8--user-id=4 must specify an existing users. Else, an error message will be
printed. As --item-type=graph is given, --item-id=1 must specify a valid
graph. Again, if no graph template with this specific id exists, an error
message will be printed. No output is produced on successful operations.
Copyright (c) 2004-2026 The Cacti Group