MartijnBraam / python-isc-dhcp-leases

Small python module for reading /var/lib/dhcp/dhcpd.leases from isc-dhcp-server
MIT License
123 stars 47 forks source link

Extract leases - Binding state backup #20

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello,

My problem is the following: I can't extract from the leases.get (), the leases whose binding state is backup and of which there is no end.

I can :

lease **** {
  starts 4 2017/10/05 15:22:29;
  ends 1 2017/10/16 08:09:23;
  tstp 1 2017/10/16 15:22:29;
  tsfp 1 2017/10/16 15:22:29;
  atsfp 1 2017/10/16 15:22:29;
  cltt 4 2017/10/05 15:22:29;
  binding state backup;
  hardware ethernet *****;
  uid *****;

I can"t :

lease ******* {
  starts 2 2017/10/10 12:05:14;
  tstp 2 2017/10/10 12:05:14;
  tsfp 2 2017/10/10 12:05:14;
  atsfp 2 2017/10/10 12:05:14;
  binding state backup;

Is there a solution ?

Regards,

MartijnBraam commented 7 years ago

Well it should ignore incomplete leases since those aren't valid. I'll check why your backup lease won't work.

ghost commented 7 years ago

So in fact, this lease does not appear in the list of leases.get() because it lacks the "ends" ?

MartijnBraam commented 7 years ago

Oh I thought you meant end as in "missing the }". Leases without end should work.

MartijnBraam commented 7 years ago

I've added testcases for both your leases and it seems to work fine. You can see my lease file here: https://github.com/MartijnBraam/python-isc-dhcp-leases/pull/21/files

Maybe you have something different in your lease file that makes it stop working?

ghost commented 7 years ago

In fact, as the lease is backup it has never been used, there is not the line "hardware ethernet ***" and I think the problem is there

ghost commented 7 years ago

It would be necessary that the code accepts that the lease does not have ends and harware

MartijnBraam commented 7 years ago

The current version does support leases without ends but skips leases without hardware. In #21 I've added a option to the get() method to allow you to get hardware-less leases.

Can you try if that version works if you specify get(include_backups=True)?

ghost commented 7 years ago

Thank you ! It works very well in case there is no hardware but I still have the following error if I do not have any ends

line 209, in __init__
    if properties['ends'] == 'never':
KeyError: 'ends'
MartijnBraam commented 7 years ago

Hmm that line doesn't exist in the current codebase. Are you using an older version?

ghost commented 7 years ago

This corresponded to line 213 in the most recent version. I missed get('ends', 'never'), it's works now !

MartijnBraam commented 7 years ago

I've just released 0.9.0 on pypi with the fixes for this included.