The Cacti Manual
Prev | Chapter 20. Command Line Scripts | Next

# Associate a Data Query to an existing Host

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

    Add Data Query Script 1.0, Copyright 2004-2012 - The Cacti Group

    A simple command line utility to add a data query to an existing device in Cacti

    usage: add_data_query.php --host-id=[ID] --data-query-id=[dq_id] --reindex-method=[method] [--quiet]

    Required:
        --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

## List all Hosts

    shell>php -q add_data_query.php --list-hosts

    Known Hosts: (id, hostname, template, description)
    1       127.0.0.1       8       Localhost
    11      router          3       router.mydomain.com

## List all Data Queries

    shell>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 Information

## Add a Data Query

    shell>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].

Prev | Home | Next
Add a New Device | Up | Associate a Graph Template to an existing Host