VYOS: monitor nexthop static route table

 bikin file /config/scripts/monitor-next-hop.sh


#!/bin/vbash

source /opt/vyatta/etc/functions/script-template


NEXT_HOP="10.10.10.2"    # IP Next-Hop yang dipantau

ROUTE_TABLE="100"         # Nomor tabel

CHECK_COUNT=3             # Jumlah ping untuk menentukan status

PING_INTERVAL=1           # Waktu antar ping dalam detik


# Fungsi untuk menambahkan static route

add_route() {

    configure

    echo "Adding static route to next-hop $NEXT_HOP in table $ROUTE_TABLE"

    set protocols static table $ROUTE_TABLE route 0.0.0.0/0 next-hop $NEXT_HOP

    commit

    exit

}


# Fungsi untuk menghapus static route

remove_route() {

    configure

    echo "Removing static route to next-hop $NEXT_HOP from table $ROUTE_TABLE"

    delete protocols static table $ROUTE_TABLE route 0.0.0.0/0

    commit

    exit

}


# Cek apakah next-hop dapat dijangkau

if ping -c $CHECK_COUNT -i $PING_INTERVAL $NEXT_HOP > /dev/null 2>&1; then

    echo "Next-hop $NEXT_HOP is reachable"

    # Jika rute belum ada, tambahkan

    if ! run show ip route table $ROUTE_TABLE | grep -q $NEXT_HOP; then

        add_route

    fi

else

    echo "Next-hop $NEXT_HOP is unreachable"

    # Jika rute ada, hapus

    if run show ip route table $ROUTE_TABLE | grep -q $NEXT_HOP; then

        remove_route

    fi

fi


set system task-scheduler task monitor-next-hop executable path "/config/scripts/monitor-next-hop.sh"

set system task-scheduler task monitor-next-hop interval 1


pengecekan 1 menit