Community discussions

 
NetWorker
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Sun Jan 31, 2010 6:55 pm

No such item

Fri Apr 26, 2019 1:28 am

So I want to wite a script that checks if an item exists and performs an action if it doesn't.

Specifically, we want to check if ipsec is connected and if it isn't disable the l2tp interface so it doesn't endlessly pollute the log with reconnection attempts.

-----Background info-----
We have a 2 router setup at a remote location that connects to our central office via ipsec/l2tp. We chose this setup because it runs on UDP, ipsec offers hardware encryption and the use of certificates and l2tp simplifies other configs since you have an actual interface to work with rather than the interfaceless ipsec tunnel.
Each router is connected to a different wireless uplink (they are in different buldings) so if one link goes down, dynamic routes reroute the traffic to the other uplink. This means loosing one of the VPN connections is not a major concern. Though it does happen every now and then. And when it does, that router keeps on working but we want to disable the non funtional l2tp interface because it just keeps on trying to reconnect even though the ipsec connection is down (a filter rule drops l2tp traffic if it isn't encrytped).
------------------------------

Now, for the life of me I can't seem to move past the "no such item" error. My logical choice was:
/ip ipsec installed-sa get 0 anyproperty
This obviously throws "no such item" if there aren't any security associations installed. The same goes for remote peers.
I then thought of counting the policies since there's always at least one (default) with do while and for each. But I still run into the same problem. If I query a non existing policy number the script exits with "no such item".

How do you check for a non existing item in RouterOS??
 
Sob
Forum Guru
Forum Guru
Posts: 4621
Joined: Mon Apr 20, 2009 9:11 pm

Re: No such item  [SOLVED]

Fri Apr 26, 2019 4:43 am

Wouldn't it be more logical to check for number of items?
:log info [:len [/ip ipsec installed-sa find]];
And then compare if it's zero or more.
People who quote full posts should be spanked with ethernet cable. Some exceptions for multi-topic threads may apply.
 
NetWorker
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 74
Joined: Sun Jan 31, 2010 6:55 pm

Re: No such item

Mon Apr 29, 2019 4:22 pm

Wouldn't it be more logical to check for number of items?
:log info [:len [/ip ipsec installed-sa find]];
And then compare if it's zero or more.
*Facepalm* :lol: Thanks sob!

Who is online

Users browsing this forum: No registered users and 16 guests