Community discussions

MikroTik App
 
loic69
just joined
Topic Author
Posts: 8
Joined: Mon Dec 28, 2015 3:34 pm

SNMP Number of DHCP lease used in pool

Mon Dec 28, 2015 3:55 pm

Hi all
I'm using routerboard for big wifi hotspot.
I'm using too a supervision system wich is nagios based with trafic, CPU and a lot of information.

I'd like to monitor the number of DHCP lease in the pool of one or several subnet.
Just one for the moment will be very good.

I don't find the good OID and don't find any script on the web.

I try near OIB 9999 with
snmpwalk -v 2c -c XXX HHHH .1.3.6.1.2.1.9999
but I obtained just the list of IP address I think...

I dont' nead to have lease list but just the number of uses lease.
Bonus is to have number of pool remaining (so the total number of pool)

Thanks for your help

For example :
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.2.66.62 = INTEGER: 2
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.2.66.71 = INTEGER: 2
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.2.66.74 = INTEGER: 2
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.2.66.92 = INTEGER: 2
....
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.5.10.2.67.198 = Gauge32: 1498
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.5.10.2.67.199 = Gauge32: 1626
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.5.10.2.67.202 = Gauge32: 1734
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.5.10.2.67.208 = Gauge32: 1163
.....
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.7.10.2.66.62 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.7.10.2.66.71 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.7.10.2.66.74 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.7.10.2.66.92 = INTEGER: 3
.....
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.8.10.2.66.62 = Hex-STRING: BC 4C C4 88 B3 ED
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.8.10.2.66.71 = Hex-STRING: FC FC 48 41 0C D7
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.8.10.2.66.74 = Hex-STRING: CC AF 78 6C C3 8A
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.8.10.2.66.92 = Hex-STRING: F0 4F 7C 04 34 03
 
Feklar
Forum Guru
Forum Guru
Posts: 1724
Joined: Tue Dec 01, 2009 11:46 pm

Re: SNMP Number of DHCP lease used in pool

Wed Dec 30, 2015 9:35 pm

You can do an OID count, that's how I monitor the number of connected devices to the wireless interface of a MikroTik:

/usr/bin/snmpwalk <ip>:<port> -v 1 -c <comm> <oid> | /usr/bin/wc -l

I'm not familiar with Nagios specifically, but that's the script I have in place for my Cacti server for couting the OIDs.
 
merrywt
just joined
Posts: 17
Joined: Mon Dec 05, 2011 7:53 pm
Location: Hertfordshire, UK

Re: SNMP Number of DHCP lease used in pool

Tue Jun 09, 2020 8:32 pm

Do a MIB Walk and save the output to a file.

Open the file in something like Notepad++ and search for DHCP. It should be arround .1.3.6.1.2.1.9999.1.1.1.1.0.

The next OID will tell you where to look in the walk to find the DHCP server information. Mine returned 1.3.6.1.4.1.14988.1

Looking under there the number of active leases for my single scope was in .1.3.6.1.4.1.14988.1.1.6.1.0 There should be a Gauge32 value for each scope.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3334
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: SNMP Number of DHCP lease used in pool

Tue Jun 09, 2020 10:43 pm

I have skipped use SNMP, since I need to set up SNMP for each new router. Instead I make the router send me the data using Syslog, including DHCP pool information.

See how to use Splunk with MikrotTik using link in my signature. Or click here to just show the DHCP example. viewtopic.php?p=676543#p676543
 
pe1chl
Forum Guru
Forum Guru
Posts: 10513
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP Number of DHCP lease used in pool

Tue Jun 09, 2020 11:30 pm

Looking under there the number of active leases for my single scope was in .1.3.6.1.4.1.14988.1.1.6.1.0 There should be a Gauge32 value for each scope.
This is not correct, there always is only a single number (the total number of entries) there even when you have more than one DHCP scope!
To find the number of leases per scope you need to walk the .1.3.6.1.2.1.9999.1.1.6.4.1.4 OID and group/count the entries (the address is part of the OID, the value of each entry is the type static/dynamic/waiting).
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3334
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: SNMP Number of DHCP lease used in pool

Wed Jun 10, 2020 11:01 am


To find the number of leases per scope you need to walk the .1.3.6.1.2.1.9999.1.1.6.4.1.4 OID and group/count the entries (the address is part of the OID, the value of each entry is the type static/dynamic/waiting).
Seems to be a bug in RouterOS when getting DHCP information. I have around 200 addresses in my DHCP scopes. This show the bottom part of the log, and you see snmpwalk from linux fails not getting all leases.
...
...
...
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.170 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.171 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.172 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.173 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.174 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.20.174 = INTEGER: 3
SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.175 = INTEGER: 3
Error: OID not increasing: SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.20.174
 >= SNMPv2-SMI::mib-2.9999.1.1.6.4.1.4.10.10.10.175
 
pe1chl
Forum Guru
Forum Guru
Posts: 10513
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP Number of DHCP lease used in pool

Wed Jun 10, 2020 11:52 am

That is true, it is a bug in RouterOS but you can work around it by passing the "-Cc" flag to snmpwalk.
(I would recommend using snmpbulkwalk -v2c for such long lists, but it requires the same flag to work around this bug)

snmpbulkwalk -Cc -v2c -c public router .1.3.6.1.2.1.9999.1.1.6.4.1.4

works fine here.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3334
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: SNMP Number of DHCP lease used in pool

Wed Jun 10, 2020 12:07 pm

"-Cc" flag to snmpwalk.
That did the trick. Thanks.
 
User avatar
DavidCN
just joined
Posts: 12
Joined: Wed Feb 27, 2019 1:37 am
Location: Spain
Contact:

Re: SNMP Number of DHCP lease used in pool

Thu Aug 26, 2021 2:37 pm

Hi,

One year later but.. there are an OID to get this value -> MIKROTIK-MIB::mtxrDHCPLeaseCount.0

Regards ;-)
 
pe1chl
Forum Guru
Forum Guru
Posts: 10513
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP Number of DHCP lease used in pool

Thu Aug 26, 2021 4:10 pm

This was already mentioned in reply #3, the OID .1.3.6.1.4.1.14988.1.1.6.1.0 is the numeric value of MIKROTIK-MIB::mtxrDHCPLeaseCount.0
However, there is always only a .0 and there is no separate DHCPLeaseCount per pool or per DHCP scope.
That is why the solution is to walk the list of DHCP leases and group them by address in some external script.
 
LaZyLion
newbie
Posts: 32
Joined: Fri May 09, 2014 10:27 am

Re: SNMP Number of DHCP lease used in pool

Thu Dec 21, 2023 8:38 pm

This is great. Thank you all.

Total number of leases is sufficient for my purposes, though I can certainly see a use case for getting the totals of each pool (and count of pools) if the RouterOS devs are ever bored (unlikely).

Next question: Is there a way to get a count of "available" dhcp leases or a count of "remaining" dhcp leases?
I'd like to set up a Zabbix trigger to tell me if the pool is nearing exhaustion. ie: % of remaining available leases is less than 20.

Thanks again.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10513
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP Number of DHCP lease used in pool

Thu Dec 21, 2023 9:58 pm

No, it is not available. You will have to write your own script to count the number of leases and calculate the percentage based on the size of your pools.
You can do this on the system running Zabbix or (in theory) also on the router itself, because you can write RouterOS scripts that are invoked when you read a user-defined OID.
But I am not going to help you with that! Writing and debugging RouterOS scripts is a frustrating affair.

Who is online

Users browsing this forum: anav, GoogleOther [Bot], kurei3nei and 28 guests