What I don’t know is if I can take the information from the templates and script, and create a function in The Dude to do the same thing. Does anyone have an elegant approach to this?
I don’t know, maybe if this ASSP supports SNMP (well if cacti can read it, so can Dude) then you could try to do a SNMP-walk from Dude and see what it finds on this machine. I suspect it’s all obfuscated, otherwise Cacti wouldn’t need funky perl scripts and XML to connect to it.
I agree that SNMP support is probably not existent in ASSP-- otherwise graphing it in Cacti would be much easier as well. So, assuming that the obfuscated way is the only way to get this done, could anyone outline a best path to follow?
I no programmer/scripter, but looking at the script it seems that it simply gathers all the data it needs from the web interface and prints it all on one line. How should this be altered to make it easy to use by The Dude? I guess the script is small enough I’ll just post the whole thing:
#!/usr/bin/perl
# script to get assp statistics
#
# please edit the username - passwd - ip address before you use it.
#
#
# Created by Luuk de Boer - 30 - 03 - 2005
# Modified October 2006 for version 1.2.3
#
use LWP;
use HTTP::Cookies;
$| = 1;
my $ua = new LWP::UserAgent;
#
#
# Modify these 3 lines for your system.
$username = "admin";
$passwd = $ARGV[0];
$ipaddress = $ARGV[1];
$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
#$ua->proxy('http','http://:8080/');
$cookie_jar = new HTTP::Cookies;
$cookie_jar->{'hide_cookie2'} = 1;
$cookie_jar->{'set_version'} = 0;
$ua->cookie_jar($cookie_jar);
#print "getting url\n";
# Original line below:
# $starturl = 'http://'.$username.':'.$passwd.'@'. $ipaddress.':55555/stats';
$starturl = 'http://'.$username.':'.$passwd.'@'. $ipaddress.':55555/infostats';
$request = new HTTP::Request('GET', $starturl);
$response = $ua->request($request);
@pagelines = $response->content =~ /(.*\n?)/g;
$nr = 0;
foreach $line (@pagelines) {
chomp($line);
$line =~ s/\r//g;
# print "($line)\n";
if ($line =~ /SMTP Connections Received:/i) {
$line2 = $pagelines[$nr+2];
# print "line2 = $line2 **\n";
if ($line2 =~ /2">(\d+)<\/td/i) {
$smtpcon = $1;
# print "SMTP CONNECTIONS = $smtpcon **\n";
}
}
elsif ($line =~ /Messages Processed:/i) {
$line2 = $pagelines[$nr+2];
# print "line2 = $line2 **\n";
if ($line2 =~ /2">(\d+) \(\d+/i) {
$totmess = $1;
# print "Messages Processed = $totmess **\n";
}
}
elsif ($line =~ /Bayesian Spams:/i) {
$line2 = $pagelines[$nr+2];
# print "line2 = $line2 **\n";
if ($line2 =~ /2">(\d+)<\/td/i) {
$bayspam = $1;
# print "Bayesian Spam = $bayspam **\n";
}
}
elsif ($line =~ /Local:/i) {
$line2 = $pagelines[$nr+2];
# print "line2 = $line2 **\n";
if ($line2 =~ /2">(\d+)<\/td/i) {
$locmail = $1;
# print "Local Mails = $locmail **\n";
}
}
elsif ($line =~ /Whitelisted:/i) {
$line2 = $pagelines[$nr+2];
# print "line2 = $line2 **\n";
if ($line2 =~ /2">(\d+)<\/td/i) {
$whitemail = $1;
# print "Whitelisted Messages = $whitemail **\n";
}
}
$nr++;
}
print "smtpcon:$smtpcon totmess:$totmess bayspam:$bayspam locmail:$locmail whitemail:$whitemail";
I’ll start with what seems to be the easiest way-- Can I simply call a Perl script inside a Dude Function?
To test this out, I modified that script to just return one number-- the total number of smtp connections.
I made a Dude Function called assp_smtpcon():
array_element(execute(“perl.exe”,“asspstats.pl password 192.168.x.x”,“c:\perl\bin”),“1”)
I made a Dude Probe assp_smtpcon:
Type: Function
Available: assp_smtpcon() > 0
Error: “”
Value: assp_smtpcon() > 0
Unit:
Rate: None
The Function works, as I’m using it in the Device Appearance. There must be something wrong I’m doing with the Probe, because the probe’s graph stays at 0. The interesting thing is that if I take out the “array_element()” from the Function and put it in the probe instead, it graphs!
I’m still getting hung up here. Does anyone know why a function’s results would display correctly in a device’s appearance label, but stay at 0 when used in a probe or a manually created data source?
Any ideas would be appreciated.
Added note: When I initially created the data source, I clicked “Test” and it returned the correct result. Since it has been created, the Test button (along with the Walk button) has disappeared, but at least I know the data source was correctly receiving the function’s results.