Community discussions

 
fallegretti
newbie
Topic Author
Posts: 33
Joined: Thu Jul 20, 2017 1:23 pm

Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 12:26 pm

Hi all,

I am trying to write scripts to control my Internal <-> external traffic.

I got a script working in case a BGP session is anything but established I am disabling the internal ip address where I run OSPF.

I am having issues with the other side because the OSPF neighbor is not present at all (unlike BGP where the session changes to idle for example) when the internal interface is down.

This means that when I check for the neighbor I get a no such item error. The script works when I want to re-enable the ip address, here is the example:
add dont-require-permissions=no name=var1 owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
\n:local new;\
\n:set new [/routing ospf neighbor get [find address=\"192.168.37.1\"] state];\
\nif (new=\"Full\") do={\
\n/ip address enable [find interface=LO173];\
\n}"
But if OSPF is down I get an error "no such item"

Hope I have explained myself, let me know if you have any questions. Thanks for your help.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5934
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 1:37 pm

Of course you will get no such item, because you are trying to get "state" parameter for non-existent item.

First check if ospf neighbor exist and only then try to get any params.
 
fallegretti
newbie
Topic Author
Posts: 33
Joined: Thu Jul 20, 2017 1:23 pm

Re: Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 1:48 pm

Thanks MRZ,

Maybe I should have explained this a little better.

The idea is to monitor the OSPF status using a continuous loop ( if there are better ways to achieve this, please let me know).

The script would have to do be pretty much (not exactly):
if status is "Full" do nothing
else
shut down Lo123

The issue is that if OSPF is down, the neighbor is not there and therefore I get an error.

I now am looking at the option:
on-error={
would that work?
 
fallegretti
newbie
Topic Author
Posts: 33
Joined: Thu Jul 20, 2017 1:23 pm

Re: Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 1:50 pm

Hi MRZ,

You say "First check if ospf neighbor exist and only then try to get any params." how do I achieve this?

Because I could write a script that says:

"check if OSPF neighbor exist"
if not
shut down interface
!
If I knew how to check if ospf neigh existed.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5934
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 2:01 pm

if ([/routing ospf neighbor find where address=\"192.168.37.1\"] != "") do={
#get state
{
 
fallegretti
newbie
Topic Author
Posts: 33
Joined: Thu Jul 20, 2017 1:23 pm

Re: Script to disable BGP when OSPF neighbor down - No such item

Tue Dec 18, 2018 4:28 pm

Thanks mrz,

That seems to work only if the neighbor is up, which is not my problem.

In case the neighbor is down, which is what I want to check, I still get the error: no such item.

In other words if the neighbor exist then the statement:
if ([/routing ospf neighbor get [find address=\"192.168.37.1\"] ] != "")
returns a true vale
if it does not exist it does NOT return a false value but it just throws an error.

I could solve the issue if I could initiate action on errors; is that possible?

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 2 guests