routeros-scripts/lease-script
Christian Hesse ceaa83b83e global-functions: merge $LogAnd{Error,Put} to $LogPrintExit ...
... and fix logging.

Logging with severity from variable (:log $severity ...) is not
possible, this is considered a syntax error. Also the 'workaround' with
parsing code failed with missing message in log.

The reliable code is a lot longer, so merge the two functions to save a
lot of duplicate code.
2020-02-26 14:19:54 +01:00

48 lines
1.2 KiB
Plaintext

#!rsc
# RouterOS script: lease-script
# Copyright (c) 2013-2020 Christian Hesse <mail@eworm.de>
#
# run scripts on DHCP lease
:global LogPrintExit;
:if ([ :typeof $leaseActIP ] = "nothing" || \
[ :typeof $leaseActMAC ] = "nothing" || \
[ :typeof $leaseServerName ] = "nothing" || \
[ :typeof $leaseBound ] = "nothing") do={
$LogPrintExit error "This script is supposed to run from ip dhcp-client." true;
}
:local Scripts;
:local ScriptsAssign {
"dhcp-to-dns";
"collect-wireless-mac.local";
"dhcp-lease-comment.local";
"collect-wireless-mac.capsman";
"dhcp-lease-comment.capsman"
}
:local ScriptsDeAssign {
"dhcp-to-dns"
}
:local State "";
:if ($leaseBound = 0) do={
:set State "de";
:set Scripts $ScriptsDeAssign;
} else={
:set Scripts $ScriptsAssign;
}
:log debug ("DHCP Server " . $leaseServerName . " " . \
$State . "assigned lease " . $leaseActIP . " to " . $leaseActMAC);
# delay a moment to update the lease table, do not run in parallel for de/assign
:delay ((1 + $leaseBound) . "s");
:foreach Script in=$Scripts do={
:if ([ / system script print count-only where name=$Script ] > 0) do={
:log debug ("Running script from lease-script: " . $Script);
/ system script run $Script;
}
}