Skip to content

Instantly share code, notes, and snippets.

@cristianmenghi
Created March 11, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristianmenghi/9f3dcbc6f281646b0ef947e4046fbd4e to your computer and use it in GitHub Desktop.
Save cristianmenghi/9f3dcbc6f281646b0ef947e4046fbd4e to your computer and use it in GitHub Desktop.

Mikrotik>Telegram

Pequeño script para mandar mensajes al bot Telegram, así podemos detectar o monitorear cambios de los cuales queremos enterarnos.

Este ejemplo notifica del cambio de estado de un puerto.

El TELEBOTID es el ID de bot cuando lo crearmos con el @botFather El TELECHATID lo obtenes con el @getmyid_bot

Lo importanet son las 2 primeras lineas y la ultima, en el medio se puede poner cualquier info o el resultado de cualquier operacion de Mikrotik y guardan el mensaje en "enviar"

:local TELEBOTID 999999999:AAAAAAAAAAAAAAAAAAAAA-xxXX
:local TELECHATID 1111111111111
:local MENSAJE " CAMBIO ESTADO PUERTO"
:local VOLT  [/system health get voltage]
:local DATE [/system clock get date]
:local CLOCK [/system clock get time]
:local STATION [/system identity get name]
:local INTER "ether1"
:local SHOULD "1Gbps"
:local INTERVALUE [/interface ethernet get $INTER value-name=speed]
:if ($INTERVALUE!=$OLMALI) do={ 
:local enviar "$ STATION $ MENSAJE En interfaz $INTER$ pero $INTERVALUE $DATE $HOUR"
/tool fetch keep-result=no url="https://api.telegram.org/$TELEBOTID/sendMessage\?chat_id=$TELECHATID&text=$enviar"; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment