add data source CLI script

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Moderators, Developers

Post Reply
Author
Message
ghartung13
Posts: 11
Joined: Mon Feb 08, 2010 7:00 pm

add data source CLI script

#1 Post by ghartung13 » Mon Jun 14, 2010 1:03 pm

I see a few older posts asking for this, but the only conclusion seems to be to use the add_graphs.php script.

Unfortunately, this isn't enough info to help me.

Does this mean that I'm supposed to modify the script? That seems hugely intimidating since the whole point is to avoid screwing up the db.

Or that it supports adding data_sources? If so, is there an example?

Has anyone successfully done this? I have thousands of data sources to add.

Thanks!!
Greg

ghartung13
Posts: 11
Joined: Mon Feb 08, 2010 7:00 pm

#2 Post by ghartung13 » Mon Jun 14, 2010 5:25 pm

OK, no response, so I just started trying things. Eventually I got this to work, sort of:

shell>php -q add_graphs.php
--host-id=46
--graph-type=cg
--graph-template-id=39
--input-fields="51:basestation=00-00-3a-20-0c-12"
--graph-title="au3-bs1.htsl1"
--force

Which worked perfectly, except it doesn't fill in the name for the data source. Which is why I had to use --force.

I have "Use Per-Data Source Value" for the Name in the Data Template.

However, the script ignores the checkbox in the data template for Name. It leaves the resulting data source name blank if the template is blank, or puts the value from the template in the data source if the template has something in the value.

It looks like the script needs a --data-source-name or should put the title for the graph in the data source name.

And the docs should mention something about add_graphs will create the datasource also.

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#3 Post by gandalf » Tue Jun 15, 2010 2:12 am

ghartung13 wrote:OK, no response, so I just started trying things. Eventually I got this to work, sort of:

shell>php -q add_graphs.php
--host-id=46
--graph-type=cg
--graph-template-id=39
--input-fields="51:basestation=00-00-3a-20-0c-12"
--graph-title="au3-bs1.htsl1"
--force

Which worked perfectly, except it doesn't fill in the name for the data source. Which is why I had to use --force.
What did you expect?
I have "Use Per-Data Source Value" for the Name in the Data Template.
Please post data of that Data Template.
However, the script ignores the checkbox in the data template for Name. It leaves the resulting data source name blank if the template is blank, or puts the value from the template in the data source if the template has something in the value.
Ok, again you seem to expect specific handling of ds names. Honestly, I don't know how this is handled by the script right now.
And the docs should mention something about add_graphs will create the datasource also.
Good hint. Will add some words in a mo'

It would help a lot to know, which version of cacti you're using. And as in all previous posts, I do not understand why you want to add a data source alone, without any graph. So we should talk about the context to avoid stumbling from one problem to the next.
R.

ghartung13
Posts: 11
Joined: Mon Feb 08, 2010 7:00 pm

#4 Post by ghartung13 » Tue Jun 15, 2010 11:46 am

0.8.7e

I was trying to do 2 things:

1. Emulate the manual process I used to add a datasource and graph. I asked for a script to add a datasource because the docs didn't indicate that add_graphs does that too. So I don't need an add_data_source script now.

2. Once I realized that and ran the add_graphs script, what I need is for it to add the datasource with a name that matches how I am doing it manually. Meaning, when I add a datasource manually, I specify a name that is unique to each datasource. The add_graphs script doesn't do this as I described in the previous post. I need a --data_source_name option to specify the name for the datasource where I would simply make it match the graph name, or for the script to assume that it should be named the same. The fact that the script has a --force option means the author realized that every datasource would get the same name, which is not desirable.
Attachments
Untitled 3.jpg
Untitled 3.jpg (217.85 KiB) Viewed 6734 times

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#5 Post by gandalf » Tue Jun 15, 2010 12:54 pm

Ok, now I understand better. The hint to the documentation has already been added. I will consider a new parameter for the data source's name for cacti 088. To track this, it would be helpful to submit this as a new mantis ticket as given by http://www.cacti.net/bugs.php
R.

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#6 Post by gandalf » Fri Jun 18, 2010 2:47 pm

Unfortunately, a single graph template may be associated with different data templates. Thus, there's not necessarily a single --data-soure-title. See e.g. "ucd/net - CPU Usage".

An option might be to use
--data-source-title="4:title no 1"|"5:title no 2"|"6:title no 3"
or similar

R.

Epx998
Posts: 19
Joined: Wed Oct 12, 2011 2:48 pm

Re: add data source CLI script

#7 Post by Epx998 » Fri Aug 10, 2012 11:11 pm

I am running into a similar issue myself. I need to have a unique internal datasource name when I add graphs from the add_graphs.php cli, any chance this has been addressed in 0.88, or if there is a work around that will allow me to do this without using the gui?

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: add data source CLI script

#8 Post by gandalf » Thu Aug 23, 2012 2:41 pm

Please explain in more detail what you want to achieve. CLI has been completely reworked for 089
R.

kaf3773
Posts: 21
Joined: Sun Sep 09, 2012 8:48 pm

Re: add data source CLI script

#9 Post by kaf3773 » Tue Sep 11, 2012 10:30 pm

Although add_graphs.php creates the data source it leaves the Data Source Path field empty.

Is there anyway the script can also fill in the data source path?

Clarification will be very much appreciated

Thanks

ypant
Posts: 3
Joined: Sun Nov 04, 2012 11:25 pm

Re: add data source CLI script

#10 Post by ypant » Mon Nov 19, 2012 9:23 am

Any further updates on this subject? No followup posting since Sept 2012.

Looks like there is a lot of request for this type of scripting needs. Per Gandalf, the new functionality is available in 0.8.9. This version is not available in the webpage for download, but I have downloaded a copy from svn. So is this version ready for some basic sanity testing? Thank you so much.

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: add data source CLI script

#11 Post by gandalf » Tue Nov 20, 2012 5:09 pm

ypant wrote:Any further updates on this subject? No followup posting since Sept 2012.

Looks like there is a lot of request for this type of scripting needs. Per Gandalf, the new functionality is available in 0.8.9. This version is not available in the webpage for download, but I have downloaded a copy from svn. So is this version ready for some basic sanity testing? Thank you so much.
Yes, this is it. I backported the cli scripts from main trunk to 089 branch. There's already a thread in the unstable forum to discuss possible issues.
R.

mcqueenorama
Posts: 2
Joined: Tue Nov 27, 2012 9:36 pm

Re: add data source CLI script

#12 Post by mcqueenorama » Tue Nov 27, 2012 9:39 pm

I've made a simple change to the script to suit my purposes. I think it probably ought to go into the tool. I made it accept snmp version=0, since I'm adding hosts that are using external rrds.

/* process snmp information */
if ($snmp_ver != "0" && $snmp_ver != "1" && $snmp_ver != "2" && $snmp_ver != "3") {
echo "ERROR: Invalid snmp version ($snmp_ver)\n";
exit(1);
}else{
if ($snmp_port <= 1 || $snmp_port > 65534) {
echo "ERROR: Invalid port. Valid values are from 1-65534\n";
exit(1);
}

if ($snmp_timeout <= 0 || $snmp_timeout > 20000) {
echo "ERROR: Invalid timeout. Valid values are from 1 to 20000\n";
exit(1);
}
}

/* community/user/password verification */
if ($snmp_ver == "0" || $snmp_ver == "1" || $snmp_ver == "2") {
/* snmp community can be blank */
}else{
if ($snmp_username == "" || $snmp_password == "") {
echo "ERROR: When using snmpv3 you must supply an username and password\n";
exit(1);
}
}

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: add data source CLI script

#13 Post by gandalf » Thu Nov 29, 2012 4:25 pm

Sorry, but which file should be patched at which line?
Usually, those requests go into http://bugs.cacti.net
And please know, that add_graphs.php has been kept for compatibility reason, but graph_create.php is the new script accepting more input parameters to select devices
R.

mcqueenorama
Posts: 2
Joined: Tue Nov 27, 2012 9:36 pm

Re: add data source CLI script

#14 Post by mcqueenorama » Mon Dec 03, 2012 7:12 pm

Those lines are for add_device.php.

Thanks for the tip about graph_create.php. I guess I have an old version.

Post Reply