SFP monitor array

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

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"
	}
}

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.