I’m totally brand new to MT scripting (and not a programmer).
I found a great script to test for changes in the status of a route but needed to make a couple of changes:
- Check for changes in multiple routes – so I made the variables unique for each route by add 3 numbers that have significance to me to the ends of the var names
- Change TRUE and FALSE to UP and DOWN
Here’s what I came up with (after hiking the learning curve):
{
:global prevstatus355;
:global updown355;
:global status355 [:ip route get value-name=active [:ip route find comment="355"]]
:global true true
:global false false
:log info $status355;
:log info $prevstatus355;
:log info $true
:log info $false
:if ( "$status355" != "$prevstatus355" ) do={
:if ( "$status355" = $true ) do={
:log info "works";
:set $updown355 UP;
log info $status355;
}
:log warn "355 connectivity changed status from \"$prevstatus355\" -> \"$status355\" (true=up, false=down, nothing=unintialized)";
:tool e-mail send to=xxxxxxxx subject="355 Connectivity now \"$updown355\"" body=( [ :system clock get date ] . " " . [ :system clock get time ] . " 355 connectivity changed status from \"$prevstatus355\" -> \"$updown355\" (true=up, false=down, nothing=unintialized)" )
}
:set $prevstatus $updownstatus
:global prevstatus355 $status355
}
How bad is this?
Also, will this check for connectivity (that’s really what I was looking for)?
Thanks!
:global true true
:global false false
Enough, I’ll stop here.
I thought I’d seen them all…
You’re welcome (;-)!
I was trying to figure out what my ‘if’ statements comparing variable contents weren’t working.
But, please go on…
This section (a nested if) breaks the scripts and I’m having no luck figuring out how to fix it:
:
if ( "$status355" = $true ) do={
:log info "works";
:set $updown355 UP;
log info $status355;
}
I just wanted to the email notification to read “Up” instead of “true”
Okay, I got it working – Fun learning this stuff!
{
:global prevstatus355;
:global updown355;
:global status355 [:ip route get value-name=active [:ip route find comment="355"]]
:log info ("status355 is $status355");
:log info ("prevstatus355 is $prevstatus355");
:if ( "$status355" = true ) do={:set updown355 UP} else= {:set updown355 DOWN}
:log info ("updown355 is $updown355");
:if ( "$status355" != "$prevstatus355" ) do={
:log warn "355 connectivity is now \"$updown355\" ";
:tool e-mail send to=xx@xx.com subject="355 Connectivity now \"$updown355\"" body=( [ :system clock get date ] . " " . [ :system clock get time ] . " 355 connectivity changed status from \"$prevstatus355\" -> \"$updown355\" " )
:set prevstatus355 $status355
}
Learn from this.
:global prevstatus355
{
/ip route
:local status355 [get [find where comment="355"] active]
:if ($status355) do={:set status355 "UP"} else={:set status355 "DOWN"}
:log info "status355 is $status355 and prevstatus355 is $prevstatus355"
:if ($status355 != $prevstatus355) do={
:log warning "355 connectivity is now $status355"
/tool e-mail send to=email@example.com subject="355 Connectivity is now $status355" \
body="$[/system clock get date] $[/system clock get time] 355 connectivity changed status $prevstatus355 -> $status355"
:set prevstatus355 $status355
}
}
One of the assumptions needed to not block this script is: There must be for sure one and only one route with that comment.