|
|
| Author |
Message |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Tue Nov 28, 2006 1:02 pm Post subject: |
|
|
Wow, cool. I'm not a MRTG user, but sth like this was asked often. I'll surely link to this post from time to time
Reinhard
|
|
| Back to top |
|
 |
c1155499
Joined: 29 Nov 2006 Posts: 1 Location: Ohio
|
Posted: Wed Nov 29, 2006 3:25 pm Post subject: add_tree.php |
|
|
I have added close to 300 devices and 1500 graphs, but I am having problems with the add_tree.php.
What I would like to do is make new Tree Item underneath an already made Graph Tree under the root tree, and then add the specific location graphs to that tree. Can anyone help me with the command?
Example:
Remote Sites -> Location 304 -> Location 304 Graphs
Also, is there a later version of the add_tree with the new features listed below:
Other Options: --list-hosts
--list-trees *
--tree-id [ID] --list-nodes *
--list-rras *
--host-id [ID] --list-graphs *
Thanks,
Jamie
|
|
| Back to top |
|
 |
sini Cacti User
Joined: 24 Nov 2003 Posts: 55 Location: Hungary
|
Posted: Mon Dec 11, 2006 4:45 am Post subject: |
|
|
Hi,
I upgraded cacti from 0.8.6.g > 0.8.6i and the add_graph.php script does not work anymore...
Every time I execute the script its gives me the help output, although I use the same parameters like I used with 0.8.6g.
Does anyone use this script with success on 0.8.6i ??
|
|
| Back to top |
|
 |
melvinshaw
Joined: 13 Feb 2007 Posts: 6 Location: Columbus, OH
|
Posted: Tue Mar 06, 2007 2:41 pm Post subject: |
|
|
It's been a little quiet around here but thought I'd ask anyway.
These scripts run wonderfully for my on 0.8.6i but on 0.8.6j they seem to run REALLY slow, and somewhat unreliably. I have a PERL script wrapper thing that I use to call the add_device.php script. It can take upwards of 5 or 6 minutes to add some hosts. Others seem to fail altogether. This took seconds on the previous versions.
When I run the command directly on the console, I get the same symptoms so I'm fairly confident it has nothing to do with my usage via my wrapper. I also don't suspect it's the host I'm running it on as it's a fairly powerful HP ProLiant with a ton of RAM and really not much else to be working on.
Before I get started digging in, figured I check if anyone had similar issues, tips, or fixes they'd like to share.
-melvin
|
|
| Back to top |
|
 |
melvinshaw
Joined: 13 Feb 2007 Posts: 6 Location: Columbus, OH
|
Posted: Wed Mar 07, 2007 2:27 pm Post subject: |
|
|
Solved my previously posted issue somewhat - I found I was missing a PHP memory error. Upped that a bit in /etc/php5/cli/php.cfg and seems to be completing now, though slower than I would like.
score one for the good guys
-melvin
|
|
| Back to top |
|
 |
glista
Joined: 19 Mar 2007 Posts: 10
|
Posted: Wed Apr 11, 2007 2:08 am Post subject: |
|
|
We needed a mechanism for automaticly (using scripts) adding alot of data sources and graphs to cacti. So I've implemented an additional data input method (data_input.php). The changes also add data validation in database functions. The mechanism works like a black-box but requires PHP4. It works with any GUI (is not tied into a specific GUI). This way one can easily write a data input tool, it can be a command line, SOAP, Cacti GUI, .... One only needs to use the following functions to implement data input:
-method_add, method_edit, mehod_delete,
-input_add, input_edit, input_delete,
-output_add, output_edit, output_delete.
Methods return values or throw exceptions. Exceptions should be catched by "if ($throwExceptionArray)"
There are 4 files in cati-data_input.zip:
data_input_cmd.php // for command line calls
data_input_function.php // implemented functions from cacti
data_input_validate.php // input validations, database validations
error_Exception.php // error exception
Knowing these are quite extensive changes I would welcome your input. Hopefully I've also managed to make code a bit more readable.
| Description: |
|
 Download |
| Filename: |
cacti-data_input.zip |
| Filesize: |
7.08 KB |
| Downloaded: |
294 Time(s) |
Last edited by glista on Wed Apr 11, 2007 4:59 am; edited 1 time in total |
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Wed Apr 11, 2007 3:19 am Post subject: |
|
|
Hey, interesting.
Would you please be so kind to post some application examples?
Reinhard
|
|
| Back to top |
|
 |
glista
Joined: 19 Mar 2007 Posts: 10
|
Posted: Wed Apr 11, 2007 5:07 am Post subject: |
|
|
Here is sample to use command line data_input_cmd.php UI:
C:\cacti>php data_input_cmd.php --type method --do add --name TestMethod --inputType scriptcommand --inputString c:/phptest/random2.pl
Method Created - method-id: (33)
#set --methodID 33
C:\cacti>php data_input_cmd.php --type output --do add --name OutputField --methodID 33 --dataName friendlyName --updateRRA
Output Created - output-id: (67)
php data_input_cmd.php --type method --do show
php data_input_cmd.php --type output --do show
The changes should be visible in cacti GUI "data input methods"
|
|
| Back to top |
|
 |
danathane Cacti User
Joined: 03 May 2007 Posts: 127
|
Posted: Fri May 04, 2007 9:04 am Post subject: |
|
|
peolple hie!!!
I have read all the topic and I think that the solution to my problem is there. But I am still asking myself this question : how can i run the commands like ./add_device.php? I think that thoose commands are Linux ones. So do thoose scripts work one windows. And if the answer is yes how can I run thoose script?
Thanks for all
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Fri May 04, 2007 2:54 pm Post subject: |
|
|
php -q add_device.php ...
at least I suppose so. It's quite a time that I windozed last
Reinhard
|
|
| Back to top |
|
 |
danathane Cacti User
Joined: 03 May 2007 Posts: 127
|
Posted: Wed May 16, 2007 7:22 am Post subject: |
|
|
hello again.
I would like to know where i have to copy paste the files for add_device. Is it in the cacti folder or in a sub-folder like for plug ins?
I am a totaly new user so i don't know anything.
Thanks.
|
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Wed May 16, 2007 3:24 pm Post subject: |
|
|
I put them into main directory and it worked well for me
Reinhard
|
|
| Back to top |
|
 |
disirk
Joined: 11 Sep 2006 Posts: 12 Location: Atlanta, GA
|
Posted: Sat May 19, 2007 1:43 pm Post subject: |
|
|
Updated the add_tree.php to include the --list-trees and --tree-id [ID] --list-nodes options. I'm not an expert with patching, so not sure if this will work on all systems so please backup your original.
apply by copying the code below to a patch file...for instance add_tree.patch. Then from the directory you have add_tree.php in execute:
patch -p0 < add_tree.patch
Test by trying it out: ./add_tree.php --list-trees
./add_tree.php --list-trees
Known Trees:(id, name)
9 Testing
12 Points of Presence
13 Firewall testing
| Code: | --- add_tree.php Sat May 19 18:36:16 2007
+++ add_tree.php.new Sat May 19 18:37:35 2007
@@ -44,8 +44,9 @@
(Host group styles: 1 = Graph template, 2 = Data Query Index)
Other Options: --list-hosts
- --list-trees *
- --tree-id [ID] --list-nodes *
+ --list-trees
+ --tree-id [ID] --list-nodes
+ (--tree-id must be set before --list-nodes)
--list-rras *
--host-id [ID] --list-graphs *
@@ -121,6 +122,21 @@
case "--list-hosts":
displayHosts($hosts);
return 0;
+ case "--list-trees":
+ $trees = getTrees();
+ displayTrees($trees);
+ return 0;
+ case "--list-nodes":
+ if (isset($treeId))
+ {
+ $treeNodes = getTreeNodes($treeId);
+ displayTreeNodes($treeNodes,$treeId);
+ }
+ else
+ {
+ usage();
+ }
+ return 0;
case "--host-group-style":
$i++;
$hostGroupStyle = $_SERVER["argv"][$i];
@@ -241,6 +257,7 @@
function getHosts()
{
+ $hosts = array();
$tmpArray = db_fetch_assoc("select id, hostname from host order by id");
foreach ($tmpArray as $host)
$hosts[$host["id"]] = $host["hostname"];
@@ -256,4 +273,40 @@
}
}
+function getTrees()
+{
+ $trees = array();
+ $tmpArray = db_fetch_assoc("select id, name from graph_tree order by id");
+ foreach ($tmpArray as $tree)
+ $trees[$tree["id"]] = $tree["name"];
+ return $trees;
+}
+
+function displayTrees($trees)
+{
+ echo "Known Trees:(id, name)\n";
+ while (list($id, $tree) = each ($trees))
+ {
+ echo "\t" . $id . "\t" . $tree . "\n";
+ }
+}
+
+function getTreeNodes($treeId)
+{
+ $nodes = array();
+ $tmpArray = db_fetch_assoc("select id, title from graph_tree_items WHERE graph_tree_id = $treeId AND title != ''");
+ foreach ($tmpArray as $node)
+ $nodes[$node["id"]] = $node["title"];
+ return $nodes;
+}
+
+function displayTreeNodes($treeNodes,$treeId)
+{
+ echo "Known Tree Nodes for Tree ID $treeId:(id, title)\n";
+ while (list($id,$title) = each ($treeNodes))
+ {
+ echo "\t" . $id . "\t" . $title . "\n";
+ }
+}
?>
+ |
|
|
| Back to top |
|
 |
glista
Joined: 19 Mar 2007 Posts: 10
|
Posted: Fri May 25, 2007 5:52 am Post subject: |
|
|
| It would be very nice if this script could make it into official Cacti distribution becouse of the future compatibility. A nice approch might be to seperate the work API functions from the GUI.
|
|
| Back to top |
|
 |
robt
Joined: 27 May 2007 Posts: 1
|
Posted: Sun May 27, 2007 10:47 am Post subject: dirty way to add hosts from discover, using this script |
|
|
create a php script to loop through the newly added hosts:
| Code: |
<?
$db = "cacti";
$h = "localhost";
$user = "whoever";
$pass = "cactipass";
$go = mysql_connect($h,$user,$pass);
$SQL = "SELECT * from plugin_discover_hosts where ip like '10.10.%'";
$result = mysql_db_query($db,$SQL,$go);
while($row = mysql_fetch_array($result)) {
$ip = $row['ip'];
$sysname = $row['sysName'];
echo "found Customer-YourDescription-$sysname with ip $ip\n";
$addhost = passthru("/usr/bin/php /path/to/add_device.php 9 \"customer-whatever-$sysname\" $ip COMMUNITY 2 0");
// add add_graph command line here, or whatever else
}
?> |
|
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|