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
Automatically adding graph
Moderators: Developers, Moderators
Re: Automatically adding graph
I think you should create new graph template that can show the title you want,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.
then specify its ID at 'GRAPH_TEMPLATE_ID=' in your script.
Re: Automatically adding graph
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.
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.
Re: Automatically adding graph
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..
(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: (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. 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 fromto
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..
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
(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: (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. 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") {
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") {
(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..
Re: Automatically adding graph
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. :)
--graph-title="|host_description| - Traffic - |query_ifIP| (|query_ifDescr|)[|query_ifAlias|]"
That's most simplest. :)
Re: Automatically adding graph
Thanks for this i really appreciate the time i am testing it now
Who is online
Users browsing this forum: No registered users and 0 guests