mirror of
https://github.com/gbudny93/RouterOS_Useful_Scripts.git
synced 2025-06-20 17:15:47 +02:00
Update
This commit is contained in:
parent
ec0478cbca
commit
1508f05bc0
7 changed files with 82 additions and 39 deletions
|
@ -1,21 +1,25 @@
|
|||
# RouterOS Function
|
||||
# Copyright (c) Grzegorz Budny
|
||||
# Creates directory in RouterOS
|
||||
|
||||
:global CreateDirecotry do={
|
||||
|
||||
:global userName;
|
||||
:global password;
|
||||
:global directoryName;
|
||||
:global tempFileName temp.rsc;
|
||||
:global userName;
|
||||
:global password;
|
||||
:global directoryName;
|
||||
:global tempFileName temp.rsc;
|
||||
|
||||
system identity export file=$tempFileName;
|
||||
/system identity export file=$tempFileName;
|
||||
/tool fetch address=127.0.0.1 src-path=$tempFileName user=$userName password=$password \
|
||||
dst-path=($directoryName."/".$tempFileName) mode=ftp port=21;
|
||||
|
||||
tool fetch address=127.0.0.1 src-path=$tempFileName user=$userName password=$password dst-path=($directoryName."/".$tempFileName) mode=ftp port=21;
|
||||
/file remove ($directoryName."/".$tempFileName);
|
||||
/file remove $tempFileName;
|
||||
|
||||
file remove ($directoryName."/".$tempFileName);
|
||||
file remove $tempFileName;
|
||||
|
||||
:log info ("New directory created - ".$directoryName)
|
||||
:log info ("New directory created - ".$directoryName);
|
||||
|
||||
}
|
||||
|
||||
$CreateDirecotry userName=UserName password=Password directoryName=DirectoryName
|
||||
$CreateDirecotry userName=UserName password=Password directoryName=DirectoryName;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
# RouterOS Function
|
||||
# Copyright (c) Grzegorz Budny
|
||||
# Adds log entry if file is removed or added
|
||||
|
||||
:global FileToLog do={
|
||||
|
||||
:local fileName "FilesCount.txt";
|
||||
:local fileCountOld;
|
||||
:local fileCountCurrent;
|
||||
|
||||
:if ([:len [/file find name=$fileName]] <= 0) do={
|
||||
|
||||
/file print file=$fileName;
|
||||
:delay 5;
|
||||
/file set $fileName contents=[/file print count-only];
|
||||
|
||||
}\
|
||||
else={
|
||||
|
||||
:set $fileCountOld [/file get $fileName contents];
|
||||
:set $fileCountCurrent [/file print count-only];
|
||||
|
||||
:if ($fileCountCurrent > $fileCountOld) do={
|
||||
|
||||
:log warning "File has been added";
|
||||
/file set $fileName contents=$fileCountCurrent;
|
||||
|
||||
}
|
||||
:if ($fileCountCurrent < $fileCountOld) do={
|
||||
|
||||
:log warning "File has been removed";
|
||||
/file set $fileName contents=$fileCountCurrent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$FileToLog;
|
0
RouterOS_LCD_Change.rsc
Normal file
0
RouterOS_LCD_Change.rsc
Normal file
|
@ -1,3 +1,7 @@
|
|||
# RouterOS Script
|
||||
# Copyright (c) Grzegorz Budny
|
||||
# Filters logs to desired output for specified match
|
||||
|
||||
:global LogFilter do={
|
||||
|
||||
:local message #message
|
||||
|
|
|
@ -1,21 +1,35 @@
|
|||
# RouterOS Function
|
||||
# Copyright (c) Grzegorz Budny
|
||||
# Generates mail alarm based on log message match
|
||||
|
||||
:global LogToAlert do={
|
||||
|
||||
:local logMessage $message;
|
||||
|
||||
:local logMessage $message
|
||||
:local logCount [/log print count-only where message~$logMessage]
|
||||
:local logArray
|
||||
|
||||
:put $logCount
|
||||
:local logFoundCount;
|
||||
:local logArray;
|
||||
:local alarmText;
|
||||
|
||||
:local logCount [/log print count-only where message~$logMessage];
|
||||
:local systemName [/system identity get value-name=name];
|
||||
|
||||
:if ($logCount > 0) do={
|
||||
|
||||
:set $logArray [/log find where message~$logMessage];
|
||||
:toarray value=$logArray;
|
||||
:set logFoundCount [:len value=$logArray];
|
||||
|
||||
:set $logArray [/log find where message~$logMessage]
|
||||
:toarray value=$logArray
|
||||
:log print file=$fileName where .id=($logArray->($logFoundCount-1));
|
||||
|
||||
:log print where .id=($logArray->0)
|
||||
:set alarmText [/log print where .id=($logArray->($logFoundCount-1))];
|
||||
|
||||
}
|
||||
:log warning "$systemName triggered mail alarm";
|
||||
|
||||
/tool e-mail send server=$smtpServer port=$smtpPort from=($systemName.$domain) \
|
||||
to=$recipient subject=($systemName." triggered an alarm!") body="Enclosed detected alarm log message" \
|
||||
file=$fileName;
|
||||
}
|
||||
}
|
||||
$LogToAlert message="winbox"
|
||||
|
||||
$LogToAlert message="message" fileName="fileName" smtpServer=smtpServer smtpPort=smtpPort domain="@example.com" \
|
||||
recipient="recipient@example.com";
|
|
@ -1,18 +0,0 @@
|
|||
:global SendEmail do={
|
||||
|
||||
:local smtpServer #smtp server IP
|
||||
:local smtpPort #smtp port
|
||||
:local from #sender email
|
||||
:local to #recipeints email
|
||||
:local cc #cc email
|
||||
:local subject #email subject
|
||||
:local body #email body
|
||||
|
||||
:log info "..::Sending email notification::..";
|
||||
tool e-mail send server=$smtpServer port=$smtpPort from=$from to=$to cc=$cc subject=$subject body=$body;
|
||||
|
||||
}
|
||||
|
||||
$SendEmail smtpServer=SMTPServer smtpPort=SMTPPort from=From to=To subject=Subject body=Body
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue