Community discussions

MikroTik App
 
User avatar
hughrobbie
just joined
Topic Author
Posts: 10
Joined: Wed Apr 15, 2015 2:29 pm
Location: KZN
Contact:

SFP monitor array

Wed Jun 02, 2021 4:42 pm

Hi Guys,

quick question, I'm trying to get an array script to monitor my sfp signals, if any interface defined in my array is higher than -16 to log info as a test, however, I cant seem to get it working and my syntax seems correct, perhaps someone can guide me in the right direction?

Below is my code:
#Hugh's SFP script
:global thisbox [/system identity get name];
:global thistime [/system clock get time];
:global thisdate [/system clock get date];
:global sfplist [:toarray "sfp1,sfp3,sfp7,sfp8,sfp12"];
:global sfpsignal;
:global sfpmonitor;
:foreach i in=$sfplist do={
:set $sfpmonitor [/interface monitor-traffic $i as-value once];
:set $sfpsignal [:put ($sfpmonitor->"sfp-rx-power")];
:if ($sfpsignal<"-16000") do={log warning "there is an issue with $i signal is at $sfpsignal"
} else={log warning "no issue found on $i"}
Thanks in advance.
Hugh
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: SFP monitor array

Wed Jun 02, 2021 7:44 pm

I do not have any SFP, so can not test it, but you do miss a } at the end.
You do not need ; at end of each line, only when havning multiple command at one line.
Using tab makes it simpler to see missing }
Using code tabs make script show tabs when posing </>
#Hugh's SFP script
:local thisbox [/system identity get name]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local sfplist [:toarray "sfp1,sfp3,sfp7,sfp8,sfp12"]
:local sfpsignal
:local sfpmonitor
:foreach i in=$sfplist do={
	:set $sfpmonitor [/interface monitor-traffic $i as-value once]
	:set $sfpsignal [:put ($sfpmonitor->"sfp-rx-power")]
	:if ($sfpsignal<"-16000") do={
		log warning "there is an issue with $i signal is at $sfpsignal"
	} else={
		log warning "no issue found on $i"
	}
}
 
User avatar
hughrobbie
just joined
Topic Author
Posts: 10
Joined: Wed Apr 15, 2015 2:29 pm
Location: KZN
Contact:

Re: SFP monitor array

Tue Jun 15, 2021 9:48 am

Thanks for this, I also found I had a bad line of script on the monitor part, had to change it to:
:set $sfpmonitor [/interface ethernet monitor "$i" once as-value];

and all seems to be working now, thanks again for the assistance.
I do not have any SFP, so can not test it, but you do miss a } at the end.
You do not need ; at end of each line, only when havning multiple command at one line.
Using tab makes it simpler to see missing }
Using code tabs make script show tabs when posing </>
#Hugh's SFP script
:local thisbox [/system identity get name]
:local thistime [/system clock get time]
:local thisdate [/system clock get date]
:local sfplist [:toarray "sfp1,sfp3,sfp7,sfp8,sfp12"]
:local sfpsignal
:local sfpmonitor
:foreach i in=$sfplist do={
	:set $sfpmonitor [/interface monitor-traffic $i as-value once]
	:set $sfpsignal [:put ($sfpmonitor->"sfp-rx-power")]
	:if ($sfpsignal<"-16000") do={
		log warning "there is an issue with $i signal is at $sfpsignal"
	} else={
		log warning "no issue found on $i"
	}
}

Who is online

Users browsing this forum: Bing [Bot] and 17 guests