# Restart Gateway Network Connection from script?

**URL:** <https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013>\
**Category:** Ignition\
**Created:** [April 4, 2022, 6:05pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013 "2022-04-04T18:05:24Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 4, 2022, 6:05pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/1 "2022-04-04T18:05:24Z")

</div>

@Kevin.Herron @paul-griffith  
Is it possible to restart gateway network connections via script?

I.e. press this button:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba2c86e84bcac1bd032248e9e8b4d81476f3f06c.png)

I want to give operators access to this from clients while we’re still trying to resolve performance issues so that I don’t have to take lots of calls in the early hours of the morning to press this button myself

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 4, 2022, 6:10pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/2 "2022-04-04T18:10:54Z")

</div>

Mmm, not easily. It’s a private method on the `GatewayNetworkManager` you get from `GatewayContext::getGatewayAreaNetworkManager` and it takes the record ID as a parameter, not the name of the connection.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 4, 2022, 6:44pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/3 "2022-04-04T18:44:39Z")

</div>

I’m almost there, I just don’t know how to get the id. On the available connections collection items I’ve tried getting `getId`, `getLocalUUID` and some others. The restart connection method is looking for an id of type Java.lang.Long 🤔 any clues?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 4, 2022, 6:55pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/4 "2022-04-04T18:55:51Z")

</div>

I’m pretty sure it’s the ID of the row in the internal database, if that helps.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 4, 2022, 7:26pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/5 "2022-04-04T19:26:21Z")

</div>

Yep!

I may have had a bit more help with this one 🙂

Thanks all!

```auto
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.gateway.gan import WSConnectionSettings
from simpleorm.dataset import SQuery,SQueryMode

# Parameters
target_host = "outgoing-connection-hostname"
target_port = 8060

# Obtain PersistenceInterface
gateway = IgnitionGateway.get()
pi = gateway.getPersistenceInterface()
gan_manager = gateway.getGatewayAreaNetworkManager()

# Setup a query
query = SQuery(WSConnectionSettings.META, SQueryMode.SREAD_ONLY)
query = query.eq(WSConnectionSettings.Host, target_host)
query = query.eq(WSConnectionSettings.Port, target_port)

# Issue query
record = pi.queryOne(query)

if record is not None:
	record_id = record.getId()
	gan_manager.restartConnection(record_id)

```

---

<div class="post-metadata">

**Author:** ![fadihindi](https://avatars.discourse-cdn.com/v4/letter/f/34f0e0/32.png) [@fadihindi](https://forum.inductiveautomation.com/u/fadihindi)\
**Post date:** [September 9, 2022, 11:40pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/6 "2022-09-09T23:40:23Z")

</div>

When I try to implement this code I get the following errors for line 1 and 2: “ImportError: No module named gateway”  
And for line 3 : “ImportError: No module named simpleorm”  
What could I be doing wrong?

Also, would this work for either outgoing or incoming connections?

Thanks for any help, I’m looking for exactly this function!

---

<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:** [September 9, 2022, 11:41pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/7 "2022-09-09T23:41:33Z")

</div>

Gateway scope only. Won’t work in the script console, which is Designer scope (a variant of Vision Client scope).

---

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [October 26, 2023, 4:58pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/8 "2023-10-26T16:58:57Z")

</div>

> [@nminchin](#):
>
> ```auto
> from com.inductiveautomation.ignition.gateway import IgnitionGateway
> from com.inductiveautomation.ignition.gateway.gan import WSConnectionSettings
> from simpleorm.dataset import SQuery,SQueryMode
> 
> ```

I'm curious as to how someone becomes aware of and finds info on `com.inductiveautomation.ignition.gateway.IgnitionGateway`?

`IgnitionGateway` is not listed as a package, module or member of `com.inductiveautomation.ignition.gateway` in the [Ignition javadocs](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.33/index.html).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 26, 2023, 5:04pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/9 "2023-10-26T17:04:40Z")

</div>

`IgnitionGateway` is an internal "implementation" class. You aren't _supposed_ to program against it.  
The proper way to do something like this is to write a module, where you will be delivered a (documented) `GatewayContext` object in your `setup` hook and can use that to get access to the (supported from module development) managers that represent various subsystems.

_None_ of what Nick wrote is supported from scripting. Your resource for discovery is these forums.

Sneak edit: Scooped ya, Phil 🙂

---

<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:** [October 26, 2023, 5:06pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/10 "2023-10-26T17:06:50Z")

</div>

> [@paul-griffith](#):
>
> Scooped ya, Phil

I saw you were typing. I just wasn't fast enough. 😛

---

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [October 26, 2023, 6:36pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/11 "2023-10-26T18:36:09Z")

</div>

@paul-griffith, so is there is no "proper" way to get a `GatewayContext` object for gateway scripting, outside of developing a module?

The use case I was looking into was finding a way to list all configured gateway network connections and their status since that does not seem to be available through the [system functions](https://docs.inductiveautomation.com/display/DOC81/System+Functions). I managed to pull some detail by making a revised version of @nminchin's script above using trial-and-error and guesswork (see below)... but it would be great to have better documentation on the attributes for each object used (particularly for `class com.inductiveautomation.metro.impl.ConnectionWatcher`), or a supported/approved way to get at the same detail.  
BTW, I am aware of the very limited status info available in the system tags at `[System]Gateway/Gateway Network`.

```python
	from com.inductiveautomation.ignition.gateway import IgnitionGateway

	gateway = IgnitionGateway.get()
	pi = gateway.getPersistenceInterface()
	gan_manager = gateway.getGatewayAreaNetworkManager()
	gan_connections = gan_manager.getAvailableConnections()
	
	gan_connections_info = []
	for connection in gan_connections:
		gan_connections_info.append({
			 "certificateChain" : connection.certificateChain
			,"class" : connection.class
			,"currentIncomingMessages" : connection.currentIncomingMessages
			,"currentOutgoingMessages" : connection.currentOutgoingMessages
			,"direction" : connection.direction
			,"id" : connection.id
			,"inboundConnection" : connection.inboundConnection
			,"incomingOneMinRate" : connection.incomingOneMinRate
			,"lastCommTime" : connection.lastCommTime
			,"lastError" : connection.lastError
			,"localUUID" : connection.localUUID
			,"outgoingDescription" : connection.outgoingDescription
			,"outgoingOneMinRate" : connection.outgoingOneMinRate
			,"pingTime" : connection.pingTime
			,"remoteId" : connection.remoteId
			,"remoteNetworkAddress" : connection.remoteNetworkAddress
			,"remoteServerAddress" : connection.remoteServerAddress
			,"routedServers" : connection.routedServers
			,"sessionId" : connection.sessionId
			,"state" : connection.state
			,"status" : connection.status
			,"toString" : connection.toString()
		})
	
	return {
		"gan_connection_info": gan_connections_info
	#	,"gan_manager_attributes" : ( type(gan_manager), dir(gan_manager) ) 
	#	,"gan_connection_attributes" : ( type(connection ), dir(connection ) )
	#	,"ignitionGateway_attributes": ( type(gateway) , dir(gateway ) )
	#	,"ignitionGatewayPersistentInterface_attributes": ( type(pi), dir(pi) )
	}

```

---

<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:** [October 26, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/12 "2023-10-26T18:43:12Z")

</div>

> [@tyler.bennett](#):
>
> so is there is no "proper" way to get a `GatewayContext` object for gateway scripting, outside of developing a module?

No, because IA doesn't promise to keep SDK APIs backwards compatible, and implementation details do change from time to time. Module authors are expected to ~~suck it up~~ deal with it.

However, there are publicly available free modules that expose a gateway/designer/vision context, like my [Integration Toolkit module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) and Paul's open source [Ignition Extensions](https://github.com/IgnitionModuleDevelopmentCommunity/ignition-extensions).

Just know that anything you do in jython with a context object is subject to breakage on Ignition upgrades, and IA support will ignore your whining about it.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 26, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/13 "2023-10-26T18:52:53Z")

</div>

> [@pturmel](#):
>
> No, because IA doesn't promise to keep SDK APIs backwards compatible, and implementation details do change from time to time. Module authors are expected to ~~suck it up~~ deal with it.

For a concrete example:  
For basically all of Ignition's lifetime, we've been using SimpleORM and an internal database, though the 'flavor' of that internal DB has changed from HSQLDB to SQLite. We also take great pains to make _supported_ operations continue to work even when you upgrade Ignition.

So if the things you're doing in that script were supported, but we ditched SimpleORM (as we are in 8.3.0, when gateway config is moving to the filesystem), we would have to spend **even more** engineering effort adapting all of the scripting you had in place to "bridge" all the calls to whatever new system we come up with. Now expand that example to literally everything else in the gateway, designer, and client, across every version, across the entire history of Ignition.

We have to have _some_ line in the sand as far as guaranteed support; what we've come up with is _allowing_ access to these internal details (we don't make any effort to prevent you from doing things like you and Nick are doing here), but also not making it easier - because the "right" thing to do is for us to make a better first-party API that _is_ supported (and maintained) that solves the problem(s) you might have. For everything we can't/won't/haven't done first party, you've got the forums.

So the "right" solution would be an ideas post or a support ticket that describes your problem, and we'll collate that together with everyone else's feedback and decide on a future path for the product forward.

---

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [October 26, 2023, 7:21pm UTC](https://forum.inductiveautomation.com/t/restart-gateway-network-connection-from-script/58013/14 "2023-10-26T19:21:23Z")

</div>

@paul-griffith and @pturmel, thanks for taking the time to provide detailed responses and improve my understanding.
