Community discussions

MikroTik App
 
aryawidura
just joined
Topic Author
Posts: 3
Joined: Wed Jul 17, 2024 7:21 am

script notify and email if bgp status change

Wed Jul 17, 2024 8:52 am

Hi everyone,

Im newbie in script and have one unresolved script in my network
I`d like to create a script which would change some mangle, distance route and email me if BGP session is established or NOT based on ping link gateway
I have tried writing script from few source on this forum but it seem not works correctly, the problem is that on every script run it shows repeated status on the logs and e-mail notification
I would like to be notified only once (log & email) if the current status become different from the last status.
Im sory for my bad english, Thank you in advance

CTTH : viewtopic.php?t=40507
/viewtopic.php?t=189128
:global pinghost "10.10.211.2"
:global oldbgpstate
:if (:len $oldbgpstate = 0 ) do={ 
   :set $oldbgpstate {"_dummy"=33} }
:global bgpstates ({disabled=0},{idle=1},{connect=2},{active=3},{opensent=4},{openconfirm=5},{established=6})
    :foreach peer in=$bgpstate do={
    :global peerstate [:toarray [/routing bgp peer get $bgpstate state]]
	:global pstate [get $peer state]
        :if ( [get $peer disabled] ) do={ :set $pstate value="disabled" }
            :global peername [get $peer name]
            :global severity "info"
	    :global result [/ping 10.10.211.2 count=10]
    	
	    :if ($result=0) do={
            :log error "Ping host: ALL FAILED (0/10)"
            /ip firewall mangle set [find comment="mangle" disabled=yes] disabled=no
	    /tool e-mail send to=$emailTo subject="[$DeviceName] $emailSubject $commentFilter" body="$emailBody" 
	} else={
        :if ($result!=10) do={
            :log warning "Ping : ONLY SOME ($result/10)"
        } else={
            :log info "Ping host: ALL OK (10/10)"
            /ip firewall mangle set [find comment="mangle" disabled=no] disabled=yes
            /tool e-mail send to=$emailTo subject="[$DeviceName] $emailSubject $commentFilter" body="$emailBody"
        }
   }
} 

 
aryawidura
just joined
Topic Author
Posts: 3
Joined: Wed Jul 17, 2024 7:21 am

Re: script notify and email if bgp status change

Sat Jul 20, 2024 7:23 am

anyone, maybe have another idea
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12379
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script notify and email if bgp status change

Sat Jul 20, 2024 10:25 am

Of course: As he sees that script, he changes the topic.
 
aryawidura
just joined
Topic Author
Posts: 3
Joined: Wed Jul 17, 2024 7:21 am

Re: script notify and email if bgp status change

Mon Jul 22, 2024 6:11 am

So, what should i do to solve it

Who is online

Users browsing this forum: No registered users and 8 guests