Mailing List Archive

Perl scripts
Hi,

I'm trying to use the embedded perl interpreter in wackamole to reconfigure
my services when an VIF comes up. I want to start an instance of Exim smtp
server listening on port 25 on the newly acquired IP address, but only for
certain addresses.

I've managed to get a perl function logging to syslog, but I don't see how
to work out what the new IP address is. Does the perl function get called
with any parameters? Is there a way to do that? If not, is there another
way of deciding which interfaces just came up?

I'm using MacOSX 10.4 with this config:

# Named socket for online control
Control = /var/run/wack.it
PerlUseLib /opt/local/etc/
PerlUse wackamole
RunDynamic wackamole::mysub on up

mysub just prints a string to syslog. I tried to capture arguments passed
to mysub by dumping $_ into the string, but couldn't make any sense of the
output. That could be my perl ignorance, though.
--
Ian Eiloart
IT Services, University of Sussex

_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users
Re: Perl scripts [ In reply to ]
On Jun 23, 2006, at 12:16 PM, Ian Eiloart wrote:

> Hi,
>
> I'm trying to use the embedded perl interpreter in wackamole to
> reconfigure my services when an VIF comes up. I want to start an
> instance of Exim smtp server listening on port 25 on the newly
> acquired IP address, but only for certain addresses.
>
> I've managed to get a perl function logging to syslog, but I don't
> see how to work out what the new IP address is. Does the perl
> function get called with any parameters? Is there a way to do that?
> If not, is there another way of deciding which interfaces just came
> up?

It isn't doc'd. check in perl.c: you get three arguments:

(1) hash ref with the psuedo interface that was affected.
(2) an array ref of hashrefs of the extra interfaces associated with it
(3) hash ref with the real interface that was affected.

These are complicated to explain, I suggest Dumper'ing them to see
what you get first -- it might be obvious at that point.

> I'm using MacOSX 10.4 with this config:
>
> # Named socket for online control
> Control = /var/run/wack.it
> PerlUseLib /opt/local/etc/
> PerlUse wackamole
> RunDynamic wackamole::mysub on up
>
> mysub just prints a string to syslog. I tried to capture arguments
> passed to mysub by dumping $_ into the string, but couldn't make
> any sense of the output. That could be my perl ignorance, though.

use Data::Dumper;
print LOGFILE Dumper(\@_);


// Theo Schlossnagle
// CTO -- http://www.omniti.com/~jesus/
// OmniTI Computer Consulting, Inc. -- http://www.omniti.com/
// Ecelerity: Run with it.



_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users
Re: Perl scripts [ In reply to ]
>> I've managed to get a perl function logging to syslog, but I don't
>> see how to work out what the new IP address is. Does the perl
>> function get called with any parameters? Is there a way to do that?
>> If not, is there another way of deciding which interfaces just came
>> up?
>
> It isn't doc'd. check in perl.c: you get three arguments:
>
> (1) hash ref with the psuedo interface that was affected.
> (2) an array ref of hashrefs of the extra interfaces associated with it
> (3) hash ref with the real interface that was affected.

Ah, that's excellent - thanks, Theo. I had managed to see that there was a
hash, and empty array (but my test case has only one IP address per VIF)
and another hash. I'd not managed to figure out the content of the hashes.
I'll put more effort in now that I know that there is valuable data there!

> These are complicated to explain, I suggest Dumper'ing them to see what
> you get first -- it might be obvious at that point.
>
>> I'm using MacOSX 10.4 with this config:
>>
>> # Named socket for online control
>> Control = /var/run/wack.it
>> PerlUseLib /opt/local/etc/
>> PerlUse wackamole
>> RunDynamic wackamole::mysub on up
>>
>> mysub just prints a string to syslog. I tried to capture arguments
>> passed to mysub by dumping $_ into the string, but couldn't make
>> any sense of the output. That could be my perl ignorance, though.
>
> use Data::Dumper;
> print LOGFILE Dumper(\@_);
>
>
> // Theo Schlossnagle
> // CTO -- http://www.omniti.com/~jesus/
> // OmniTI Computer Consulting, Inc. -- http://www.omniti.com/
> // Ecelerity: Run with it.
>
>
>
> _______________________________________________
> wackamole-users mailing list
> wackamole-users@lists.backhand.org
> http://lists.backhand.org/mailman/listinfo/wackamole-users



--
Ian Eiloart
IT Services, University of Sussex

_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users
Re: Perl scripts [ In reply to ]
OK, so here's a slightly useful example script, which logs interfaces as
they come up. It also shows how to extract the IP addresses that just came
up. For example, in future I'll use that data to bring up an Exim smtp
server listening on that IP address.

NB: The brick wall I was banging my head against today was the use of null
terminated strings in the hash keys!

My wackamole.conf file holds this segment:
------------------------------------------

# Named socket for online control
Control = /var/run/wack.it
PerlUseLib /opt/local/etc/
PerlUse wackamole
RunDynamic wackamole::onup on up

And, here's the content of wackamole.pm:
----------------------------------------

package wackamole;

use strict;
use Sys::Syslog;
use Data::Dumper;

sub logaddressup {
sleep 2;
my ($ipadd) = @_;
# let's also open a syslog facility
openlog('wackamole.pm', 'ndelay pid', 'daemon');

# this is how we address an element of the hash
# keys we could use are (all null terminated!):
# "ifname\0" eg: en0
# "broadcast\0" eg: "192.168.0.1"
# "netmask\0" eg: 255.255.255.255
# "ip\0" eg "192.168.0.1"
my $address = $ipadd->{ "ip\0" };
my $if = $ipadd->{"ifname\0"};
my $string = 'IP address '.$address.' acquired on '.$if.' ';

# make a syslog notice
syslog('notice','%s',$string);

closelog();
}

sub onup {
# we're being passed:
# 1. a hash reference describing what just came up
# 2. an array of hash references - the rest of the VIF
# 3. a hash reference with the real interface that was affected
# we'll just put them all into separate variables
my ($ipadd, $vifs, $extern) = @_;
#open (NFAM, '> /opt/local/etc/klop');
#print NFAM Dumper(\@_);
logaddressup($ipadd);
# report each additional ip address (NB $vifs is a reference)
foreach my $ipaddss (@{$vifs}){
logaddressup($ipaddss);
}
#close NFAM;

}
# return a true value, otherwise wackamole doesn't start
1;




--
Ian Eiloart
IT Services, University of Sussex

_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users
Re: Perl scripts [ In reply to ]
On Jun 26, 2006, at 5:34 PM, Ian Eiloart wrote:

> OK, so here's a slightly useful example script, which logs
> interfaces as they come up. It also shows how to extract the IP
> addresses that just came up. For example, in future I'll use that
> data to bring up an Exim smtp server listening on that IP address.
>
> NB: The brick wall I was banging my head against today was the use
> of null terminated strings in the hash keys!

Ouch... that can only be considered a bug. Is that broken in CVS?

> My wackamole.conf file holds this segment:
> ------------------------------------------
>
> # Named socket for online control
> Control = /var/run/wack.it
> PerlUseLib /opt/local/etc/
> PerlUse wackamole
> RunDynamic wackamole::onup on up
>
> And, here's the content of wackamole.pm:
> ----------------------------------------
>
> package wackamole;
>
> use strict;
> use Sys::Syslog;
> use Data::Dumper;
>
> sub logaddressup {
> sleep 2;
> my ($ipadd) = @_;
> # let's also open a syslog facility
> openlog('wackamole.pm', 'ndelay pid', 'daemon');
>
> # this is how we address an element of the hash
> # keys we could use are (all null terminated!):
> # "ifname\0" eg: en0
> # "broadcast\0" eg: "192.168.0.1"
> # "netmask\0" eg: 255.255.255.255
> # "ip\0" eg "192.168.0.1"
> my $address = $ipadd->{ "ip\0" };
> my $if = $ipadd->{"ifname\0"};
> my $string = 'IP address '.$address.' acquired on '.$if.' ';
>
> # make a syslog notice
> syslog('notice','%s',$string);
>
> closelog();
> }
>
> sub onup {
> # we're being passed:
> # 1. a hash reference describing what just came up
> # 2. an array of hash references - the rest of the VIF
> # 3. a hash reference with the real interface that was affected
> # we'll just put them all into separate variables
> my ($ipadd, $vifs, $extern) = @_;
> #open (NFAM, '> /opt/local/etc/klop');
> #print NFAM Dumper(\@_);
> logaddressup($ipadd);
> # report each additional ip address (NB $vifs is a reference)
> foreach my $ipaddss (@{$vifs}){
> logaddressup($ipaddss);
> }
> #close NFAM;
>
> }
> # return a true value, otherwise wackamole doesn't start
> 1;
>
>
>
>
> --
> Ian Eiloart
> IT Services, University of Sussex
>
> _______________________________________________
> wackamole-users mailing list
> wackamole-users@lists.backhand.org
> http://lists.backhand.org/mailman/listinfo/wackamole-users

// Theo Schlossnagle
// CTO -- http://www.omniti.com/~jesus/
// OmniTI Computer Consulting, Inc. -- http://www.omniti.com/
// Ecelerity: Run with it.



_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users
Re: Perl scripts [ In reply to ]
--On 26 June 2006 18:58:33 +0100 Theo Schlossnagle <jesus@omniti.com> wrote:

> On Jun 26, 2006, at 5:34 PM, Ian Eiloart wrote:
>
>> OK, so here's a slightly useful example script, which logs
>> interfaces as they come up. It also shows how to extract the IP
>> addresses that just came up. For example, in future I'll use that
>> data to bring up an Exim smtp server listening on that IP address.
>>
>> NB: The brick wall I was banging my head against today was the use
>> of null terminated strings in the hash keys!
>
> Ouch... that can only be considered a bug. Is that broken in CVS?

I don't know. I just downloaded the latest version. Is development still
active, I'd kind of assumed it wasn't.

| Version 2.1.1

| Released 2004-Aug-31


--
Ian Eiloart
IT Services, University of Sussex

_______________________________________________
wackamole-users mailing list
wackamole-users@lists.backhand.org
http://lists.backhand.org/mailman/listinfo/wackamole-users