Community discussions

 
User avatar
fcucci
newbie
Topic Author
Posts: 30
Joined: Mon Feb 13, 2012 11:31 am
Location: Italy

BGP Peer state

Mon Jul 09, 2018 12:25 pm

Hi All,

I have a problem with a script; it works good via shell but doesn't work on system/script also if I import the code exactly as is.

{:if ([/routing bgp peer get [find name="CYMRU-1"] state] = "established") do={:global CYMRUSTATE;:delay 1;:set $CYMRUSTATE value="1";} else={:log error message="BGP Peer state not established"; /routing ospf instance set 0 distribute-default=never; :if ($CYMRUSTATE = "1") do={/tool e-mail send from=r1@mydomain.it server=X.X.X.X to=support@mydomain.it subject="BGP Peer down" port=25 body="BGP Peer down";:delay 1;:set $CYMRUSTATE value="0";}}}
When the peer is enstablished, it set the $CYMRUSTATE=1 (works); when the peer is idle it writes in log, it change OSPF instance but doen't change $CYRMUSTATE to 0 and doesn't send mail; same script copied and pasted in terminal works without problems,

WHY ? Any ideas ?
Francesco Cucci
MTCNA-MTCRE-MTCTC-MTCINE Certified
 
User avatar
fcucci
newbie
Topic Author
Posts: 30
Joined: Mon Feb 13, 2012 11:31 am
Location: Italy

Re: BGP Peer state

Mon Jul 09, 2018 6:48 pm

Nobody ?
Francesco Cucci
MTCNA-MTCRE-MTCTC-MTCINE Certified
 
User avatar
doneware
Trainer
Trainer
Posts: 408
Joined: Mon Oct 08, 2012 8:39 pm
Location: Hungary

Re: BGP Peer state

Sat Jul 14, 2018 2:32 pm

you should start your script the following way:

{:global CYMRUSTATE; if .... }

you always need to declare that a variable is global in the script, even if it exists. otherwise you can't reference it.

your code defined CYMRUSTATE in an IF condition. so whenever the condition was fulfilled, you had the variable in your scope, otherwise you don't have access to it.
if you run the same script as CLI, you already have CYMRUSTATE in your scope.
#TR0359
 
User avatar
fcucci
newbie
Topic Author
Posts: 30
Joined: Mon Feb 13, 2012 11:31 am
Location: Italy

Re: BGP Peer state

Mon Jul 23, 2018 1:05 pm

Hi doneware,

OK, now it works good.

Thank you so much !!
Francesco Cucci
MTCNA-MTCRE-MTCTC-MTCINE Certified

Who is online

Users browsing this forum: No registered users and 7 guests