Hello,
We would like to use several parameters of an element in an Automation script.
More specifically, we would like to retrieve the Polling IP and the SNMP Read community string, in order to trigger device-related actions directly on the device.
Below is what we have tried so far. However, the Read Community and Write Community values are always empty. We also tried setting/checking EnableSNMP = false, but this did not change the result.
<code class="language-csharp">using Skyline.DataMiner.Automation;
public class Script
{
public void Run(Engine engine)
{
ScriptDummy dummy = engine.GetDummy("dummy1");
engine.ShowUI(
"Element: " + dummy.ElementName + "\n" +
"IP: " + dummy.PollingIP + "\n" +
"EnableSNMP: " + dummy.ElementInfo.EnableSNMP + "\n" +
"Read Community: [" + dummy.ElementInfo.SnmpReadCommunityString + "]\n" +
"Write Community: [" + dummy.ElementInfo.SnmpWriteCommunityString + "]"
);
}
}</code>
Could you please confirm whether it is possible to retrieve these values from an Automation script?
If so, could you provide an example of how this should be done in C#?
Many thanks,
Romain
Hi Romain,
Yes, this is possible, but not via dummy.ElementInfo.SnmpReadCommunityString / SnmpWriteCommunityString (those often come back empty).
For Automation scripts, the reliable approach is to read the SNMP credentials from the element port configuration (ElementPortInfo) using GetLiteElementInfo and LiteElementInfoEvent:
<code class="font-mono whitespace-pre text-body-small leading-body-small">using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Messages;
using System.Linq;
using System.Text;
public class Script
{
public void Run(Engine engine)
{
ScriptDummy dummy = engine.GetDummy("dummy1");
Element element = engine.FindElement(dummy.ElementName);
var request = new GetLiteElementInfo
{
DataMinerID = element.DmaId,
ElementID = element.ElementId
};
var lite = (LiteElementInfoEvent)Engine.SLNet.SendSingleResponseMessage(request);
var sb = new StringBuilder();
sb.AppendLine("Element: " + dummy.ElementName);
sb.AppendLine("Polling IP (dummy): " + dummy.PollingIP);
foreach (ElementPortInfo port in lite.PortInfo.Where(p => p.ProtocolType.ToString().StartsWith("Snmp")))
{
sb.AppendLine($"Port {port.PortID} ({port.ProtocolType})");
sb.AppendLine($" Get community: [{port.GetCommunity}]");
sb.AppendLine($" Set community: [{port.SetCommunity}]");
}
engine.ShowUI(sb.ToString());
}
}
</code>
If you also need to update the credentials, you can modify port.GetCommunity / port.SetCommunity in lite.PortInfo and send them back with AddElementMessage (same pattern as above).
Kind regards.