Restart Gateway Network Connection from script?

@Kevin.Herron @PGriffith
Is it possible to restart gateway network connections via script?

I.e. press this button:

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

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.

1 Like

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 :thinking: any clues?

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

1 Like

Yep!

I may have had a bit more help with this one :slight_smile:

Thanks all!

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)
2 Likes

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!

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