Files
Cactidocumentation/How-To-New-SNMP-Data-Queries.md
T
Thomas Vincent 741ad51355 docs: [1.2.x] refresh the front page, correct grammar and Markdown, and align plugin pages with their READMEs (#273)
* docs: [1.2.x] refresh the manual front page

The front page opened with version notes before saying what Cacti is,
used headings as sentences in the credits, and its table of contents
listed seven sections while the page has ten.

Open with a short description and a getting-started sequence, link the
website and forums, give the credits real headings, and list every
section in the table of contents in page order. Record Jeff Pasnak
under In Memoriam with a link to the 1.2.31 release announcement.
Correct label typos and wrap long entries with reference links.

Existing section anchors are unchanged, and every page is still linked.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs: [1.2.x] fix typos, unrendered headings and forum links

A check of every page linked from the front page found misspellings in
eleven pages, three Mactrack headings written without a space after the
hashes, which render as plain text, and two forum links still using
http.

Correct the spellings, add the missing space so the headings render,
and point the forum links at https, where they already redirect.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs: [1.2.x] align the plugin pages with the plugin READMEs

The supported plugins list and the Syslog and Mactrack pages had drifted
from the README and INFO files in the plugin repositories.

Update the descriptions that the READMEs contradict: Monitor's Thold
requirement, the Router Configs transfer methods, the ReportIt release
and Cacti versions, the WMI collection methods and its development
status, and NUT support in Apcupsd. Add the Syslog requirements, the
upgrade procedure, the dedicated database settings and the remote
collector settings, and correct the database grant and a misplaced
code fence. Add the Mactrack requirements and a short section on
history partitioning and ignored ports that links to the README.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs: [1.2.x] correct grammar, spelling and broken Markdown

A read of every page linked from the front page found grammar and
spelling errors throughout, and Markdown that does not render as
intended.

Correct grammar, spelling, punctuation and product-name capitalization
in 95 pages without changing headings, code blocks, link targets or
the meaning of the text. Repair the Markdown defects: a code fence in
the SSH tunnel how-to that never closed, malformed bold markers in the
user management and device defaults pages, a release notes table with
no blank line before it, split rows in the tree sorting table, and
LDAP list items missing their markers. Correct three interface labels
quoted with typos.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs: [1.2.x] correct statements that differ from the 1.2.x source

Reviewers of the linked pages flagged statements that looked wrong.
Each was compared with the Cacti 1.2.x source at 1523aa04b, and only
those the source or the page itself settles are changed.

Correct interface labels and option names (Index Count Changed,
Permissive, Not Selected, Utilities, the BCC description, the gear
icon for plugin install), the default Maximum Value of U for a new
data source item, the sysDescr object name, the PHP floor wording in
the requirements table, the Mactrack wildcard character and the
snmptrapd -On option. Repair cross-references, example values that
disagree with their commands, two table captions, a split list and
several sentences with missing words.

Statements the source does not settle are left as written.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-11-24 00:58:06 -08:00

19 KiB

SNMP Data Query Walkthrough

This walkthrough will show you how to implement a new SNMP Data Query. Assuming you know the SNMP table, the next steps show how to proceed.

Building Raw XML File

The starting point will be snmptable for a well-known table of the HOSTS MIB:

snmptable -c <community> -v 1 <host> HOST-RESOURCES-MIB::hrStorageTable
SNMP table: HOST-RESOURCES-MIB::hrStorageTable

 hrStorageIndex                hrStorageType hrStorageDescr hrStorageAllocationUnits hrStorageSize hrStorageUsed hrStorageAllocationFailures
          1     HOST-RESOURCES-TYPES::hrStorageOther Memory Buffers           1024 Bytes       1035356     59532               ?
          2       HOST-RESOURCES-TYPES::hrStorageRam    Real Memory           1024 Bytes       1035356    767448               ?
          3 HOST-RESOURCES-TYPES::hrStorageVirtualMemory     Swap Space           1024 Bytes       1048568   0               ?
          4     HOST-RESOURCES-TYPES::hrStorageFixedDisk          /           4096 Bytes       2209331    826154               ?
          5     HOST-RESOURCES-TYPES::hrStorageFixedDisk       /sys           4096 Bytes         0   0               ?
          6     HOST-RESOURCES-TYPES::hrStorageFixedDisk  /proc/bus/usb           4096 Bytes         0   0               ?
          7     HOST-RESOURCES-TYPES::hrStorageFixedDisk      /boot           1024 Bytes    102454      9029               ?
          8     HOST-RESOURCES-TYPES::hrStorageFixedDisk      /home           4096 Bytes    507988    446407               ?
          9     HOST-RESOURCES-TYPES::hrStorageFixedDisk     /usr/local           4096 Bytes    507988     17133               ?
         10     HOST-RESOURCES-TYPES::hrStorageFixedDisk       /var           4096 Bytes    507988    129429               ?
         11     HOST-RESOURCES-TYPES::hrStorageFixedDisk /var/lib/nfs/rpc_pipefs           4096 Bytes         0        0               ?**

This given, the first step will be the definition of an XML file based on those OIDs. So change to your <path_cacti>/resource/snmp_queries directory and create a file named hrStorageTable.xml. You may of course choose your own name, but for me it seems appropriate to take the name of the SNMP Table itself. Before doing so, it is necessary to identify the Index of that table. Without looking at the MIB file, simply perform

snmpwalk -c <community> -v 1 -On <host> HOST-RESOURCES-MIB::hrStorageTable|more
.1.3.6.1.2.1.25.2.3.1.1.1 = INTEGER: 1
.1.3.6.1.2.1.25.2.3.1.1.2 = INTEGER: 2
.1.3.6.1.2.1.25.2.3.1.1.3 = INTEGER: 3
.1.3.6.1.2.1.25.2.3.1.1.4 = INTEGER: 4
.1.3.6.1.2.1.25.2.3.1.1.5 = INTEGER: 5
.1.3.6.1.2.1.25.2.3.1.1.6 = INTEGER: 6
.1.3.6.1.2.1.25.2.3.1.1.7 = INTEGER: 7
.1.3.6.1.2.1.25.2.3.1.1.8 = INTEGER: 8
.1.3.6.1.2.1.25.2.3.1.1.9 = INTEGER: 9
.1.3.6.1.2.1.25.2.3.1.1.10 = INTEGER: 10
.1.3.6.1.2.1.25.2.3.1.1.11 = INTEGER: 11
.1.3.6.1.2.1.25.2.3.1.2.1 = OID: .1.3.6.1.2.1.25.2.1.1
.1.3.6.1.2.1.25.2.3.1.2.2 = OID: .1.3.6.1.2.1.25.2.1.2

The first index is .1.3.6.1.2.1.25.2.3.1.1.1, but the Index Base is .1.3.6.1.2.1.25.2.3.1.1. This OID is needed for the XML file:

<interface>
    <name>Get hrStoragedTable Information</name>
    <description>Get SNMP based Partition Information out of hrStorageTable</description>
    <index_order>hrStorageDescr:hrStorageIndex</index_order>
    <index_order_type>numeric</index_order_type>
    <oid_index>.1.3.6.1.2.1.25.2.3.1.1</oid_index>

    <fields>
        <hrStorageIndex>
            <name>Index</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.1</oid>
        </hrStorageIndex>
    </fields>
</interface>

Let's talk about the header elements

Field Description
Name Short Name; choose your own one if you want
Description Long Name
index_order tells us, which field shall be selected to index on; evaluated from left to right
index_order_type numeric instead of alphabetic sorting
oid_index the index of the table

There are more header elements, but for the sake of simplification, we'll stick to that for now.

Let's turn to the fields. They correspond to the columns of the snmptable. For debugging purposes it is recommended to start with the Index field first. This will keep the XML as tiny as possible. The <fields> section contains one or more fields, each beginning with <field_description> and ending with </field_description>. It is recommended but not necessary to take the textual representation of the OID or an abbreviation of that.

Field Description
Name Short Name
Method Walk or get (representing snmpwalk or snmpget to fetch the values)
Source Value = take the value of that OID as the requested value. Sounds ugly, but there are more options that we won't need for the purpose of this example
Direction Input (for values that may be printed as COMMENTs or the like). Output (for values that shall be graphed, e.g. COUNTERs or GAUGEs).
OID the real OID as numeric representation

Now save this file and let's turn to Cacti to implement this one. First, go to Data Queries to see

SNMP Table 1 - Data Query

and Add a new one:

SNMP Table 2 - Data Query

Fill in Short and Long Names at your wish. Enter the file name of the XML file and don't forget to choose Get SNMP Data (Indexed). Create to see

SNMP Table 3 - Data Query

It has now Successfully located XML file. But this does not mean that there are no errors. So let's go on with that. Turn to the Device you want to query and add the new Data Query as shown:

SNMP Table 1 - Device

Index Count was chosen on purpose as the Re-Index Method to tell Cacti to re-index not only on reboot but each time the Index Count (e.g. number of partitions) changed. When done, see the results as

SNMP Table 2 - Device

You'll notice that on my laptop there are 11 indices = 11 partitions. So the XML worked up to now! To make this clear, select Verbose Query to see:

SNMP Table Preview - Device

Insert all descriptive table columns

Now let's put all descriptive table columns into the SNMP Query XML file. This refers to

  • hrStorageType

  • hrStorageDescr

  • hrStorageAllocationUnits

I like to take the XML field names from the snmptable output, but this is not a must.

<interface>
    <name>Get hrStoragedTable Information</name>
    <description>Get SNMP based Partition Information out of hrStorageTable</description>
    <index_order>hrStorageDescr:hrStorageIndex</index_order>
    <index_order_type>numeric</index_order_type>
    <oid_index>.1.3.6.1.2.1.25.2.3.1.1</oid_index>

    <fields>
        <hrStorageIndex>
            <name>Index</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.1</oid>
        </hrStorageIndex>
        <hrStorageType>
            <name>Type</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.2</oid>

        </hrStorageType>
        <hrStorageDescr>
            <name>Description</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.3</oid>
        </hrStorageDescr>
        <hrStorageAllocationUnits>
            <name>Allocation Units (Bytes)</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.4</oid>
        </hrStorageAllocationUnits>
    </fields>
</interface>

The <name></name> information will later show up as a column heading. Don't forget to provide the correct base OIDs. Remember that the Index will always be appended to those OIDs, e.g. the first Description will be fetched from OID = .1.3.6.1.2.1.25.2.3.1.3.1 (that is base OID = .1.3.6.1.2.1.25.2.3.1.3 together with the appended index .1 will form the complete OID .1.3.6.1.2.1.25.2.3.1.3.1.).

Please notice that all fields that will yield descriptive columns only take <direction>input</direction>

If you have completed your work, turn to the Cacti web interface and select your host from the Devices list to see:

SNMP Table 3 - Devices

Select the little green circle next to our SNMP XML to update your last changes. Then you'll see something like:

SNMP Table 4 - Devices

When using Verbose Query, you'll now find

SNMP Table 5 - Devices

And clicking Create Graphs for this Device will result in

SNMP Table 6 - Devices

You're not supposed to really create graphs at this moment, because the XML is not yet complete. And you'll notice that the second column does not present very useful information. So it may be omitted in later steps.

Getting the Output Values

Now let's modify the XML again. As said earlier, the second column is not very meaningful, so let's drop it. To get the output values, I appended the last two XML field descriptions, see:

<interface>
    <name>Get hrStoragedTable Information</name>
    <description>Get SNMP based Partition Information out of hrStorageTable</description>
    <index_order>hrStorageDescr:hrStorageIndex</index_order>
    <index_order_type>numeric</index_order_type>
    <oid_index>.1.3.6.1.2.1.25.2.3.1.1</oid_index>

    <fields>
        <hrStorageIndex>
            <name>Index</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.1</oid>
        </hrStorageIndex>
        <hrStorageDescr>
            <name>Description</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.3</oid>
        </hrStorageDescr>
        <hrStorageAllocationUnits>
            <name>Allocation Units (Bytes)</name>
            <method>walk</method>
            <source>value</source>
            <direction>input</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.4</oid>
        </hrStorageAllocationUnits>
        <hrStorageSize>
            <name>Total Size (Units)</name>
            <method>walk</method>
            <source>value</source>
            <direction>output</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.5</oid>
        </hrStorageSize>
        <hrStorageUsed>
            <name>Used Space (Units)</name>
            <method>walk</method>
            <source>value</source>
            <direction>output</direction>
            <oid>.1.3.6.1.2.1.25.2.3.1.6</oid>
        </hrStorageUsed>
    </fields>
</interface>

This works very much the same way as above.

  • Provide the fields hrStorageSize and hrStorageUsed

  • Provide a useful name

  • Don't forget to specify <direction>output</direction>

  • Give the corresponding base OIDs

Now we may proceed as said above: Pressing the green circle runs those XML definitions against the host and updates the rows/columns. You will notice the “missing” second column only when Create Graphs for this Device is selected.


Note: Don't forget to set <direction>output</direction> for all variables/fields that should be stored in RRDfiles and be graphed! This is the mistake that occurs most often.

Defining the Data Template

The Data Template will define how the data retrieved by the XML Query is saved. For more information about the principles of operation, please see Common Tasks. Please go to Data Templates and Add:

SNMP Table 1 - Data Template

Define the Name of the Data Template. When defining the Name of the Data Source, do not forget to check the checkbox that allows the user to override the value during Data Source creation. This will come in useful later. Data Input Method will read Get SNMP Data (Indexed). Select the Data Source Profile as usual:

SNMP Table 2 - Data Template

Now to the Data Source Items. I like giving them the names of the MIB OIDs, see:

SNMP Table 3 - Data Template

and New or the plus sign on the Data Source Item panel. Now enter the second Data Source Item:

SNMP Table 4 - Data Template

Please pay attention to setting the Maximum Value to 'U' (no limit). Else, all values exceeding the maximum are stored as NaN. Now scroll down to the bottom of the page and check Index Type, Index Value and Output Type ID

SNMP Table 5 - Data Template

Save and the Data Template is finished.

Defining the Graph Template

The Graph Template will define how the data is presented. For more information about the principles of operation, please see Graph Templates. Please go to Graph Templates and Add:

Defining Graph Template

Fill in the header names and don't forget to check the checkbox that allows the user to override the value during Graph creation for the Graph Template Title:

Graph Template Preview

and Create.

Graph Template Preview after creation

Now Add the first Graph Item as usual:

Graph Template Items 1

Add the Legend and the second Graph Item:

Graph Template Items 2

Again, add the Legend to end up with

Graph Template Items 3

Revisiting The Data Query

We'll now have to revisit the Data Query

Data Query Review 1

Create:

Data Query Review 2

Select the correct Data Sources and check the boxes on the right. Save. Now fill in some useful Suggested Values, at first for the Data Template:

Data Query - Name Suggested Values

Now apply suggested values for the Graph Template:

Data Query - Apply Suggested Values

Now the Data Query is complete:

Data Query Complete

Create Graphs for this Host

Now we're almost done. Everything's ready for use now. So go to your device and select Create Graphs for this Device. Select some of the partitions you're interested in:

Create Graphs for this host

and Create to see:

Graphs created

Let's visit the Data Sources:

Host Data Sources

As you can see, the Suggested Values of the Data Query defined the Name of the Data Source. So let's go to Graph Management:

Graph Management Preview

to see the title defined by the Suggested Values. When turning to the Graphs, you may see something like

Graph image

This might be the end of the show. While it should be enough to define some “easy” SNMP XML based Data Queries, there are some tricks and hints left to explain.

As you may have noticed, the quantities defined by this example are counted in Units, not Bytes. This is somewhat inconvenient but may be changed. Let's wait for the next Section...

VALUE/REGEXP in Action

As said above, with the current XML size values are measured in Units. The current Unit Size is given by hrStorageAllocationUnits, but the reading of it is like 4096 Bytes. To use this in any calculations, we must get rid of the string Bytes. This can be done by the VALUE/REGEXP Feature of Cacti's XML definitions. So please change

<hrStorageAllocationUnits>
   <name>Allocation Units (Bytes)</name>
   <method>walk</method>
   <source>value</source>
   <direction>input</direction>
   <oid>.1.3.6.1.2.1.25.2.3.1.4</oid>
</hrStorageAllocationUnits>

By

<hrStorageAllocationUnits>
   <name>Allocation Units (Bytes)</name>
   <method>walk</method>
   <source>VALUE/REGEXP:([0-9]*) Bytes</source>
   <direction>input</direction>
   <oid>.1.3.6.1.2.1.25.2.3.1.4</oid>
</hrStorageAllocationUnits>

To prove this, go to your device and again Verbose Query our Data Query to see:

Data Query Debug Info

Now select Create Graphs for this Device and notice the change of the column Allocation Units (Bytes). The string “Bytes” has gone:

Data Query Table

To use these values, we define a CDEF:

CDEF Preview

Notice that with recent releases of Cacti, it is possible to use |query_*| values within CDEFs. Finally, go to Graph Templates and use this CDEF with all Graph Items:

Graph Template - CDEF

Change the Base Value to 1024 for Bytes → kBytes and the y-axis description to Bytes:

Graph Template - Base and Vertical values

Now the Graph looks like

Graph image

Please find the example resources below. Save hrStorageTable.xml into ./resource/snmp_queries and import the Graph Template from cacti_graph_template_host_mib_hrstoragetable.xml.

Cacti Graph Template Host MIB hrStorageTable

hrStorageTable download and store into resource/snmp_queries.


Copyright (c) 2004-2026 The Cacti Group