MikroTik Telegram Integration

Kustomisasi dinamis dan salin script monitoring PPPoE & Netwatch RouterOS untuk notifikasi Telegram.

Terakhir Diperbarui: 05 July 2026 RouterOS v6 & v7 Approved
☀️ 🌙

Form Kustomisasi

Masukkan credentials Bot Telegram Anda untuk memperbarui parameter script secara real-time.

Cara Mendapatkan Kredensial

  1. 1
    Hubungi @BotFather di Telegram. Kirim pesan /newbot dan ikuti petunjuknya hingga Anda memperoleh Bot Token.
  2. 2
    Untuk mendapatkan Chat ID pribadi Anda, kirim pesan apa saja ke @userinfobot.
  3. 3
    Untuk mengirim pesan ke Grup, undang bot buatan Anda ke grup tersebut. Dapatkan Chat ID grup menggunakan bot pengidentifikasi ID (biasanya berawalan -100).
Setting Icon

Variabel Icon Default

Script menggunakan UTF-8 hex escape bytes untuk menampilkan emoji di Telegram secara native. Anda dapat menyalin baris variabel berikut jika ingin mengubah kustomisasi emoji:

Variabel Icon
:local iconLogin "\F0\9F\9F\A2"
:local iconLogout "\F0\9F\94\B4"
:local iconDown "\E2\9D\8C"
:local iconUp "\E2\9C\85"
:local iconInfo "\E2\84\B9"
:local iconWarn "\E2\9A\A0"
Script Login

Fitur A - Notifikasi Login PPPoE (on-up)

💡
Cocok untuk notifikasi login pelanggan. Anti-spam aktif jika persentase user online terlalu rendah dibanding total secret untuk mencegah spam saat recovery massal.
RouterOS Script
:local nama "$user"
:local botToken "{{BOT_TOKEN}}"
:local chatId "{{CHAT_ID}}"
:local iconLogin "\F0\9F\9F\A2"
:local iconWarn "\E2\9A\A0"
:local antiSpamThreshold 30
:local antiSpamPercent 35

:local active [:len [/ppp active find]]
:local secret [:len [/ppp secret find where disabled=no]]
:local off ($secret - $active)

:if ($off < 0) do={ :set off 0 }

:if (($secret >= $antiSpamThreshold) and (($active * 100) <= ($secret * $antiSpamPercent))) do={
    :log warning ($iconWarn . " skip notif login " . $nama . " karena terdeteksi recovery massal: active=" . $active . " secret=" . $secret . " off=" . $off)
    :return
}

:local ipaddress $"remote-address"
:local lastcall $"caller-id"

:local secretId [/ppp secret find where name=$nama]
:local profile "-"
:local lastdic "-"
:if ([:len $secretId] > 0) do={
    :set secretId [:pick $secretId 0]
    :set profile [/ppp secret get $secretId profile]
    :set lastdic [/ppp secret get $secretId last-disconnect-reason]
}

:local text ($iconLogin . " LOGIN" . "\nUser : " . $nama . "\nIP Address : " . $ipaddress . "\nProfile : " . $profile . "\nLast Caller ID : " . $lastcall . "\nLast Disconnect Reason : " . $lastdic)
{{STATUS_BLOCK}}
:local payload ("{\"chat_id\":\"" . $chatId . "\",\"text\":\"" . $text . "\"}")

:do {
    /tool fetch mode=https check-certificate=no http-method=post http-header-field="Content-Type: application/json" http-data=$payload url=("https://api.telegram.org/bot" . $botToken . "/sendMessage") keep-result=no
} on-error={
    :log warning "gagal kirim notifikasi login"
}
🤖
🟢 LOGIN User : budi_pppoe IP Address : 10.10.10.25 Profile : 5Mbps Last Caller ID : 00:11:22:33:44:55 Last Disconnect Reason : user request
18:12
Script Logout

Fitur B - Notifikasi Logout PPPoE (on-down)

💡
Format sama dengan login agar notifikasi tetap konsisten saat dibaca di Telegram.
RouterOS Script
:local nama "$user"
:local botToken "{{BOT_TOKEN}}"
:local chatId "{{CHAT_ID}}"
:local iconLogout "\F0\9F\94\B4"
:local iconWarn "\E2\9A\A0"
:local antiSpamThreshold 30
:local antiSpamPercent 35

:local active [:len [/ppp active find]]
:local secret [:len [/ppp secret find where disabled=no]]
:local off ($secret - $active)

:if ($off < 0) do={ :set off 0 }

:if (($secret >= $antiSpamThreshold) and (($active * 100) <= ($secret * $antiSpamPercent))) do={
    :log warning ($iconWarn . " skip notif logout " . $nama . " karena terdeteksi gangguan massal: active=" . $active . " secret=" . $secret . " off=" . $off)
    :return
}

:local profile "-"
:local lastcall "-"
:local lastdic "-"

:local secretId [/ppp secret find where name=$nama]
:if ([:len $secretId] > 0) do={
    :set secretId [:pick $secretId 0]
    :set profile [/ppp secret get $secretId profile]
    :set lastdic [/ppp secret get $secretId last-disconnect-reason]
    :set lastcall [/ppp secret get $secretId last-caller-id]
}

:local text ($iconLogout . " LOGOUT" . "\nUser : " . $nama . "\nProfile : " . $profile . "\nLast Caller ID : " . $lastcall . "\nLast Disconnect Reason : " . $lastdic)
{{STATUS_BLOCK}}
:local payload ("{\"chat_id\":\"" . $chatId . "\",\"text\":\"" . $text . "\"}")

:do {
    /tool fetch mode=https check-certificate=no http-method=post http-header-field="Content-Type: application/json" http-data=$payload url=("https://api.telegram.org/bot" . $botToken . "/sendMessage") keep-result=no
} on-error={
    :log warning "gagal kirim notifikasi logout"
}
🤖
🔴 LOGOUT User : budi_pppoe Profile : 5Mbps Last Caller ID : 00:11:22:33:44:55 Last Disconnect Reason : user request
18:12
Script Cek PPPoE Offline

Fitur C - Daftar PPPoE Offline

💡
Lebih aman dipakai sebagai laporan berkala jika jumlah pelanggan banyak.
RouterOS Script
:local botToken "{{BOT_TOKEN}}"
:local chatId "{{CHAT_ID}}"
:local iconOffline "\F0\9F\94\B4"
:local active [:len [/ppp active find]]
:local secret [:len [/ppp secret find]]
:local off ($secret - $active)

:if ($off < 0) do={ :set off 0 }

:local laporan ""
:local scount 0

:foreach sid in=[/ppp secret find where profile~"^mgr"] do={
    :local pppname [/ppp secret get $sid name]
    :local lastd "-"
    :if ([:len [/ppp secret get $sid last-logged-out]] > 0) do={
        :set lastd [/ppp secret get $sid last-logged-out]
    }

    :local amjam "-"
    :if ([:len $lastd] >= 16) do={
        :set amjam [:pick $lastd 11 16]
    }

    :local aid [/ppp active find where name=$pppname]
    :if ([:len $aid] = 0) do={
        :set scount ($scount + 1)
        :set laporan ($laporan . $scount . ". " . $pppname . " | Last logout: " . $amjam . "\n")
    }
}

:if ($scount > 0) do={
    :local text ($iconOffline . " PPPoE OFFLINE" . "\nActive  : " . $active . "\nSecret  : " . $secret . "\nOffline : " . $off . "\n\n" . $laporan)
    :local payload ("{\"chat_id\":\"" . $chatId . "\",\"text\":\"" . $text . "\"}")

:do {
    /tool fetch mode=https check-certificate=no http-method=post http-header-field="Content-Type: application/json" http-data=$payload url=("https://api.telegram.org/bot" . $botToken . "/sendMessage") keep-result=no
} on-error={
    :log warning "gagal kirim daftar pppoe offline"
}
} else={
    :log info "semua pppoe manager online"
}
🤖
🔴 PPPoE OFFLINE Active : 141 Secret : 150 Offline : 9 1. budi_pppoe | Last logout: 18:12 2. ani_pppoe | Last logout: 17:05 3. joko_pppoe | Last logout: 14:30
18:12
Script Alarm Massal

Fitur H - Alarm Gangguan Massal PPPoE

💡
Tempel sebagai System Script lalu jalankan via Scheduler 1-5 menit sekali.
RouterOS Script
:global pppMassState
:global pppMassLastText
:if ([:len $pppMassState] = 0) do={ :set pppMassState "normal" }

:local botToken "{{BOT_TOKEN}}"
:local chatId "{{CHAT_ID}}"
:local iconWarn "\E2\9A\A0"
:local iconUp "\E2\9C\85"
:local minSecret 30
:local alarmPercent 35
:local recoveryPercent 70

:local active [:len [/ppp active find where service=pppoe]]
:local secret [:len [/ppp secret find where service=pppoe disabled=no]]
:local off ($secret - $active)

:if ($off < 0) do={ :set off 0 }

:if ($secret < $minSecret) do={
    :set pppMassState "normal"
    :set pppMassLastText "secret di bawah batas monitoring"
    :log info "alarm massal dilewati karena secret masih sedikit"
    :return
}

:local activePercent 0
:if ($secret > 0) do={
    :set activePercent (($active * 100) / $secret)
}
:local nowDate [/system clock get date]
:local nowTime [/system clock get time]
:local stamp ($nowDate . " " . $nowTime)

:if ($activePercent <= $alarmPercent) do={
    :if ($pppMassState != "alarm") do={
        :local text ($iconWarn . " ALARM GANGGUAN MASSAL PPPoE" . "\nWaktu    : " . $stamp . "\nActive   : " . $active . "\nSecret   : " . $secret . "\nOffline  : " . $off . "\nActive % : " . $activePercent . "%")
        :local payload ("{\"chat_id\":\"" . $chatId . "\",\"text\":\"" . $text . "\"}")

:do {
    /tool fetch mode=https check-certificate=no http-method=post http-header-field="Content-Type: application/json" http-data=$payload url=("https://api.telegram.org/bot" . $botToken . "/sendMessage") keep-result=no
} on-error={
    :log warning "gagal kirim alarm gangguan massal"
}
        :set pppMassState "alarm"
        :set pppMassLastText $text
    }
    :return
}

:if (($pppMassState = "alarm") and ($activePercent >= $recoveryPercent)) do={
    :local text ($iconUp . " RECOVERY PPPoE" . "\nWaktu    : " . $stamp . "\nActive   : " . $active . "\nSecret   : " . $secret . "\nOffline  : " . $off . "\nActive % : " . $activePercent . "%")
    :local payload ("{\"chat_id\":\"" . $chatId . "\",\"text\":\"" . $text . "\"}")

:do {
    /tool fetch mode=https check-certificate=no http-method=post http-header-field="Content-Type: application/json" http-data=$payload url=("https://api.telegram.org/bot" . $botToken . "/sendMessage") keep-result=no
} on-error={
    :log warning "gagal kirim pesan recovery pppoe"
}
    :set pppMassState "normal"
    :set pppMassLastText $text
    :return
}
🤖
⚠️ ALARM GANGGUAN MASSAL PPPoE Waktu : may/20/2026 18:12:00 Active : 5 Secret : 150 Offline : 145 Active % : 3%
18:12

Troubleshooting & Verifikasi Cepat

1. Pastikan Kredensial Valid

Bot Token dan Chat ID wajib diisi dengan benar. Untuk grup Telegram, pastikan ID berawalan tanda minus (misalnya: -1001234567890).

2. Masukkan Bot ke dalam Grup

Bot Telegram tidak akan bisa mengirim pesan ke grup target sebelum Anda mengundang bot tersebut sebagai salah satu anggota grup.

3. Sinkronisasi Waktu (Clock) & DNS

Jika pengiriman pesan gagal dengan logs peringatan SSL pada RouterOS versi lama, pastikan waktu sistem router sinkron via NTP dan DNS terkonfigurasi dengan benar.

4. Uji Menggunakan Fitur G

Gunakan script up/down pada Netwatch (Fitur G) terlebih dahulu untuk memverifikasi koneksi. Script ini memiliki beban terkecil dan paling mudah diuji.