[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [OSSTEST PATCH 2/7] DhcpWatch: add dnsmasq support
dnsmasq use much simpler format - one lease by line with fields separated with spaces. Add separate function to parse this format and plug it info check_ip. Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx> --- Osstest/DhcpWatch/leases.pm | 40 +++++++++++++++++++++++++++++++++++--- README | 2 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Osstest/DhcpWatch/leases.pm b/Osstest/DhcpWatch/leases.pm index 5ec305f..0c379e9 100644 --- a/Osstest/DhcpWatch/leases.pm +++ b/Osstest/DhcpWatch/leases.pm @@ -40,8 +40,8 @@ BEGIN { sub new { my ($class, $ho, $meth, $format, $source) = @_; - die "'$format' is missing dhcp3 in it! (args: @_) ?" - unless $format eq 'dhcp3'; + die "'$format' is missing dhcp3/dnsmasq in it! (args: @_) ?" + unless $format eq 'dhcp3' or $format eq 'dnsmasq'; return bless { Format => $format, Source => $source, @@ -118,6 +118,36 @@ sub parse_dhcp_dhcp3($$$$) { return $best; } +sub parse_dhcp_dnsmasq($$$$) { + my ($gho, $leases, $copy, $leasesfn) = @_; + + my $props; + my $best; + + while (<$leases>) { + print $copy $_ or die $!; + + chomp; s/^\s+//; s/\s+$//; + next if m/^\#/; next unless m/\S/; + + my ($ends, $ether, $ip, $hostname, $client_id) = split / /; + $ends = strftime "%Y/%m/%d %T", localtime($ends); + $props = { + ' addr' => $ip, + ' ends' => $ends, + 'hardware ethernet' => $ether + }; + # ignore leases for other hosts + next unless lc $props->{'hardware ethernet'} eq lc $gho->{Ether}; + + next if $best && + $best->{' ends'} gt $props->{' ends'}; + $best= $props; + } + + return $best; +} + sub check_ip ($$) { my ($mo, $gho) = @_; @@ -169,7 +199,11 @@ sub check_ip ($$) { return $m; }; - eval { $best = parse_dhcp_dhcp3($gho, $leases, $copy, $leasesfn) }; + if ($mo->{Format} eq 'dnsmasq') { + eval { $best = parse_dhcp_dnsmasq($gho, $leases, $copy, $leasesfn) }; + } elsif ($mo->{Format} eq 'dhcp3') { + eval { $best = parse_dhcp_dhcp3($gho, $leases, $copy, $leasesfn) }; + } if ($@) { return $badleases->($@); } diff --git a/README b/README index bb9dc18..4e4066a 100644 --- a/README +++ b/README @@ -508,7 +508,7 @@ HostFlags_<host> flag,^flag,^flag,flag... HostProp_DhcpWatchMethod leases <format> <source> - where <format> is dhcp3 + where <format> is dhcp3 or dnsmasq <source> is filename (with slash) or <host>:<port> AuthorizedKeysFiles -- git-series 0.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |