Questo forum fa uso dei cookie
Questo forum utilizza i cookie per memorizzare i dettagli del tuo login o della tua ultima visita. I cookie sono piccoli files di testo salvati nel computer; i cookie da noi utilizzati sono relativi unicamente ai servizi da noi forniti direttamente o dai banner pubblicitari. I cookie su questo forum salvano inoltre i dettagli relativi alle discussioni lette e alle tue preferenze personali. Sei pregato di selezionare il tasto OKAY se sei consapevole della presenza di questi files e ci autorizzi ad utilizarli per le informazioni specificate.

Indipendentemente dalla tua scelta un cookie verrà salvato per memorizzare nel tuo pc la risposta a questo form. Puoi modificare le impostazioni relative ai cookie nelle preferenze del tuo browser.

  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5
[Mikrotik] Resilience/Monitoring- Monitoring Script

#1
Information 
Actually there are two scripts. The first one is the main script for monitoring arbitrary RouterOS parameters. It uses the second auxiliary script for logging.

Add both scripts to your RouterOS. Make sure they are named as "monitoring" and "log-up-down". Add the monitoring script to the system scheduler:

Codice:
/system scheduler add name=monitoring on-event=monitoring interval=5s \
   start-date=jan/01/1970 start-time=00:00:00
Check the log messages. You will see the following lines:
Codice:
Check the log messages. You will see the following lines:


Edit the monitoring script to adjust it for your own RouterOS configuration. By default the script monitors the state of three routes and makes log entries when the state is changed, assuming that a failover between two ISP connections is configured. But you can monitor arbitrary parameters and do other actions than just logging.

If you want to receive monitoring notifications by e-mail, just set up RouterOS system logging for that.

Codice:
############################################################################

Codice:
# Script name:   monitoring

Codice:
# Last changed:  25 Feb 2011

Codice:
# ROS version:   5.0rc10

Codice:
# Author:        Vadim Guchenko [yhw at relost dot net]

Codice:
#

Codice:
# Monitors one or more parameters of RouterOS and performs specified actions

Codice:
# when parameters change their values. A parameter is any expression of the

Codice:
# RouterOS scripting language that can return a value of any data type to

Codice:
# which the = operator can be applied. When the parameter value is changed,

Codice:
# the specified action is executed. An action is any statement of the

Codice:
# RouterOS scripting language that doesn't return a value (usually it's

Codice:
# invocation of another script). Before executing an action the following

Codice:
# global variables are set:

Codice:
#

Codice:
#   monParamName         The name of the parameter that has been changed.

Codice:
#                        Can be used to distinguish different parameters in

Codice:
#                        one action script.

Codice:
#   monParamOldValue     The old parameter value.

Codice:
#   monParamNewValue     The new parameter value.

Codice:
#   monParamOldValueAge  How long (seconds) the parameter had the old value.

Codice:
#                        Calculated without using the system clock.

Codice:
#

Codice:
# This script must be run from the scheduler at small intervals. If a # The names of the parameters. Every array element corresponds to an

Codice:
# individual parameter. Dimensions of the arrays "paramNames", "paramValues"

Codice:
# and "paramActions" must be the same.

Codice:
:local paramNames {

Codice:
       "ISP1"

Codice:
       "ISP2"

Codice:
       "Internet"

Codice:
}

Codice:
#

Codice:
# The expressions to compute parameter values. Note that the expressions

Codice:
# must NOT be enclosed in double quotes.

Codice:
:local paramValues {

Codice:
       ([/ip route find dst-address=127.127.127.1/32 active] != "")

Codice:
       ([/ip route find dst-address=127.127.127.2/32 active] != "")

Codice:
       ([/ip route find dst-address=0.0.0.0/0 active] != "")

Codice:
}

Codice:
#

Codice:
# The actions to be executed when parameter values are changed. Note that

Codice:
# all actions must be enclosed in double quotes.

Codice:
:local paramActions {

Codice:
       "/system script run log-up-down""/system script run log-up-down"

Codice:
       "/system script run log-up-down"

Codice:
}

Codice:
#

Codice:
# The action to be executed when the script is run for the first time after

Codice:
# RouterOS is booted up.

Codice:
:local initAction ":log info \"Monitoring started\""

Codice:
#

Codice:
############################################################################

Codice:
# Don't change anything below this line.

Codice:
############################################################################


Codice:
:global monTimeCounter

Codice:
:global monParamValues

Codice:
:global monParamValuesChangedAt


Codice:
:local newParamValues

Codice:
:local newParamValuesChangedAt


Codice:
:if ($monTimeCounter > 0) do={

Codice:
} else={

Codice:
       :set monTimeCounter 0

Codice:
       :local action [:parse $initAction]

Codice:
       $action:for i from=0 to=([:len $paramNames] - 1) do={

Codice:
       :if ([:pick $paramValues $i] = [:pick $monParamValues $i]) do={

Codice:
               :set newParamValues ($newParamValues, [:pick $monParamValues $i])

Codice:
               :set newParamValuesChangedAt ($newParamValuesChangedAt, [:pick $monParamValuesChangedAt $i])

Codice:
       } else={

Codice:
               :set newParamValues ($newParamValues, [:pick $paramValues $i])

Codice:
               :set newParamValuesChangedAt ($newParamValuesChangedAt, $monTimeCounter)

Codice:
               :global monParamName [:pick $paramNames $i]

Codice:
               :global monParamOldValue [:pick $monParamValues $i]

Codice:
               :global monParamNewValue [:pick $paramValues $i]

Codice:
               :global monParamOldValueAge ($monTimeCounter - [:pick $monParamValuesChangedAt $i])

Codice:
               :local action [:parse [:pick $paramActions $i]]

Codice:
               $action

Codice:
       }

Codice:
}


Codice:
:set monTimeCounter ($monTimeCounter + $runInterval)

Codice:
:set monParamValues $newParamValues

Codice:
:set monParamValuesChangedAt $newParamValuesChangedAt


Codice:
############################################################################

Codice:
# Script name:   log-up-down

Codice:
# Last changed:  25 Feb 2011

Codice:
# ROS version:   5.0rc10

Codice:
# Author:        Vadim Guchenko [yhw at relost dot net]

Codice:
#

Codice:
# Logs the new value of the parameter in terms of "up" and "down". Also logs

Codice:
# uptime/downtime. Used in conjunction with the monitoring script.

Codice:
#

Codice:
# There is nothing to configure.

Codice:
############################################################################


Codice:
:global monParamName

Codice:
:global monParamNewValue

Codice:
:global monParamOldValueAge


Codice:
:local status

Codice:
:local time


Codice:
:if ($monParamNewValue = true) do={

Codice:
       :set status "up"

Codice:
       :set time "downtime"

Codice:
} else={

Codice:
       :set status "down":set time "uptime"

Codice:
}


Codice:
:log info "$monParamName is $status ($time=$[:totime $monParamOldValueAge])"

Cita messaggio


Discussioni simili
Discussione Autore Risposte Letto Ultimo messaggio
Exclamation Script: Notifica sovraccarico CPU hamtarociaoo 1 1'858 10-09-2016, 01:18
Ultimo messaggio: hunte88
Information [Mikrotik] Semi-Automating CPE ROS/Firmware/script updates and setting changes berryberry 0 1'503 17-06-2015, 11:54
Ultimo messaggio: berryberry
Information [Mikrotik] SXT 5HnD Alignment Script berryberry 0 1'835 17-06-2015, 11:47
Ultimo messaggio: berryberry
Information [Mikrotik] Yet Another Alignment Script With LEDs And Sound berryberry 0 2'379 17-06-2015, 11:07
Ultimo messaggio: berryberry
  [Mikrotik] Improved auto upgrade script v3.X berryberry 0 1'388 17-06-2015, 10:53
Ultimo messaggio: berryberry
Information [Mikrotik] Automated Upgrade/Downgrade script V3.9+ berryberry 0 1'376 17-06-2015, 10:51
Ultimo messaggio: berryberry
Information [Mikrotik] Auto upgrade script V3.x berryberry 0 850 17-06-2015, 10:34
Ultimo messaggio: berryberry
Information [Mikrotik] Monitor logs, send email alert / run script berryberry 0 1'302 16-06-2015, 10:55
Ultimo messaggio: berryberry
Information [Mikrotik] Resilience /Monitoring -ECMP Failover Script berryberry 0 1'032 16-06-2015, 09:45
Ultimo messaggio: berryberry
Information [Mikrotik] Log Parser - Event Trigger Script berryberry 0 1'136 11-06-2015, 09:52
Ultimo messaggio: berryberry

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Utenti che stanno guardando questa discussione:
1 Ospite(i)


Powered by MyBB, © 2002-2019 MyBB Group.