Need help with $ARGV[1]...I'm just not getting it....

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

Moderators: Developers, Moderators

Post Reply
rafchumley
Posts: 19
Joined: Tue Jan 25, 2005 2:17 pm

Need help with $ARGV[1]...I'm just not getting it....

Post by rafchumley »

Hello, and Thanks for reading this.

It will quickly become obvious that I am a newbie when it comes to this stuff., so please bear with me.

My issue is with $ARGGV[1}...where does Cacti get that value from? For example, looking at this script:

Code: Select all

#!/usr/bin/perl



$a = q!-p 1248 -v COUNTER -l!;

$b = q!"\\MSExchangeIS Mailbox(!;

$c = q!)\\Average Delivery Time"!;



$time = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] $a $b$ARGV[1]$c`;

chomp ($time);

print "$time\n";
Where do put in the value of $ARGV[1] such that it will be properly inserted into the script? It seems $ARGV[0] is from <grepstr1> in my data source, i.e. "perl <path_cacti>/scripts/MSExchangeIS_Inbound_Bytes.pl.pl <grepstr1>". I then define the value of "grepstr1" as "hostname". I've tried to follow that out logically and use "perl <path_cacti>/scripts/MSExchangeIS_Inbound_Bytes.pl.pl <grepstr1> <grepstr2>" then define "<grepstr2>" as the value "(_Local)", which is the instance of the counter I am looking for...but that doesn't seem to work. I waited 45 minutes and got zip from that...

Any reply would be greatly appreciated. I have read the docs and searched the forums to no avail....at least nothing that speaks to my knowledge level. I can't even seem to find out if my formatting of the script line, i.e. using more than 1 <grepstr> with nothing but a space between them, is correct.

Thanks!

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

Post by gandalf »

It seems that you are defining a Data Input Method, in your case implemented as a perl script. All input parameters must be specified both
- on the command line, e.g. as <in1> <in2> <in3>
- as Input Fields with the same name(s)
Output fields have to be specified accordingly. (see pic "Data Input Method")

Example:
When defining the Data Template, you will refer to the Data Input Method you defined (see pic "Data Template 1").
You have the choice to
- predefine Input values for all Data Sources to be defined with this Template (see pic "Data Template 2, right ellipsoid)
- or to provide different Input values each time you create a new Data Source (see pic "Data Template 2" left ellipsoid). You will then be prompted to enter this value each time you create a new Data Source.
Perhaps things become more clearly, when experimenting e.g. with this template at your own...

hth
Reinhard
Attachments
Data Template 2
Data Template 2
data_template-2.png (13.98 KiB) Viewed 2545 times
Data Template 1
Data Template 1
data_template-1.png (14.26 KiB) Viewed 2545 times
Data Input Method
Data Input Method
data_input_method.png (27.31 KiB) Viewed 2545 times
rafchumley
Posts: 19
Joined: Tue Jan 25, 2005 2:17 pm

Here is what I have set up...all is nan on graph

Post by rafchumley »

First off...THANK YOU for the reply!

I feel I've done exactly as you've said but no joy.

In my earlier post I used an example script. This is the actual script I am using:

#!/usr/bin/perl

$a = q!-p 1248 -v COUNTER -l!;
$b = q!"\\MSExchangeIS Mailbox(!;
$c = q!)\\Client Logons"!;
$d = q!"\\MSExchangeIS Mailbox(!;
$e = q!)\\Active Client Logons"!;

$client = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] $a $b$ARGV[1]$c`;
$aclient = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] $a $d$ARGV[1]$e`;
chomp ($client);
print "$client\n";
chomp ($aclient);
print "$aclient\n";


So using this script, I then created my Data Input Method. The full "Input String" command line is:

perl <path_cacti>/scripts/MsExchangeIS_User_Conn.pl <grepstr1> <grepstr2>

I then defined grepstr1 as special type code hostname, and gave grepstr2 the friendly name "Instance Name", as that is the role it plays in the script.

Then on my Data Template, I put in the value (_Total). Note that it would NOT allow me to save successfully if I just checked the box for "Use Per-Data Source Value". So for now I "hard coded" the value to (_Total).

My goal here is to have the section of the script including $ARGV[1] end up being interpreted as "\\MSExchangeIS Mailbox(_Total)\\Client Logons", which returns the proper values when run from a CLI.

My graphs remain at "nan", though they are made.

Below is my setup "as built". Again, I appreciate your reply to no end! THANK YOU!

Regards,

Chum[/code]
Attachments
Data Template.PNG
Data Template.PNG (39.67 KiB) Viewed 2512 times
Data Input Method.PNG
Data Input Method.PNG (18.44 KiB) Viewed 2512 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Here is what I have set up...all is nan on graph

Post by gandalf »

rafchumley wrote:

Code: Select all

$client = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] $a $b$ARGV[1]$c`;
$aclient = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] $a $d$ARGV[1]$e`;
chomp ($client);
print "$client\n";
chomp ($aclient);
print "$aclient\n";
This is not the recommended way to return results from scripts.
1) Please put all output into one single print statement. cactid is know not to wait for the second print statement. Even if this may work with cmd.php, you should change this.
2) Referring to http://www.cacti.net/downloads/docs/htm ... cacti.html you'll have to prefix the different output values with names, e.g. output should look like client:nn aclient: mm
I then defined grepstr1 as special type code hostname, and gave grepstr2 the friendly name "Instance Name", as that is the role it plays in the script.
hostname will always be replaced by cacti with the hostname of the device you are currently polling. This is not correct in your case!
Please follow the instruction given at http://www.cacti.net/downloads/docs/htm ... lates.html to continue with the corresponding data template.

Please provide a sample cli call of your script along with the output produced

Reinhard
rafchumley
Posts: 19
Joined: Tue Jan 25, 2005 2:17 pm

Next steps...still trying...still nan

Post by rafchumley »

Reinhard,


I am at a remote location and cannot get to my box to give you a cli readout right now. I will provide it later...but...

I rather gave up on the whole $ARGV[1] thing and went to a more basic script in an effort to just get something out of it. I removed the $a, $b, etc and "hard coded" everything but the $ARGV[0] line. I also re-did my output per what I think the docs are saying, i.e. I gave it a name like so:

The following is from memory and may not be exactly correct in syntax. It is enough tho that you can see what I did to the scripts in my "hard coding" effort. It does give the desired output from a CLI tho when run from the actual script.

Code: Select all

$client = '/srv/www/htdocs/cacti/scripts/MsExchangeIS_Conn.pl -H $ARGV[0] -p 1248 -l "\\MSExchange Mailbox(_Total)\\Client Logons"';
$aclient = '/srv/www/htdocs/cacti/scripts/MsExchangeIS_Conn.pl -H $ARGV[0] -p 1248 -l "\\MSExchange Mailbox(_Total)\\Active Client Logons"';
chomp ($client)
chomp ($aclient)
print "Total Logons:($client) Active Logons:($aclient\n)

When run from the CLI thusly: "perl MsExchangeIS_Conn.pl 172.16.1.5" it returns:

Total Logons:49 Active Logons:17

So it is getting the data correctly. I will post later with the actuals. I'm just doing this now because of timezone differences. I suspect that by the time I can post actuals you'll be soundly sleeping (I'm GMT -5) :)

Anyway..."Total Logons" and "Active Logons" are also the "Friendly Names" give to my output fields in my data input method. I have also tried "Tot_Cli_Logons" and "Act_Cli_Logons" which are the actual field names, not the friendly names. Neither has resulted in anything but "nan" values on my graphs.

Do I need to whack the graphs and data sources and re-create them for this to show up? I didn't think I did....but I suppose I will just to be sure, tho I hate deleting anything in Cacti regarding data sources...I remember the bug that deleted more than was supposed to be....and so I try to avoid it at all costs.

So thats where I am. I will whack the graphs and data sources and re-create it to see if that fixes anything.

Again, I appreciate every word you write to me. I am learning as fast as I can!

S!

Chum aka Brian
rafchumley
Posts: 19
Joined: Tue Jan 25, 2005 2:17 pm

Actual script and CLI readout...

Post by rafchumley »

S! Reinhard!

Here is the actual script...I almost had it right :)

Code: Select all

#!/usr/bin/perl



$aclient = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l "\\MSExchangeIS Mailbox(_Total)\\Active Client Logons"`;
$client = `/srv/www/htdocs/cacti/scripts/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l "\\MSExchangeIS Mailbox(_Total)\\Client Logons"`;

chomp ($client);
chomp ($aclient);

#print "Tot_Cli_Logon:$client Act_Cli_Logon:$aclient\n";
print "Total Logons:$client Active Logons:$aclient\n";
Here is the CLI readout:
scripts # perl MsExchangeIS_User_Conn2.pl 172.16.1.5
Total Logons:64 Active Logons:19
So it works fine from a CLI...but not in the graphs. The Data Input Method has 2 Output Fields defined and I have tried the script with both the regular names and the friendly names..to no avail.

But here is what I would say is a clue....from my cacti log:
10/17/2005 10:36:05 PM - CMDPHP: Poller[0] Host[20] DS[392] WARNING: Result from CMD not valid. Partial Result: Total Logons:47 Acti
Thats it...it's cut off after that....why would it be cut off in the middle of a word? Column limitation in the log?

Dag this is frustrating.....I'll try with simple one word field names in the script and see if thats any different...

Thanks Again for your help!

S!

Chum
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Maybe try removing the spaces out of the names.
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

That will fix it. Syntax error...

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
rafchumley
Posts: 19
Joined: Tue Jan 25, 2005 2:17 pm

Well....yes and no....and YES! Woot!..but 1 question remains

Post by rafchumley »

S! All!

I did remove the spaces...I also re-worked my data input method to use field names EXACTLY matching the script...and then I blew away the existing graph (that had "nan" values) and associated data sources and re-created them.

So now I am getting the Total but not the Active.....

So just now I went back to my data template and verified everything on it. It seemed to me that the issue had to lie there. Definitely everything was in place but just for kicks I re-selected the field for the "act_logon" as "Active" and saved again....now I am getting data in both areas.

SWEETNESS!

Thanks to ALL, with specials to Reinhard!

STILL...I have 1 question and it goes back to the $ARGV[1] thing.....

When using check_nt and monitoring performance counters, there are "instances" to be considered. For example, I have a client with multiple web sites on 1 server, and each is a measurable "instance" to perfmon. I know I can use the script command line and specify the value of $ARGV[1] there but....

Can I make a SINGLE data input method and "fill in the instance" when I create the graph for the host? How would I do that? I tried it thusly:

Create a data input method and in the script command string, after the <grepstr1> I put "<instance>". Then in the Data Input field I gave it only a friendly name.

Moving to the Data Template I see there are 2 fields in the "Custom Data" area. I don't want to define the instance field, so I check the "per-data source value"...and it complains upon saving. It appears to save though, i.e. if I navigate away and come back the field is there empty...but the per-dat check box is not checked....so maybe it's not saving? I stopped at that point as it seemed all the pieces were not in place....

I want to be able to, when creating the graph for the device, specify the instance to be monitored. Is there a way to do this?? Do I have to create a data input method and data template and graph for each instance I want to monitor?

Or am I missing something (a much more likely scenario, lol!)?

Oh yes..one other thing....through all my fussing and farting around with my Exchange connections, I now have several "tot_logon.rrd" files in my RRA dir. Can I delete those that are older? Only one shows modified "today at...". I should be able to safely whack the older ones, yes?

Again...thanks for helping this non-scripter out. If you ever need help with BGP, networks, and routing, I am your man. But Perl scripts are not my forte, most obviously!

S! (Salute!)

Chum
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests