This commit is contained in:
Grzegorz Budny 2019-08-03 10:48:07 +02:00
parent 0f3f4a1950
commit 50874b1760
3 changed files with 89 additions and 0 deletions

View file

@ -5,6 +5,12 @@
## Change log
- 8/3/2019
- RouterOS_String_Generator.rsc
- Generates 6 char string based on dictionary
- RouterOS_Reset_Interface.rsc
- Resets interface if particular IP does not respond
- 7/29/2019
- RouterOS_Modulo.rsc
- Modulo operation
@ -162,6 +168,22 @@ $Modulo number=number_to_be_devided modulo=modulo_value;
$LoadScript scriptName=scriptName.rsc;
```
### RouterOS_String_Generator.rsc
> Generates 6 char string based on dictionary
```
$GenerateString;
```
### RouterOS_Reset_Interface.rsc
> Resets interface if particular IP does not respond
```
$ResetInterface ipAddress=ipAddress_To_Monitor interfaceName=interface_name;
```
## Authors
- Grzegorz Budny

View file

@ -0,0 +1,22 @@
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Reset interface if particular IP does not respond
:global ResetInterface do={
:if ([/ping $ipAddress interval=1 count=4] > 0) do={
:log info "...:::Interface healthcheck. Status OK:::..."
}\
else={
:log error ("...:::Monitor detected ".$interfaceName." down. Resetting:::...");
/interface ethernet disable $interfaceName;
:delay 3;
/interface ethernet enable $interfaceName;
}
}
$ResetInterface ipAddress=ipAddress_To_Monitor interfaceName=interface_name;

View file

@ -0,0 +1,45 @@
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Generates random string based on dictionary of six chars length
:global GenerateString do={
:global generatedString;
:local characters q,w,e,r,t,y,u,i,o,p,l,k,j,h,g,f,1,2,3,4,5,6,7,8,9,0,d,s,a,z,x,c,v,b,n,m,M,N,B,V,C,X,Z,A,S,D,F,G,H,J,K,L,P,O,I,U,Y,T,R,E,W,Q;
:local hour [:pick [/system clock get time] 0 2];
:local minute [:pick [/system clock get time] 3 5];
:local second [:pick [/system clock get time] 6 8];
:if ((:pick $hour 0) = 0) do={
:set $hour [:pick $hour 1];
}
:if ((:pick $minute 3) = 0) do={
:set $minute [:pick $minute 4];
}
:if ((:pick $second 6) = 0) do={
:set $second [:pick $second 7];
}\
else={
:log warning "Something's wrong with system time. Check system time and NTP settings.";
}
:set $generatedString ($generatedString.([:pick $characters $hour].[:pick $characters $minute].[:pick $characters $second].\
[:pick $characters ($hour/2)].[:pick $characters ($minute/2)].[:pick $characters ($second/2)]));
:log info "...:::Random string generated:::..."
:return ($generatedString);
}
$GenerateString;