Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Sun Apr 21, 2019 11:15 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 140 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 10  Next
Author Message
 Post subject: SOAP for Cacti Version 0.8.7a
PostPosted: Mon May 28, 2007 6:32 am 
Offline

Joined: Mon Mar 19, 2007 12:43 am
Posts: 10
Please find attached a sample script for automated
insertion of graphs (via SOAP). Installation instructions::

SERVER:
1. Use PHP 5.x (with SOAP support) and Cacti Version 0.8.7a
2. Extract files from “soap-server.zip”
3. Place “soap_service.php” file into your Cacti installation directory
4. Place “soap” directory with all included files into your Cacti installation directory
5. Open cacti URL (typically “http://<hostname>:<port>/cacti”)
6. Click “User Management”
7. Check “admin”, choose action “duplicate” and click “Go”
8. Enter the following values:
User name: “soap”
Full name: “Soap service”
Password: “soap”

CLIENT:
1. Use PHP 5.x (with SOAP support)
2. Extracts files from “soap-client.zip”
3. Open the command line and go to the directory where you are extracted the files
4. Type:
“php add_graph_cl.php --username=soap --password=soap --urn=<hostname>:<port>/cacti --do=--list-snmp-queries”

Option “--urn” specifies the path where cacti service is running. If you are running cacti service and client in local machine, just add this parameter: “--urn=localhost/cacti” or “--urn=localhost”

5. Press enter to start the client

Sample Client for Perl
For a sample soap client in Perl see the file “samples/soap_client_perl.pl”.
Both SOAP and GUI use common work functions, this way we abstract
functionality from the user input system (GUI, SOAP) and make code more manageable.

I would appreciate any feedback on the code, does this approach seem sane and what is your opinion, should more functionality be added this way, for example the adding of devices, trees...


Attachments:
File comment: Cacti Soap-server
SOAP_Server.zip [78.12 KiB]
Downloaded 644 times
File comment: Cacti Soap-client for adding graphs, devices, trees.
SOAP Client.zip [8.02 KiB]
Downloaded 581 times
Cacti SOAP service.png
Cacti SOAP service.png [ 26.24 KiB | Viewed 15252 times ]


Last edited by glista on Tue Jul 01, 2008 6:34 am, edited 13 times in total.
Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 10:36 am 
Offline
Cacti User

Joined: Thu May 03, 2007 9:03 am
Posts: 127
Hello!!!!

So, i am using the quick and dirty script, and it is wonderfull, when i found how it works.
I have created a little script in php to use those scripts and i have added some 6 device with something like 80 scripts. It tooks me on minutes to create all that. So it is reaaly use full to me.

Thanks you very very very much :d I love Those Dirty Scripts


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 3:19 am 
Offline
Cacti User

Joined: Thu May 03, 2007 9:03 am
Posts: 127
Some question about the dirty script :
Can i Add a device which is not already connected on the network?
If it is possible with the script please could you tell me how to do that?

Thkx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 4:03 am 
Offline
Cacti User
User avatar

Joined: Wed Nov 09, 2005 8:35 am
Posts: 240
Location: Timisoara, Romania
danathane wrote:
Some question about the dirty script :
Can i Add a device which is not already connected on the network?
If it is possible with the script please could you tell me how to do that?

Thkx


you can not, you need to get the informations from the device ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 5:01 am 
Offline
Cacti User

Joined: Thu May 03, 2007 9:03 am
Posts: 127
ok thx for answering, and through the web interface? is it possible to add a device which isn't connected?

thx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 7:33 am 
Offline
Cacti User
User avatar

Joined: Wed Nov 09, 2005 8:35 am
Posts: 240
Location: Timisoara, Romania
danathane wrote:
ok thx for answering, and through the web interface? is it possible to add a device which isn't connected?

thx


if you dont need any information from that device... just do it...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 9:50 am 
Offline

Joined: Tue Feb 13, 2007 5:14 pm
Posts: 6
Location: Columbus, OH
It is possible to add a device in disabled mode with the add_devices.php script by passing a 1 as the last argument. just execute the add_devices.php for more explanation of the usage.

I think this will accomplish what you wish, to add devices to Cacti before they are on the network without the poller freaking out too bad.


Top
 Profile  
 
 Post subject: Cacti SOAP Client for adding multiple hosts, graphs, trees
PostPosted: Mon Jun 11, 2007 8:15 am 
Offline

Joined: Mon Mar 19, 2007 12:43 am
Posts: 10
SOAP adding multiple graphs manual

Before we can use soap client make sure that the soap server for cacti is installed and configured.

Soap client installation instructions:
1. Use PHP 5.x (with SOAP support)
2. Extract files from “cacti-import.zip”
3. Open the command line interface and got to the directory where you've extracted the files. There you will find tools for adding large sets of devices, graphs and trees.

Usage instructions:

Importing multiple hosts:

We need to create a CSV source file “host.csv” (this is just an example; of course you can choose a different name). Every record is a separate row of data. Every row is in the following format:
<fqdn>;<name>;<community>;<snmp_ver>;<disable>;<snmp_username>;<snmp_password>;<snmp_port>;<snmp_timeout>;<template_name>

Description of fields:
<fqdn> - FQDN or IP address of the host,
<name> - device name,
<community> - community name,
<snmp_ver> - snmp version values: 1, 2, 3,
<disable> - host is disabled (value 1) or host is enabled (value 0),
<snmp_username> - username if we use snmp version 3,
<snmp_password> - password if we use snmp version 3,
<snmp_port> - snmp port number. Default value is 161,
<snmp_timeout> - snmp timeout in milliseconds,
<template_name> - This is host template name. Go to cacti web interface. Click “Host Templates”. Select host template for new device. Copy entire field for name (watch out for empty strings) and paste it here.

An example of the “host.csv” file:

“host1”;”hostname1”;”com123”;2;0;;;161;500;”Cisco Router”
“host2”;”hostname2”;”com123”;2;0;;;161;500;”Cisco Router”
“host3”;”hostname3”;”com123”;2;0;;;161;500;”Cisco Router”


After we have the “host.csv” file, we can run the command:

php auto_add_devices_cl.php --urn="<hostname>:<port>/cacti" --username="soap"
--password="soap" --source="C:\\path\\host.csv"

--urn: is the location where cacti service is running. If you are running both cacti service and client in local machine, just type: --urn=localhost/cacti or --urn=localhost
--source: is location of the CSV file. For delimiter between directory and subdirectory use double slash (“\\”).

Script “auto_add_devices_cl.php” will generate two files named after a source file but with added suffix “log.csv” and “err.csv”. First file contains the data that was successfully imported to Cacti service. We can find it in file “host.csv.log.csv” and second file “host.csv.err.csv” contains data which failed to be imported. These files have the same structure as the source file.


Importing graphs and trees

We need to create a CSV source file “graph.csv” (this is just an example; of course you can choose a different name). Every record is a separate row of data. Every row is in the following format:
<fqdn>;<subdescr>;<graphTemplateName>;<snmpQueryName>;<snmpQueryTypeName>;<snmpFieldName>;<snmpValueName>;<page>;<section>

We can create custom graphs (CG) or data sources (DS) graphs. For CG graphs use empty values for snmpQueryName, snmpQueryTypeName, snmpFieldName and snmpValueName.
The flowing example will show how we create data sources graphs:

Description for each column:
<fqdn> - FQDN or IP address of the host.

<subdescr> - sub description of the graphs for this host. We can use defined variables for generating descriptions (|host_description|, |host_name|, |query_inxmlfile| etc.). We can use generated sub descriptions defined in Cacti Data Queries template if we leave this value empty.

<graphTemplateName> - This is a graph template name. Go to cacti web interface. Click “Graph Templates”. Select graph template for new graphs. Copy entire field from name and paste it here. Watch out for empty strings.

<snmpQueryName> - This is a data query template name. Go to cacti web interface. Click “Data Queries”. Select data query for new graphs. Copy entire field from name and paste it here. Watch out for empty strings.

<snmpQueryTypeName> - Go to cacti web service. Click “Data Queries”. Select data query for new graphs. Go to selected record in table “Associated Graph Templates”. Copy entire content from the name field and paste it here.

<snmpFieldName> - Field name for selected device interfaces. Click “Data Queries”. Select data query for new graphs. Here we can find full file path of used xml query. Open this xml file. We can see the list of all query fields for the selected data query template.

<snmpValueName> - It contains value from selected “<snmpFieldName>”. Click “New Graphs”. Select host name and graph types. Now we can see table of all input fields and their values. We can select only value in column that we defined in “<snmpFieldName>”.

<page> - This is the name of tree in root position.
For adding graphs to existing menus; go to cacti web interface. Click “Graph Trees”. Select the record in table option. Copy entire field from name and paste it here. Watch out for empty strings.
Or if we would like to add a new menu just enter a new name. If the value is empty, then the column name section is ignored. The script will put graphs in root of cacti menu,

<section> - This is the name of sub tree. This has a status of child. The left column is parent name a “<page>”. If this value is empty then column section is ignored. The script will put all graphs in parent of Cacti menu,

Sample of “graph.csv” file:

host1”;;”Interface - Traffic (bits/sec)”;” SNMP - Interface Statistics”;” In/Out Bits (64-bit Counters)”;”ifOperStatus”;”Up”;”Page1”;”Section1”

Now we have a graph.csv file. Then we run two commands:

1. Command: For adding graphs:
php auto_add_graphs_cl.php --urn="<hostname>:<port>/cacti" --username="soap" --password="soap" --source="C:\\path\\graph.csv"

2. Command: Adding trees and graphs to the trees:
php auto_add_trees_cl.php --urn="<hostname>:<port>/cacti"--username="soap" --password="soap " --source="C:\\path\\graph.csv"

First command for adding graphs will create all graphs for monitored interfaces traffic for selected host. We will use SNMP version 2 which supports 64bit counters. In the name field we enter: ”ifOperStatus”. This will ask for status for each interface. Interface has a status “Up” or “Down”. We fill filed “<snmpValueName>” with value “Up”. This will select all the interfaces for selected host which status name “ifOperStatus” is “Up” and it will create a traffic graphs for selected interfaces.

Second command for adding trees will put all created graphs for selected host to the menu of cacti tree.


Attachments:
File comment: Tools for adding multiple hosts, graphs, trees via Cacti SOAP calls
SOAP_Cacti_Import.zip [67.63 KiB]
Downloaded 566 times


Last edited by glista on Tue Jul 01, 2008 6:32 am, edited 6 times in total.
Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 12:16 pm 
Offline

Joined: Fri Jun 08, 2007 11:10 am
Posts: 9
Any suggestions on how to bulk import hosts using this method if i want to leave the community string empty (without rewriting it the script, I mean?).

I just want to bulk add a large number of remote hosts for which I'm doing nothing but advanced ping statistics - no SNMP - and I don't want cacti to attempt any SNMP contact (because they'll fail, of course!).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 1:14 pm 
Offline

Joined: Tue Jun 05, 2007 2:17 pm
Posts: 3
I've read through this thread a few times now and there are some great tools here.

I'm currently stuck on a problem and I can't seem to figure out if the solution is here in the thread or not and I could use some help.

Here is what I want to do:

I want to add a graph to cacti from the command line. The graph's data will come from a perl script.

I've been able to use Glista's script to add a perl script to cacti as a Data Input Method.

The question now is: How do I now create a Data Source which uses that input method? And then how do I add a graph to Cacti that uses that Data Source?

It seems all the methods listed here for adding graphs to cacti via the command line revolve around SNMP queries for data, which I'm not using. Or they require a new Data Template for each graph... which doesn't seem to help since I'd have to create a new template for each graph through Cacti's interface (with a new Data Source for each one) therefore defeating the purpose (unless I'm not understanding properly).

Any help or direction would be greatly appreciated.

Cliff notes:

I want to add graphs to cacti from the command line. These graphs are going to use Data Sources that use scripts for input methods (no snmp). I also need to add the Data Sources to cacti through the command line for the graphs to use. how can I do this?


Top
 Profile  
 
 Post subject: Re: A wrapper for Bradley's scripts
PostPosted: Fri Jun 15, 2007 12:26 pm 
Offline

Joined: Wed May 10, 2006 5:16 pm
Posts: 7
stutz wrote:
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.
Stutz, I simplified your script to only add devices. Other various (simplification) changes made.


Attachments:
File comment: create file server.txt file with a list of your servers and modify the variables in the script to suite your environment.
import_deviceonly.sh [937 Bytes]
Downloaded 687 times
Top
 Profile  
 
 Post subject: Newbie Question for Adding Multiple Hosts in One Shot.
PostPosted: Sun Sep 16, 2007 6:50 pm 
Offline

Joined: Wed Jul 11, 2007 12:42 pm
Posts: 10
OK.

I understand that there are several posts about Adding a large amount of devices to Cacti. However, currently my experience with Cacti is very vague. So if someone would be so kind to give me additional info...

My situation:
I have 300 Servers ( All Win2K3, all on the same domain, with same SNMP Community. )
Is the best way to add all these devices with the add_devices.php ?
If so, as painful as it may be for someone, could someone give me additional detail on how to run it? Such questions I have in mind: Where exactly do you need the add_devices.php file located on Cacti Server ? Also, do i Just run the command from a Windows Dos Cmd Promp? Do i need to run it in the Dos window in any specific directory? Do you have to do the same command line, one server after another, or can this be ran by looking at a txt file of some sort that has a list of the servers i would like to add? Also If you could, could you please give me an example of what the command would look like?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 2:31 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22376
Location: Muenster, Germany
Currently, the files are placed into main cacti directory and run from there, only on the cacti server itself.
With 0.8.7, they are moved to the ./cli directory and will be officially supported
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: wsdl file?
PostPosted: Mon Dec 10, 2007 4:12 pm 
Offline

Joined: Thu Aug 24, 2006 8:09 pm
Posts: 4
Hi,

Is a wsdl file available for the soap stuff? I'd like to interface to it in Powershell on windows and that would sure make the job easier.

Thanks,

- Robbie


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 11:05 am 
Offline

Joined: Wed Dec 19, 2007 10:56 am
Posts: 2
Hi everyone,

Thes scripts seem great. But I have an error message when using it.

I changed the following lines from the add_graphs.php file from :

include(dirname(__FILE__)."/include/config.php");
include_once($config["base_path"]."/lib/data_query.php");
include_once($config["base_path"]."/lib/utility.php");
include_once($config["base_path"]."/lib/sort.php");
include_once($config["base_path"]."/lib/template.php");
include_once($config["base_path"]."/lib/api_data_source.php");
include_once($config["base_path"]."/lib/api_graph.php");
include_once($config["base_path"]."/lib/snmp.php");
include_once($config["base_path"]."/lib/data_query.php");
include_once($config["base_path"]."/lib/api_device.php");

To :

include(dirname(__FILE__)."/config.php");
include_once($config["base_path"]."/usr/share/cacti/lib/data_query.php");
include_once($config["base_path"]."/usr/share/cacti/lib/utility.php");
include_once($config["base_path"]."/usr/share/cacti/lib/sort.php");
include_once($config["base_path"]."/usr/share/cacti/lib/template.php");
include_once($config["base_path"]."/usr/share/cacti/lib/api_data_source.php");
include_once($config["base_path"]."/usr/share/cacti/lib/api_graph.php");
include_once($config["base_path"]."/usr/share/cacti/lib/snmp.php");
include_once($config["base_path"]."/usr/share/cacti/lib/data_query.php");
include_once($config["base_path"]."/usr/share/cacti/lib/api_device.php");
include_once($config["base_path"]."/usr/share/cacti/lib/database.php");
include_once($config["base_path"]."/usr/share/cacti/lib/functions.php");

This is what I have when executing the script :

Shell % php add_graphs.php --graph-type ds --graph-template-id 110 --host-id 229 --snmp-query-id 1 --snmp-query-type-id 69 --snmp-field ifIndex --snmp-value 1000

Fatal error: Call to a member function SetFetchMode() on a non-object in /usr/share/cacti/lib/database.php on line 155
zsh: exit 255 php add_graphs.php --graph-type ds --graph-template-id 110 --host-id 229 1

The line 155 is :

$cnn_id->SetFetchMode(ADODB_FETCH_ASSOC);

I am not really good in programing... Cacti is hosted on a Fedora Core 6, PHP5.

Does anyone have any aidea ?

Thanks in advance.


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

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


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