Community discussions

MikroTik App
User avatar
just joined
Topic Author
Posts: 24
Joined: Tue Jul 11, 2017 10:12 pm
Location: Scotland

Variable Inconsistencies

Mon Sep 24, 2018 6:57 pm

Hi there. I'm trying to report on DHCP activity on one of our routers.

In order to do this I have created a simple script (dhcp-count) which is as follows:

:global monDHCPCounter;
:set monDHCPCounter ($monDHCPCounter + 1);

I have made this script the lease-script for the DHCP server placing its name in the relevant box on the DHCP server config. The console shows as follows:

name="site" interface=hotspot lease-time=4h address-pool=larger hotspot bootp-support=static authoritative=yes use-radius=no lease-script=dhcp-count

So far so good. However when I reboot the box and zero everything, I eventually see that the run-count of the script exceeds the value of the variable "monDHCPCounter"

This seems unexpected as Id expect them to follow each other in lock step. Can anybody explain how the script run count can contain run events where the variable was not incremented?
User avatar
just joined
Posts: 15
Joined: Mon Sep 17, 2018 11:07 am

Re: Variable Inconsistencies

Wed Sep 26, 2018 2:51 pm

perhaps a race condition?

Also, I believe dhcp-script will run on both activation of a lease and release.

I would add some logging to the script, then you can manually look at the logs to see DHCP being allocated the the log item in the script being called.
Home of the Badjr, the cloud-managed business network router built on Mikrotik
Forum Guru
Forum Guru
Posts: 7052
Joined: Mon Jun 08, 2015 12:09 pm

Re: Variable Inconsistencies

Wed Sep 26, 2018 2:56 pm

Maybe it is easier and better to enable logging to an external syslog server (that is a good idea anyway) and then analyze the logs using one of the many available tools or your own scripts (on the syslog server machine).
This syslog server can be as simple as a Raspberry Pi.
You can also make it poll some info using SNMP e.g. the number of active leases.

Who is online

Users browsing this forum: No registered users and 41 guests