
jesus at omniti
Jun 26, 2006, 10:58 AM
Post #5 of 6
(2152 views)
Permalink
|
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[at]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[at]lists.backhand.org http://lists.backhand.org/mailman/listinfo/wackamole-users
|