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.
Sample script to quickly create graphs
Moderators: Developers, Moderators
Sample script to quickly create graphs
- 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.
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?
Who is online
Users browsing this forum: No registered users and 3 guests