Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Guys

I'm trying to retrieve the local state of the dhcp server using the above module.
however, I can't get it to work using he below code

#! /usr/bin/perl use Net::ISC::DHCPd::OMAPI; my $omapi = Net::ISC::DHCPd::OMAPI->new( key => 'omkey ' . 'xxxxxx +' ); $omapi->connect or die "Could not connect to server: ".$omapi->err +str."\n"; # as per cpan page # my $failover = $omapi->new_object("failover",(name => 'st1_dhcpb' +)); # omapi cpan page # my $failover = $omapi->new_object(failover=>(name => 'st1_dhcpb', +)); # as per POD # my %failover_hash = ( 'name' => 'st1_dhcpb'); # my $failover = $omapi->new_object("failover" => %failover_hash); # as per github example my $failover = $omapi->new_object('failover') or die "Could not create failover: ".$omapi->errstr." +\n"; $failover->name('st1_dhcpb'); # Try to get info (equiv to cli 'open' cmd) $failover->read or die "Could not read failover: ".$omapi->errstr +."\n";
As you can see, I've tried various methods.

Setting debug on (DHCP_OMAPI_DEBUG=1) at the shell level gives

$ port 7911 $ server 127.0.0.1 $ key omkey xxxxxx $ connect obj: <null> $ new failover obj: failover $ open can't open object: not found obj: failover $ close obj: <null> Could not read failover:
Using omshell interactively
omshell > server localhost > port 7911 > key omkey "xxxxxx" > connect obj: <null> > new failover-state obj: failover-state > set name = "st1_dhcpb" obj: failover-state name = "st1_dhcpb" > open obj: failover-state name = "st1_dhcpb" partner-address = 00:00:71:02:00:00:00:00 . . . partner-state = 00:00:00:02 local-state = 00:00:00:02 .
works fine as you can see.
Has anybody got this to work?

Cheers
Chris

Replies are listed 'Best First'.
Re: Howto use Net::ISC::DHCPd::OMAPI to get failover state
by kcott (Archbishop) on Nov 04, 2013 at 04:49 UTC

    G'day Chris,

    I don't use Net::ISC::DHCPd::OMAPI; however, here's a couple of suggestions.

    # as per cpan page # my $failover = $omapi->new_object("failover",(name => 'st1_dhcpb' +));

    As per the Net::ISC::DHCPd::OMAPI::Failover CPAN page:

    $failover = $omapi->new_object("failover", { $attr => $value });

    Note there's only two scalar arguments, the second being a hashref. ("failover",(name => 'st1_dhcpb')) will be interpreted as three arguments like this: ('failover', 'name', 'st1_dhcpb')

    Also, if you add a newline to your die message, you'll lose potentially useful information. See die for details.

    -- Ken