Sample script to quickly create graphs

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Acheron
Posts: 5
Joined: Mon Apr 25, 2005 10:06 am

Sample script to quickly create graphs

Post by Acheron »

Hello all -- I got sick of creating graphs manually for many devices (I know it's a common complaint, love Cacti otherwise). Anyways, I kept seeing posts on here talking about how easy it was to use WWW::Mechanize to add graphs, but saw no code. So, here's my code -- it's not the prettiest code, but it works. A couple of things needed to run this:

- A list of the host IDs which you wish to create graphs for (which can be obtained using a SQL match off the database)
- A list of the graph IDs you wish to add (which can be viewed from the source of the page where you select the graphs you wish to add)
- The host template of the devices -- this number corresponds to the host_template_id field -- I just noticed that this entry would vary based on the template type. I've modified the script with the $templateid variable to account for this.
- A small modification needs to be made to graphs_new.php in your Cacti directory to give the checkboxes a value (I know there are other methods to get around the tick(value) limitation, but this was quicker, so I did it this way). The change I made was this:

(line 487 according to VIM):

<input type='checkbox' name='cg_$query_row' id='cg_$query_row' value='val_$query_row'" . (($use_javascript == true) ? " onClick='gt_update_selection_indicators();'" : "") . ">

- I also added the following to auth_login.php (line 157 in my VIM):
<td><input type="submit" name="Login" value="Login"></td>

- I hardcoded the checkbox name values in this script -- it would be fairly easy to implement a more flexible script, but if you just wish to quickly stamp out a bunch of graphs, you can just change the checkbox values in the script.

I hope this helps when creating graphs; it certainly saved me some time.
Attachments
mechanize_graphs.txt
WWW::Mechanize script for quickly adding graphs
(1.81 KiB) Downloaded 219 times
Last edited by Acheron on Fri Sep 09, 2005 1:11 pm, edited 1 time in total.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Sounds lovely,
but from your text I cannot figure out how it would look like. May you please provide a sample screen shot?
Thx alot
Reinhard
Acheron
Posts: 5
Joined: Mon Apr 25, 2005 10:06 am

Post by Acheron »

It's not a plugin or addin to Cacti, but rather a command line script. Sorry, I should have clarified this in the first post.
Acheron
Posts: 5
Joined: Mon Apr 25, 2005 10:06 am

Post by Acheron »

Just a thought -- I was looking at the script located at http://forums.cacti.net/viewtopic.php?t=7683 (this script works great, incidentally). I was thinking of merging the script I've listed here with this one and adding it as a plugin to Cacti. I'm a bit slow at the php side of the equation -- do we have any takers on this concept?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests