Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sun Feb 18, 2018 7:03 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 140 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next
Author Message
 Post subject: Quick and dirty script to add devices to cacti
PostPosted: Fri May 20, 2005 12:58 pm 
Offline

Joined: Mon May 02, 2005 3:33 pm
Posts: 46
Location: New York, NY
Hi all,

I just wrote this script that i'm going to be using to add a bunch of new devices (I also have a wrapper to call it multiple times with different hosts/addresses).

Put the file in your cacti directory and call it like this:
./add_device.php profilenumber somehostname somedescriptionforthehost community snmpversion disable

You can get the complete syntax by using --help or by reading the code! ;-)

The script uses api_device_add to create the new device so it should be safe.

I'm now trying to write a script to automate graph creation but it doesn't look like it's going to be a piece of cake (been reading graphs_new.php and template.php, most notably these functions: host_new_graphs, host_new_graphs_save and create_complete_graph_from_template).

Any help, comment or patches are welcome!


Top
 Profile  
 
 Post subject: suggestions
PostPosted: Fri May 20, 2005 3:33 pm 
Offline

Joined: Sat Dec 18, 2004 5:38 pm
Posts: 17
hi

this is a very important addon. perhapse you can post the script so we can test.

different approach then digging in the php code. is to trace the sql queries.

Good luck

Moshe


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 3:45 pm 
Offline

Joined: Mon May 02, 2005 3:33 pm
Posts: 46
Location: New York, NY
I thought I had attached the script, guess not, sorry about that! :-D


Attachments:
add_device.php.txt [4.86 KiB]
Downloaded 8611 times
Top
 Profile  
 
 Post subject: Re: suggestions
PostPosted: Fri May 20, 2005 3:57 pm 
Offline

Joined: Mon May 02, 2005 3:33 pm
Posts: 46
Location: New York, NY
moshesharon wrote:
different approach then digging in the php code. is to trace the sql queries.


This issue I'm concerned with this approach ('cause I thought about it) is if you're adding a set of devices that are not homogeneous, you might end up inserting the wrong data in the database.

IE: say you want to add hosts A & B. A has 2 interfaces, 3 drives and B 3 interfaces and 2 drives but let's assume you don't know about it and you've decided to use host A as the template for your SQL queries.
If you use the SQL queries you derived from A to create these devices, as you really don't query the device to see what snmp exports, you're going to insert a lot of mess in the database, though I'm not sure how bad it is.

The good thing about using the api, is when you create the device, it actually does all the snmp queries and populates all the appropriate tables. Drawback is that it takes longer as there's more processing involved.

Another problem with the API approach is that creating the actual graphs seems way trickier than just calling one simple function. I first need to create a function that actually gets the available things that can be graphed for a device and then, based on some parameters one would pass to the script, decide which one to graph.
Issue is for some of the graphs, you need to specify things like colors and so on meaning I need to recreate all the arrays that are passed to create_complete_graph_from_template.
I've dumped the actual args that are passed to it and well it looks really discouraging!!! :-D

Does this make sense?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 22, 2005 4:44 am 
Offline

Joined: Sat Dec 18, 2004 5:38 pm
Posts: 17
i guess you right about this approach if you adding complex device settings. so another option can be to create host + device + snmp. wait till the api finish and then creates the graph. maybe running the script twcie with --device flag and --graph flags. i currently working on perl script to add / import device + rrd file + graphs into cacti. this is usefull
if you have other programs like nagios creating the rrd file for you and just want to display / report it in cacti. but its still in its alpha stages. and im not ready to post ( hopefully soon ) in this script i traced the sql queries.

Moshe


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 22, 2005 5:27 am 
Offline

Joined: Mon May 02, 2005 3:33 pm
Posts: 46
Location: New York, NY
moshesharon wrote:
i guess you right about this approach if you adding complex device settings. so another option can be to create host + device + snmp. wait till the api finish and then creates the graph. maybe running the script twcie with --device flag and --graph flags.


Yea, guess I've got to get the graph part right though! ;-)

Quote:
i currently working on perl script to add / import device + rrd file + graphs into cacti. this is usefull
if you have other programs like nagios creating the rrd file for you and just want to display / report it in cacti. but its still in its alpha stages. and im not ready to post ( hopefully soon ) in this script i traced the sql queries.


Nice because I could also use this script (as I've a ton of rrds that were created by Orca). Keep us posted! ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 06, 2005 6:02 am 
Offline
Cacti User

Joined: Tue Aug 02, 2005 4:12 am
Posts: 85
any news on this topic ?

add_host.php is not working to me (doesn't do anything) ..


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 06, 2005 7:12 am 
Offline
Cacti User

Joined: Tue Aug 02, 2005 4:12 am
Posts: 85
I'm looking for script to add (from command line) a graphs to host.

anybody heard about this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 4:01 am 
Offline
Cacti User

Joined: Tue Aug 02, 2005 4:12 am
Posts: 85
hello

does any body can tell me how i can create a graph if i know all of the parametrs ?

i'm intersting to make a graph (smoke ping) thru the command (post) line somethink like:

Quote:
bash#>php graphs_new.php?host_id=50&Title=sdkfjh&UpperLimit=222&Address=123.123.123.123&Number_of_pings=5



who can help me with that and tell me what parametrs i have to put (i can't debug it from the post$) ..

thanks.


Top
 Profile  
 
 Post subject: Re: suggestions
PostPosted: Mon Dec 05, 2005 6:15 pm 
Offline

Joined: Thu Jan 02, 2003 8:03 am
Posts: 6
Location: Minneapolis, MN
mshook wrote:
...

Another problem with the API approach is that creating the actual graphs seems way trickier than just calling one simple function. I first need to create a function that actually gets the available things that can be graphed for a device and then, based on some parameters one would pass to the script, decide which one to graph.
Issue is for some of the graphs, you need to specify things like colors and so on meaning I need to recreate all the arrays that are passed to create_complete_graph_from_template.
I've dumped the actual args that are passed to it and well it looks really discouraging!!! :-D

Does this make sense?


I've been muddling around with the code trying to figure out how to "import" a csv of devices and end up with automatically generated graphs. add_device.php works *perfectly* (i have custom code that wraps add_device.php for csv reading) from the device addition perspective. As it calls api_device_save, it appropriately queries the device and stores the results. The only thing I have yet to do is to *automatically* generate all of the graphs (based on graph templates) associated with a particular host template. All I want to do, is to do the programmatical equivalent of checking all the snmp_query check boxes on the "create graphs for this device" page.

As I am using a custom XML for query definition, host templates, and graph templates, I shouldn't have to interact with the process at all.

Have you had any new success since the original posting or thoughts on my problem?

_________________
attempting:
Cacti 0.8.6g | Gentoo Linux | rrdtool 1.2.6
700 devices | 55,000 datasources


Top
 Profile  
 
 Post subject: Bulk Import Tools/Mass Import
PostPosted: Tue Dec 13, 2005 8:43 am 
Offline

Joined: Fri Dec 02, 2005 7:02 am
Posts: 38
Location: United Kingdom
Hi all,

I've created some scripts to compliment the add_device.php and together they can all be used to create graphs, plug the graphs into a tree, and assign permissions etc.

I changed the original add_device.php (posted above) so that it outputs the new device ID/Host ID which can then be captured and used to add graphs to that host. If the added device already exists, then it outputs the existing host/device ID instead so as to avoid duplicates.

Likewise, the add_graphs.php outputs the graph-id so that it can be used to add it to a tree, or to assign permissions etc.

Usage for each of the scripts are documented either within each script or if you run it with no parameters. I've successfully used these scripts to automatically add the graphs for over 2500 interfaces (the company I work for, Synetrix, manage a metropolitan-area network for all the schools in London) and to plug them into various trees, each of which have various access rights depending on the user.

The most complex script is the add_graphs.php:

To add a graph of Interface Traffic, you need to know the following in advance:

* The Host ID (I parse it from the output of add_graph.php)
use --list-hosts to see a list of them
* The Graph Template ID (I note these via the front-end and mostly use the same ones)
use --list-graph-templates to see a list of them
* The SNMP Query ID - I use "SNMP - Interface Statistics" which is ID '1' on my system
use --list-snmp-queries to see a list of them
* The SNMP Query Type ID - I use "In/Out Bits (64-bit Counters)" - ID '14' on my system
use --snmp-query-id 1 --list-query-types to see a list of them
* The SNMP Field name that you want to use to identify the interface on the host
(I use 'ifIndex' on my system, but you can use 'ifAlias' or 'ifDescr' too)
use --host-id [ID] --list-snmp-fields to see a list of them
* The SNMP Value that that you want to use to identify the interface on the host
If you use an SNMP field name of 'ifIndex' then the SNMP Value is the index number
of the interface that you want to graph.

Once you have the above info, you can add a graph by running:

Code:
./add_graphs.php --graph-type ds --graph-template-id 2 --host-id [ID] --snmp-query-id 1 --snmp-query-type-id 14 --snmp-field ifIndex --snmp-value 1


The above command would add a graph of interface 1 on the host-ID specified.
It would also output the graphi-ID that it created, and also the RRA ID.

To add this graph to a tree, you can create/get the ID of the tree using:
Code:
./add_tree.php --type tree --name 'Tree Name' --sort-method a

(Outputs the Tree ID)

To then create a sub-node in this tree, use:
Code:
./add_tree.php --type node --node-type header --tree-ID [TREE ID] --parent-node 0 --name 'Node Name'

Outputs the node ID

To then add the graph to the node in that we just created, run:
Code:
./add_tree.php --type node --node-type graph --tree-id [TREE ID] --parent-node [NODE ID] --graph-id [ID] --rra-id [RRA ID]

Outputs the graph node ID

The graph-ID and RRA ID are output from the add_graphs.php script.

To add permissions to the graph ID created, you can use the add_perms.php:
Code:
./add_perms.php --user-id [USER ID] --item-type graph --item-id [GRAPH ID]


To add permissions to the tree, you can use the following:
Code:
./add_perms.php --user-id [USER ID] --item-type tree --item-id [TREE ID]


Unzip the files into your cacti directory (don't worry they have built-in protection against being run by the web-server).

All scripts are smart enough not to add duplicates, but instead to just return the ID's of the existing things in the databases so that they can be used for other operations.

Also, this is the first thing I've ever coded in php, so feedback is would be welcome!!!

Regards
Bradley Kite

(Attachment removed - see post below)


Last edited by bradley on Fri Dec 16, 2005 6:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 3:45 pm 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
Thanks for this script, it is the kind of tool I need. I will try to test it as soon as I can.
I will try to make a similar script to add data sources, and then add a graph with this data source.

How much time did the script take to add the 2500 interfaces ?


Top
 Profile  
 
 Post subject: Re: Bulk Import Tools/Mass Import
PostPosted: Fri Dec 16, 2005 4:59 am 
Offline

Joined: Fri Dec 16, 2005 3:19 am
Posts: 8
Hi Bradley,

from add_tree.php i got error message that it couldn't find api_importTree.php.

Here is the messages:

[email protected]:/var/www/cacti$ php add_tree.php

Warning: main(/var/www/cacti-0.8.6f/lib/api_importTree.php): failed to open stream: No such file or directory in /var/www/cacti-0.8.6f/add_tree.php on line 28

Warning: main(): Failed opening '/var/www/cacti-0.8.6f/lib/api_importTree.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/cacti-0.8.6f/add_tree.php on line 28

for what version of cacti is this script made?

in my installed version there is no api_importTree.php.

Regards

Johannes


I


Top
 Profile  
 
 Post subject: Re: Bulk Import Tools/Mass Import
PostPosted: Fri Dec 16, 2005 6:38 am 
Offline

Joined: Fri Dec 02, 2005 7:02 am
Posts: 38
Location: United Kingdom
jolonghair wrote:
Hi Bradley,

from add_tree.php i got error message that it couldn't find api_importTree.php.



Hi jolonghair

Sorry, I forgot to include this file in the zip archive. The file is basically the same as
lib/api_tree.php but has some extra checks added to check for duplicates.

Here's the file you need.

It would be nice if the changes i made to this file were incorporated back into api_tree.php.

I kept the changes seperate so that i can upgrade my version of Cacti without breaking my existing stuff.

(ps: Exo7, it takes just over an hour to do everything for the ~2500 interfaces, thats add hosts, graphs, trees and permissions. It takes this long because each invocation of each script has to be parsed by PHP, connect to the DB etc. etc. but I wanted them to be seperate scripts to make them more modular.)

Also, I wrote this scripts for version 0.8.6g of cacti


Attachments:
File comment: Included missing library file
bulk_import_tools.zip [10.94 KiB]
Downloaded 7163 times
File comment: Missing Library File
api_importTree.php.txt [6.67 KiB]
Downloaded 3842 times
Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 10:07 am 
Offline
Cacti User
User avatar

Joined: Wed Aug 03, 2005 4:14 am
Posts: 61
Location: Cologne Germany
Thanks!

Just added like 100+ Servers in less than 10 minutes. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 140 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group