If "mac1" then "text1" type array.
Posted: Tue Jun 21, 2022 11:56 am
Noob question... I have a working DHCP script which sends a pushbullet notification when certain known devices join the network:
I would like to optimize the above code so that instead of repeating if's/variables/static text once per device, I would like to have a single array like "mac1, name1, mac2, name2..." etc so that I can easily add a longer list of devices, and notify with a single code block, but I have struggled to find an example of how to do this. i.e. the principle
if ([$leaseActMAC] = {any mac[n] from array})
body={corresponding name[n] from array} Arrived Home"
Can anyone point at an example I can work from?
Thanks!
Code: Select all
# Variables
:global Person1 "00:00:00:00:00:00";
:global Person2 "11:11:11:11:11:11";
:global apikey "s78e4thyfakekeyf89se47gh56ts87hft87"
:global leaseBound
:global leaseActMAC
# DHCP Bound
:if ($leaseBound =1) do={
:if ([$leaseActMAC] = $Person1) do={
:tool fetch mode=https url="https://api.pushbullet.com/v2/pushes" http-method=post http-data="type=note&body=Person1 Arrived Home" user="$apikey"
}
:if ([$leaseActMAC] = $Person2) do={
:tool fetch mode=https url="https://api.pushbullet.com/v2/pushes" http-method=post http-data="type=note&body=Person2 Arrived Home" user="$apikey"
}
}
if ([$leaseActMAC] = {any mac[n] from array})
body={corresponding name[n] from array} Arrived Home"
Can anyone point at an example I can work from?
Thanks!