Community discussions

MikroTik App
 
RIskbreaker
just joined
Topic Author
Posts: 1
Joined: Sun Mar 14, 2021 3:49 am

DHCP script not sending message to telegram

Sat May 01, 2021 1:12 am

Greettings, I have a few scripts for warning me when certain situations are present and one of them is failing. I need to send an alert over telegram when a new dynamic IP address has been assigned to an unknown host because all my devices have static IP. I also have a similar script in the same window for sending over email the same alert and it works. I'm running lastest stable release 6.48.2.
/ip dhcp-server lease
:if ($leaseBound = 1 && [ get [ find where mac-address=$leaseActMAC ] dynamic ] = true) do={
	:do {
		:tool fetch url="https://api.telegram.org/bot1688353301:AAHL3EGpj7DbbI98JhAvJUTClI8vN0MHdQQ/sendmessage?chat_id=-XXXXXXXXX&text=La dirección MAC [$leaseActMAC] recibió la IP dinámica [$leaseActIP] del servidor DHCP" 
		:log info "Sent alert for MAC $leaseActMAC to telegram"
	} on-error={:log error "Failed to send telegram alert"}
}

:local recipient "mikrotik@gmail.com"
/ip dhcp-server lease
:if (($leaseBound=1) && ([/ip dhcp-server lease find where dynamic mac-address=$leaseActMAC]!="")) do {
	:do {
		:tool e-mail send to=$recipient subject="DHCP Alert [MAC: $leaseActMAC]" body="La dirección MAC [$leaseActMAC] recibió la IP dinámica [$leaseActIP] del servidor DHCP"
#		:log info "Sent DHCP alert for MAC $leaseActMAC"
	} on-error={:log error "Failed to send email to $recipient"}
}


I have a netwatch set to send a message over telegram too and this one works very well so my telegram bot is fine and if I do :tool fetch url= in CLI it sends the message but when the script runs on event it goes to on-error. I'm trying to isolate the cause as to why is only the telegram part of my alert for new DHCP lease failing as it used to work before but one day it just didn't.

Who is online

Users browsing this forum: No registered users and 28 guests