Automatically adding graph

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
ognjen
Posts: 10
Joined: Fri Oct 12, 2007 12:26 pm

Automatically adding graph

Post by ognjen »

Hi guys,

I found a script which i modified for my own use to automatically add graphs using add_graphs.php. This works well. The only problem i am struggling with is setting correct title. At the moment my graph title get set to IfAlias. What i would like to is to pull values and set the title on graphs like
this: ifIP-ifDescr-IfAlias.

this is the script i found on forum here somewhere and have been successful using it to add all my graphs.

CLI_DIR="/var/www/html/cacti/cli"
CISCO_ROUTER=12
GRAPH_TEMPLATE_ID=32
SNMP_QUERY_ID=1
SNMP_QUERY_TYPE_ID=14
SNMP_FIELD="ifAlias"
INTERFACE="ifDescr"
IP_ADD="IfIP"

Get list of devices:
$PHP $CLI_DIR/add_graphs.php --list-hosts | tail --lines=+3 | while read id hostname template description;

do

if [ "$template" = "$CISCO_ROUTER" ]; then
$PHP $CLI_DIR/poller_reindex_hosts.php --id=$id


for circuit in `$PHP $CLI_DIR/add_graphs.php \
--host-id=$id \
--snmp-field="$IP_ADD, $INTERFACE, $SNMP_FIELD" \
--list-snmp-values | tail --lines=+4`;
do

# Bits per second graphs
if [[ "$circuit" == CORE* ]]; then
# echo "$circuit"

$PHP $CLI_DIR/add_graphs.php --host-id=$id --graph-type="ds" --graph-title=$circuit --graph-template-id=$GRAPH_TEMPLATE_ID --snmp-query-id=$SNMP_QUERY_ID --snmp-query-type-id=$SNMP_QUERY_TYPE_ID --snmp-field=$SNMP_FIELD --snmp-value=$circuit
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Automatically adding graph

Post by noname »

ognjen wrote:At the moment my graph title get set to IfAlias. What i would like to is to pull values and set the title on graphs like
this: ifIP-ifDescr-IfAlias.
I think you should create new graph template that can show the title you want,
then specify its ID at 'GRAPH_TEMPLATE_ID=' in your script.
ognjen
Posts: 10
Joined: Fri Oct 12, 2007 12:26 pm

Re: Automatically adding graph

Post by ognjen »

Well i am using bit/sec total bandwidth with graph title set to |host_description| - Traffic - |query_ifIP| (|query_ifDescr|)[|query_ifAlias|].
This works, but as i understand it when i use the script add_graphs.php and dont specify graph title it should be using the above from the template, but somehow i end up with the same result just ifAlias. Weird. I will try with different template.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Automatically adding graph

Post by noname »

As I added graph by add_graphs.php, I understood your problem.

If you used '--graph-type='"ds"', graph title will be made from datasource that is determined '--snmp-query-id=' and '--snmp-query-type-id='.

You used these options as this..
  • SNMP_QUERY_ID=1
    is equivalent to 'Interface Statistics' as Data Query
  • SNMP_QUERY_TYPE_ID=14
    is equivalent to 'In/Out Bits (64-bit Counters)' as Associated Graph Templates in that query
Now you can choose one from the below:

(A) Make new data query

Make new data query that has new Suggested Values you want,
then specify new SNMP_QUERY_ID and SNMP_QUERY_TYPE_ID in your script.
For example:
custom_graph_title-1.png
custom_graph_title-1.png (22.57 KiB) Viewed 1696 times
custom_graph_title-2.png
custom_graph_title-2.png (28.82 KiB) Viewed 1696 times
(B) Force cacti to reapply graph items

Click 'Console' -> 'Graph Templates' -> (your customized template),
then click 'save' with no changes (but 'Title' checkbox should be off).
This operation evokes actions to update items of all graphs that use given template.
custom_graph_title-3.png
custom_graph_title-3.png (9.36 KiB) Viewed 1696 times
Note:
Unfortunately, 'Reapply Suggested Names' in Graph Management don't solve this.
Because that updates 'title_cache' field in graph_template_graph table by current 'title' field.
But the above operations will update 'title' itself.

(C) Modify add_graphs.php

At line 408~, change from

Code: Select all

        $returnArray = array();

        if ($graph_type == "cg") {
to

Code: Select all

        /* get graph title from graph template */
        if ($graphTitle == "") {
                $graphTitle = db_fetch_cell("SELECT title FROM graph_templates_graph WHERE graph_template_id=$templateId AND local_graph_id=0");
        }

        $returnArray = array();

        if ($graph_type == "cg") {
These code force to retrieve current title settings from the graph template which you specified.
(I tested in Cacti0.8.7e. 'add_graphs.php' in 0.8.7g is mostly same, maybe it also works.)

Good luck!

// Sorry my English..
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Automatically adding graph

Post by noname »

Well, of course, you can also specify own title in command line like as:

--graph-title="|host_description| - Traffic - |query_ifIP| (|query_ifDescr|)[|query_ifAlias|]"

That's most simplest. :)
ognjen
Posts: 10
Joined: Fri Oct 12, 2007 12:26 pm

Re: Automatically adding graph

Post by ognjen »

Thanks for this i really appreciate the time i am testing it now :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests