Script to email on PSU failure

Obviously requires a dual PSU Routerboard!

I’m new to scripting, so there is probably a far more efficient way…

:global PSUfail "fail"
:local PSU1state [/system health get psu1-state]
:local PSU2state [/system health get psu2-state]
:if ($PSU1state = $PSUfail) do={/tool e-mail send to="xxx@gmail.com" body="PSU1 has failed" subject="**Router PSU failure**"}
:if ($PSU2state = $PSUfail) do={/tool e-mail send to="xxx@gmail.com" body="PSU2 has failed" subject="**Router PSU failure**"}

HTH