Help with script basics

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

Moderators: Developers, Moderators

Post Reply
orjanb314
Posts: 6
Joined: Fri Aug 01, 2008 7:40 am

Help with script basics

Post by orjanb314 »

Hi,

I'm completely new to both cacti and perl scripting and I'm currently trying out some basics with using scripts to expand cactis data gathering capabilities.

I have followed a howto guide to graph the output of the following script, which is working now. This script pings the host supplied as input and graphs the round trip time.

#!/usr/bin/perl
$ping = `ping -c 1 $ARGV[0] | grep icmp_seq`;
$ping =~ m/(.*time=)(.*) (ms|usec)/;
print $2;


The next step I'm trying is to make a very simple script which only returns a constant value and the goal is that cacti makes a flat, constant value graph. This is the script I have made:

#!/usr/bin/perl
$test = 200;
print $test;

I just want to confirm that this script should in theory do the job so I'll know if it's the script or the setup of all the templates and stuff in cacti that is wrong. Because all I'm getting in the graph overview is an emtpy graph.[/img]
User avatar
kramsay
Posts: 35
Joined: Fri Jan 21, 2005 1:42 pm

Post by kramsay »

Your script can be tested from the command line using

#/usr/bin/perl "your_script_name"

Your script is fine. If you are getting an empty graph there is lots of help on this forum. Just search "empty graphs"
=(8-0-)
orjanb314
Posts: 6
Joined: Fri Aug 01, 2008 7:40 am

Post by orjanb314 »

I'm still having trouble with getting Cacti to graph a constant value returned by a script. I have made some progress though with this script:

#!/usr/bin/perl
$k = $ARGV[0];
print $k;

It simply returns the value supplied as input, and with this script I get the flat graph I was looking for. The only thing I can think of myself is the format the return value has. I'm used to Integer, double, string etc. from java and not used to the idea of variables in perl. But I guess Cacti should understand it anyway if I define a variable as $number = 200;

Because what it seems to me is that Cacti only understands the variable it has supplied itself and not the ones I try to give it from the script.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please see 1st link of my sig for help
Reinhard
shull
Cacti User
Posts: 54
Joined: Thu Aug 24, 2006 1:20 am
Location: South Texas
Contact:

Post by shull »

I have a site called http://www.cactiexchange.com. There are some tools to help with scripting. Also, I will soon be adding some basic info about running and creating external scripts.


-Stephen
www.cactiexchange.com -- Hosted Tools for the Cacti Community:
Cacti Perl Tool
Cacti XML Tool
Search OID-to-Names

[url=http://www.google.com/search?num=100&hl=en&safe=off&domains=forums.cacti.net&q=cacti&sitesearch=forums.cacti.net]Cacti Forums Google Index -- Better than the main page version![/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests