Jump to content

Port forward automation using Event Juggler: Difference between revisions

From Teltonika Networks Wiki
No edit summary
No edit summary
Line 89: Line 89:
This allows you to narrow down broad triggers (like any change on a port) to more specific ones — for example, only reacting when the port goes UP or DOWN.
This allows you to narrow down broad triggers (like any change on a port) to more specific ones — for example, only reacting when the port goes UP or DOWN.


In this example, we’ll use two filter conditions to monitor the LAN1 port. One condition will detect when the port goes UP and trigger the first action. The other will detect when the port goes DOWN and trigger the second action.
In this example, we will use two filter conditions to monitor the LAN1 port. One condition will detect when the port goes UP and trigger the first action. The other will detect when the port goes DOWN and trigger the second action.


[[File:Event juggler condition1.png|border|class=tlt-border]]
[[File:Event juggler condition1.png|border|class=tlt-border]]
Line 120: Line 120:


==== Assigning the conditions ====
==== Assigning the conditions ====
 
----
Once the conditions are created, they can assigned by editing the created action:
Once the conditions are created, they can assigned by editing the created action:


Line 128: Line 128:


[[File:Assign action.png|border|class=tlt-border]]
[[File:Assign action.png|border|class=tlt-border]]
== See also ==
#[[UCI command usage]]
#[[User Scripts examples]]

Revision as of 07:07, 24 April 2025

Introdutcion

This configuration example demonstrates how to automate port forwarding using the Event Juggler function on Teltonika devices. By leveraging this feature, users can automatically create a port forwarding rule for the most recent DHCP lease IP address. This is especially useful in dynamic network environments, as it eliminates the need for manual updates and significantly reduces setup time during on-site deployments.

Port_forward script

The script used in this setup utilizes UCI commands to create a new firewall port forwarding rule, which is applied to the most recent IP address lease from the router's DHCP server. For instructions on creating a runnable script file, refer to our configuration example article - User Scripts examples.


#!/bin/sh                                                               
                                               
LAN_INTERFACE="br-lan"  # Adjust if needed                               
FORWARD_PORT=8080       # External port to forward                       
DEST_PORT=443           # Internal port on the target device           
PROTO="tcp"             # Protocol (tcp, udp, both)

RULE_NAME="DHCP_Forward"

                    
LATEST_LEASE=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}')      
LEASE_IP=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}')                          
if [ -z "$LEASE_IP" ]; then
   echo "No DHCP leases found. Exiting."                                 
   exit 1
fi  

#Remove existing port forward rule if it exists                         
uci delete firewall.$RULE_NAME 2>/dev/null 
                                          
uci set firewall.$RULE_NAME="redirect"                                   
uci set firewall.$RULE_NAME.name="$RULE_NAME"                             
uci set firewall.$RULE_NAME.src="wan"                                     
uci set firewall.$RULE_NAME.src_dport="$FORWARD_PORT"                     
uci set firewall.$RULE_NAME.dest="lan"                                   
uci set firewall.$RULE_NAME.dest_ip="$LEASE_IP"                           
uci set firewall.$RULE_NAME.dest_port="$DEST_PORT"                       
uci set firewall.$RULE_NAME.proto="$PROTO"

uci commit firewall          
/etc/init.d/firewall restart 

Event juggler configuration

To begin with open router's WebUI, navigate to Services → Event juggler and creat a new instance by entering the name and clicking on "Add" button.

Event data configuration

After creating a new event juggler instance, you will be redirected to the event data configuration window. In this window select the following options:

  1. Enable - On
  2. Event type - Log
  3. Events logs type - Port state
  4. Events log subtype - LAN1 (depending on the specific port you want to monitor)
  5. Click on Save & Apply

Action data configuration


In this setup, we will use multiple actions triggered by changes in the LAN1 port status. The first action will run a script stored on the router, which creates a custom port forwarding rule for the latest IP lease. The second action will trigger when the LAN1 port goes DOWN, sending an SMS notification to a specific recipient to let them know the device has been disconnected or is no longer detected on the LAN1 port.

Script action

Make the following changes:

  1. Action name - Enter your preferred action name
  2. Delay - 5 (Sets a time for a delay in seconds when the action will be performed after the event is triggered.)
  3. Action tpye - Script
  4. Script file type - Path
  5. Script file path - Script file location
  6. Save & Apply

Send SMS action

Make the following changes:

  1. Action name - Enter your preferred action name
  2. Action type - Send SMS
  3. Text message - Enter your preferred text (In this configuration we will send routers name and the timestamp)
  4. Recipients - Single
  5. Phone number - Enter recipients phone number
  6. Save & Apply

Conditions


In the Event Juggler feature of the Teltonika devices, conditions are optional filters you can use to control when an action should happen.

When an event is triggered (for example, when the state of LAN1 changes), the router checks if any conditions are set. If the conditions are met, the action will be executed. If not, the action is skipped. This allows you to narrow down broad triggers (like any change on a port) to more specific ones — for example, only reacting when the port goes UP or DOWN.

In this example, we will use two filter conditions to monitor the LAN1 port. One condition will detect when the port goes UP and trigger the first action. The other will detect when the port goes DOWN and trigger the second action.

Condition UP


Make the following changes:

  1. Condition name - Enter your preferred name
  2. Condition type - Filter
  3. Field name - Event text
  4. Value - UP
  5. Operator - Equals
  6. Save & Apply

Condition DOWN


Make the following changes:

  1. Condition name - Enter your preferred name
  2. Condition type - Filter
  3. Field name - Event text
  4. Value - DOWN
  5. Operator - Equals
  6. Save & Apply

Assigning the conditions


Once the conditions are created, they can assigned by editing the created action:

  1. Condition compatibility - And
  2. Active conditions - Select created condition accordingly to the setup.
  3. Save & Apply

See also

  1. UCI command usage
  2. User Scripts examples