Quick and dirty script to add devices to cacti

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

Moderators: Moderators, Developers

Post Reply
Author
Message
ymartin59
Posts: 40
Joined: Fri Feb 17, 2006 7:42 am

Must have scripts !

#16 Post by ymartin59 » Mon Feb 20, 2006 3:39 am

That script set is wonderful and powerful. And I do not find them so "quick and dirty".
I really think that scripts must be included in cacti !

ymartin59
Posts: 40
Joined: Fri Feb 17, 2006 7:42 am

Issue with multiple data sources graph creation

#17 Post by ymartin59 » Mon Feb 20, 2006 4:45 am

Hello,

I'm trying to create "ucd/net Available Disk Space" with the command:
add_graphs.php --graph-type cg --graph-template-id 3 --host-id 8
--snmp-query-id 2 --snmp-query-type-id 6 --snmp-field dskPath --snmp-value "/"
--graph-title "grenade - Disk Space - /"

Where:
Known Graph Templates:(id, name)
3 ucd/net - Available Disk Space
Known SNMP Queries:(id, name)
2 ucd/net - Get Monitored Partitions
Known SNMP Query Types:(id, name)
6 Available/Used Disk Space

Two datasources are created for the graph but their custom data fields (index type, index value and output type ID) are not set automatically - in addition, the datasource name is "|host_description| - Hard Drive Space" instead of "|host_description| - Partion - |query_dskDevice|"
Last edited by ymartin59 on Mon Feb 20, 2006 6:17 am, edited 1 time in total.

ymartin59
Posts: 40
Joined: Fri Feb 17, 2006 7:42 am

Re: Issue with multiple data sources graph creation

#18 Post by ymartin59 » Mon Feb 20, 2006 6:15 am

ymartin59 wrote: I'm trying to create "ucd/net Available Disk Space" with the command:
add_graphs.php --graph-type cg --graph-template-id 3 --host-id 8
--snmp-query-id 2 --snmp-query-type-id 6 --snmp-field dskPath --snmp-value "/"
--graph-title "grenade - Disk Space - /"
Sorry, I made a big mistake... graph-type must be 'ds' !! It works perfectly.

tclark
Posts: 28
Joined: Mon Jul 11, 2005 7:10 pm

Any plans to update add_device script to support snmpv3?

#19 Post by tclark » Sun Feb 26, 2006 3:23 am

The current version of cacti only supports AuthNoPriv. In the environment I support, we enforced an AuthPriv snmpv3 policy on our servers. To enable cacti to work properly, an update to $auth_snmp in ./lib/snmp.php was done. The updated syntax for $auth_snmp now looks like this.

$snmp_auth = "-u $username -l authPriv -a MD5 -A $password -x DES -X $password"; /* v3 - username/password */

It would be great to be able to use some of these scripts to save work : )

imbezol
Posts: 1
Joined: Wed Apr 12, 2006 7:11 pm

#20 Post by imbezol » Wed Apr 12, 2006 7:16 pm

This patch adds the ability for add_graphs.php to tell if a graph exists already even if the type is cg.

Code: Select all

--- add_graphs.php      Tue Dec 13 05:53:46 2005
+++ add_graphs.php.new  Wed Apr 12 18:06:02 2006
@@ -245,6 +245,23 @@
     if ($graph_type == "cg")
     {
         $empty = array(); /* Suggested Values are not been implemented */
+
+        $existsAlready = db_fetch_cell("select id from graph_local where graph_template_id = $templateId AND host_id = $hostId");
+        if (isset($existsAlready) && $existsAlready > 0)
+        {
+            if ($graphTitle != "")
+            {
+                db_execute("update graph_templates_graph set title = \"$graphTitle\" where local_graph_id = $existsAlready");
+                update_graph_title_cache($existsAlready);
+            }
+            $dataSourceId = db_fetch_cell("SELECT DISTINCT data_template_rrd.local_data_id
+                                             FROM graph_templates_item, data_template_rrd
+                                           WHERE graph_templates_item.local_graph_id = " . $existsAlready .
+                                           " AND graph_templates_item.task_item_id = data_template_rrd.id");
+            echo "Not Adding Graph - this graph already exists - graph-id: ($existsAlready) - data-source-id: ($dataSourceId)\n";
+            return(1);
+        }
+
         $returnArray = create_complete_graph_from_template($templateId, $hostId, "", $empty);
     }
Save this to add_graphs.php.patch and run

Code: Select all

patch -p0 < add_graphs.php.patch
Travis Morgan
http://bigfiber.net

deltaforce
Posts: 1
Joined: Fri Apr 14, 2006 10:01 am
Location: Grenoble - FRANCE

#21 Post by deltaforce » Wed Apr 19, 2006 10:26 am

About add_tree.php, some functions weren't implemented like --list-trees ; --list-nodes...
Does somebody know if these scripts are finished today ? (I'm triing to complete them, but it doesn't work).
Thank you.

User avatar
cdukes
Cacti User
Posts: 61
Joined: Tue Mar 26, 2002 1:25 pm
Location: Morrisville, NC
Contact:

Awesome!

#22 Post by cdukes » Thu Apr 20, 2006 10:25 am

Thank you so much for writing this.
I just imported 1k devices perfectly!
On to adding graphs now :-)

manaf
Cacti User
Posts: 68
Joined: Sun Apr 16, 2006 2:03 am

#23 Post by manaf » Sun Apr 23, 2006 1:54 am

How can i use it in windows??

shadowk
Posts: 3
Joined: Mon Apr 24, 2006 8:16 am

patch

#24 Post by shadowk » Mon Apr 24, 2006 8:23 am

Here is a patch to prevent adding hosts to the graph tree if they are in the specified tree already.

Code: Select all

--- add_tree.php        Fri Apr 21 16:44:38 2006
+++ add_tree.php.new    Fri Apr 21 17:29:35 2006
@@ -208,6 +208,12 @@
             $rra_id         = 0;
             $name           = '';

+            $hostNodeExists = db_fetch_cell("SELECT id FROM graph_tree_items WHERE graph_tree_id = $treeId AND host_id = $hostId");
+            if (isset($hostNodeExists))
+            {
+               echo "Not adding host, host-id ($hostId) is already in graph tree ($treeId)\n";
+               return 1;
+            }
             if (!isset($hosts[$hostId]))
             {
                 printf("No such host-id (%s) exists. Try --list-hosts\n", $hostId);
Save this to add_tree.php.patch and run:

Code: Select all

patch -p0 < add_tree.php.patch
Andrew

stutz
Posts: 4
Joined: Fri Apr 21, 2006 5:32 am
Location: London. UK

A wrapper for Bradley's scripts

#25 Post by stutz » Thu May 04, 2006 4:03 am

Firstly thanks to Bradley et al for the php import scripts. I have written my first ever script (so don't be to harsh - comments for improvements appreciated!) to successfully transfer 1500 devices from CastleRock SNMPc to Cacti. This can be modified to read in pretty much any CSV file and populate Cacti with the Tree, Devices and Graphs all asociated with the relevant Nodes.

One question I have is when creating a CG graph, is there any way to populate the custom fields?

For example for a graph 'Host Availability' in the 'Data Sources' menu in the 'Supplemental Data Template Data' section is a 'Custom Data' field for 'IP Address'. At the moment I have to manually add the address for each device.
Attachments
import.zip
Feel free to use/modify this wrapper script for your own use. Do share any improvements though!
(945 Bytes) Downloaded 1264 times

schlabschi
Posts: 2
Joined: Mon May 08, 2006 10:44 am

#26 Post by schlabschi » Mon May 08, 2006 10:50 am

Awesom scripts! Really saved me a lot of work.
But I have the same problem as "stutz" above: Can someone who is smarter in scripting than me provide a way to populate the custom fields like ip address?
I also have to put it in by hand for over 1500 entries :cry:

Thanks a lot,
Schlabschi

sini
Cacti User
Posts: 91
Joined: Mon Nov 24, 2003 10:22 am
Location: Hungary

#27 Post by sini » Tue May 16, 2006 7:01 am

Hi,

Nice work! Just one question.
How can I add a grap with space in its ifDescr like "ATM2/0.1007-aal5 layer"?

thx
Sini

kanada
Cacti User
Posts: 137
Joined: Sun Aug 28, 2005 12:51 pm

#28 Post by kanada » Fri Jun 09, 2006 4:28 am

I have in logs some errors when i try add to sql var with speed interface.

CMDPHP: Poller[0] ERROR: SQL Exec Failed "update data_template_data set rrd_maximum='|query_ifSpeed|' where local_data_id=8787"

any ideas?

Thanks.

jbajc
Posts: 6
Joined: Fri Apr 21, 2006 3:32 am

#29 Post by jbajc » Thu Jun 22, 2006 6:35 am

Hello,

I have a problem with script add_graphs.php. The script seems to be working properly if I use cmd.php as a poller. If I use cactid it doesn't create any new rrds.

Have any ideas?

Tnx for reply

Janko

User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

#30 Post by gninja » Mon Jun 26, 2006 8:24 pm

I'm having a problem with this.. It doesn't seem to execute the queries properly when setting up. If I add a host with snmp disk graphs, when I go into the device, instead of the mount points, I see the mount numbers... Any way to fix that?
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6

Post Reply