# Force redundancy Failover via scripting

**URL:** <https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889>\
**Category:** Ignition\
**Tags:** redundancy, vision\
**Created:** [March 10, 2023, 8:41am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889 "2023-03-10T08:41:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 10, 2023, 8:41am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/1 "2023-03-10T08:41:28Z")

</div>

Hello,

I am trying to create a button in Vision to force a redundancy fail over. I intend it to work like the button in the gateway webpage.

I have found this post:

> [@Redundancy : trigger failover by scripting](https://forum.inductiveautomation.com/t/redundancy-trigger-failover-by-scripting/63137/10):
>
> We don’t currently have a supported mechanism for this, but the most basic action can be achieved with: from com.inductiveautomation.ignition.gateway.redundancy.types import ActivityLevel from com.inductiveautomation.ignition.gateway import IgnitionGateway redundancy\_manager = IgnitionGateway.get().getRedundancyManager() redundancy\_manager.requestPeerActivityLevel(ActivityLevel.Active) The above effectively requests the peer to become Active. There are some System tags available for discover…

and also I have found this on Ignition Exchange which use the same lines of code:

> **[Ignition Exchange](https://inductiveautomation.com/exchange/2185/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

But the code doesn't work for me. when I launch the function via script console, I receive an error.  
Either this one:  
`
Traceback (most recent call last):
File "<input>", line 1, in 
File "<module:diagnostics>", line 33, in requestFailover
ImportError: cannot import name IgnitionGateway
`  
Or this one:  
`
Traceback (most recent call last):
File "<input>", line 1, in 
File "<module:diagnostics>", line 33, in requestFailover
ImportError: No module named redundancy
`  
Depending on which import come first.

Any idea why?

Best regards

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 10, 2023, 9:15am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/2 "2023-03-10T09:15:20Z")

</div>

Those names are only available in gateway scope. You cannot run them from the designer or from a vision client. Use a gateway message handler.

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 10, 2023, 10:33am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/3 "2023-03-10T10:33:32Z")

</div>

Ok, I understand why it doesn't work from console.

In the Ignition Exchange project. The function is called like that:  
`
def runAction(self, event):
import diagnostics
diagnostics.requestFailover()
`

In my case, this seems to do nothing...  
Any idea why?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 11, 2023, 11:15am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/4 "2023-03-11T11:15:07Z")

</div>

Look for errors in your gateway log relating to that diagnostics script.

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 13, 2023, 6:50am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/5 "2023-03-13T06:50:38Z")

</div>

I see nothing in the Gateway Logs.  
Btw, I don't know how to filter/search for script error in the logs.

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 13, 2023, 10:58am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/6 "2023-03-13T10:58:35Z")

</div>

I would like to add, that if I add a print() in the function, it is not displayed in the log... my guess is the log may not be configured correctly.

I don't know why, Everything about logs is default configuration, I have changed nothing voluntarily.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 13, 2023, 11:20am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/7 "2023-03-13T11:20:16Z")

</div>

> [@Jeremy](#):
>
> add a print() in the function, it is not displayed in the log

Print would never show in the gateway web interface's logs. If executed in gateway scope, a print may show up in the wrapper log. But Vision client scripts would print to the vision client's diagnostic console, not the gateway, because they aren't gateway scope. These scripts will never work directly in a Vision button. You need to send a message to a gateway message handler and have that handler execute these operations.

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 13, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/8 "2023-03-13T11:48:48Z")

</div>

OK, thank you.

Now, my button send a message to the gateway who execute the script and it works.

Now, I am wondering, how and if the Exchange project works...

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 13, 2023, 11:59am UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/9 "2023-03-13T11:59:49Z")

</div>

> [@Jeremy](#):
>
> how and if the Exchange project works

Does it offer this function in Vision? It is marked as Maker-compatible, so it must use Perspective. Perspective scripts run in gateway scope.

---

<div class="post-metadata">

**Author:** ![Jeremy](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@Jeremy](https://forum.inductiveautomation.com/u/Jeremy)\
**Post date:** [March 13, 2023, 1:17pm UTC](https://forum.inductiveautomation.com/t/force-redundancy-failover-via-scripting/70889/10 "2023-03-13T13:17:02Z")

</div>

It does use Perspective. So that's why.

Thanks a lot for all !
