{"id":4895,"date":"2023-03-17T21:26:00","date_gmt":"2023-03-18T02:26:00","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=4895"},"modified":"2023-03-17T14:09:45","modified_gmt":"2023-03-17T19:09:45","slug":"mikrotik-script-send-webhook-when-power-fails-on-psu","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/mikrotik-script-send-webhook-when-power-fails-on-psu\/","title":{"rendered":"Mikrotik Script &#8211; Send Webhook when Power Fails on PSU"},"content":{"rendered":"\n<p>The goal for this script is to alert us if a remote site looses power.  We can do this using a Mikrotik that has two PSUs.  One is plugged into battery backup and the other in the non battery plug.<\/p>\n\n\n\n<p>In this example, we are using PSU2 &#8220;number 8&#8221;  We can find the number using <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/system\/health\/print<\/pre>\n\n\n\n<p>We can now create a new scheduler entry with the following.  Change out the number 8 to your PSU number, and change the webhook to your Teams webhook.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:local curState [system\/health\/get value-name=value  number=8]\n:local name [\/system\/identity\/get value-name=name]\n:local webhook \"https:\/\/teams.webhook.microsoft.com\/webhook\/more\"\n\nif ($curState != $lastState) do={\nif ($curState = \"ok\") do={\n\/tool fetch http-method=post http-header-field=\"Content-Type: application\/json\" http-data=\"{\\\"text\\\": \\\"$name : Power is on.\\\"}\" url=\"$webhook\"\n}\nif ($curState != \"ok\") do={\n\/tool fetch http-method=post http-header-field=\"Content-Type: application\/json\" http-data=\"{\\\"text\\\": \\\"$name : Power is off.  On battery backup\\\"}\" url=\"$webhook\"\n}\n:global lastState $curState\n}<\/pre>\n\n\n\n<p>Set to the appropriate interval (i.e. 5 minutes).  The script will only alert once when the power state changes.  This minimizes receiving an alert every 5 minutes while the power is off.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The goal for this script is to alert us if a remote site looses power. We can do this using a Mikrotik that has two PSUs. One is plugged into battery backup and the other in the non battery plug. &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/mikrotik-script-send-webhook-when-power-fails-on-psu\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[452],"tags":[301,388,1421,173],"class_list":["post-4895","post","type-post","status-publish","format-standard","hentry","category-mikrotik","tag-mikrotik","tag-routeros","tag-scheduler","tag-script"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=4895"}],"version-history":[{"count":1,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4895\/revisions"}],"predecessor-version":[{"id":4896,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4895\/revisions\/4896"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=4895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=4895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=4895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}