|
| 1 | +--- |
| 2 | +uid: ClassLibraryElementCreation |
| 3 | +--- |
| 4 | + |
| 5 | +# Element creation |
| 6 | + |
| 7 | +This section provides more information on how to create elements using the class library. |
| 8 | + |
| 9 | +To create an element, use the [CreateElement](xref:Skyline.DataMiner.Library.Common.IDma.CreateElement(Skyline.DataMiner.Library.Common.ElementConfiguration)) method of the [IDma](xref:Skyline.DataMiner.Library.Common.IDma) interface. |
| 10 | +This method takes an [ElementConfiguration](xref:Skyline.DataMiner.Library.Common.ElementConfiguration) object as parameter, where you can configure the element settings for the element. |
| 11 | + |
| 12 | +The ElementConfiguration constructors require the element name and the protocol to be specified. |
| 13 | +Other configuration settings can be specified via the properties of the ElementConfiguration object: |
| 14 | + |
| 15 | +- [AdvancedSettings](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.AdvancedSettings): Allows you to configure advanced element settings such as the timeout, whether the element is hidden, etc. |
| 16 | +- [AlarmTemplate](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.AlarmTemplate): Allows you to specify an alarm template to be used. |
| 17 | +- [Connections](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.Connections): Allows you to specify the connections, if any. See [Creating an element with connections](xref:ClassLibraryElementCreation#creating-an-element-with-connections). |
| 18 | +- [Description](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.Description): Allows you to provide a description for the element. |
| 19 | +- [DveSettings](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.DveSettings): Allows you to configure DVE-related settings such as whether DVE creation is enabled or disabled. |
| 20 | +- [Properties](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.Properties): Allows you to configure element properties. See [Creating an element with properties](xref:ClassLibraryElementCreation#creating-an-element-with-properties). |
| 21 | +- [State](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.State): Allows you to configure the state. Must be either Active, Paused or Stopped. |
| 22 | +- [TrendTemplate](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.TrendTemplate): Allows you to specify a trend template to be used. |
| 23 | +- [Type](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.Type): Allows you to specify the type. |
| 24 | +- [Views](xref:Skyline.DataMiner.Library.Common.ElementConfiguration.Views): Allows you to specify the views the created element should be part of. See [Creating an element in specific views](xref:ClassLibraryElementCreation#creating-an-element-in-specific-views). |
| 25 | + |
| 26 | +## Creating an element with properties |
| 27 | + |
| 28 | +The following example illustrates how to create an element with some element properties: |
| 29 | + |
| 30 | +```csharp |
| 31 | +IDms dms = protocol.GetDms(); |
| 32 | +var agent = dms.GetAgent(1000); |
| 33 | + |
| 34 | +IDmsProtocol elementProtocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); |
| 35 | +string elementName = "<ElementName>"; |
| 36 | + |
| 37 | +ElementConfiguration configuration = new ElementConfiguration(dms, elementName, elementProtocol); |
| 38 | +configuration.Properties["Manufacturer"].Value = "<manufacturerValue>"; |
| 39 | +configuration.Properties["Model"].Value = "<modelValue>"; |
| 40 | + |
| 41 | +DmsElementId id = agent.CreateElement(configuration); |
| 42 | +``` |
| 43 | + |
| 44 | +## Creating an element in specific views |
| 45 | + |
| 46 | +The following example illustrates how to create an element that should be included in the specified views: |
| 47 | + |
| 48 | +```csharp |
| 49 | +IDms dms = protocol.GetDms(); |
| 50 | +var agent = dms.GetAgent(1000); |
| 51 | + |
| 52 | +IDmsProtocol elementProtocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); |
| 53 | +string elementName = "<ElementName>"; |
| 54 | + |
| 55 | +ElementConfiguration configuration = new ElementConfiguration(dms, elementName, elementProtocol); |
| 56 | + |
| 57 | +configuration.Views.Add(dms.GetView(7)); |
| 58 | +configuration.Views.Add(dms.GetView(9)); |
| 59 | + |
| 60 | +DmsElementId id = agent.CreateElement(configuration); |
| 61 | +``` |
| 62 | + |
| 63 | +## Creating an element with connections |
| 64 | + |
| 65 | +In version 1.2.0.5 of the class library, support has been added for HTTP connections of elements (virtual and SNMP connections were already supported in previous versions). The following diagram gives an overview of the provided interfaces: |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +### Creating an SNMPv1 element |
| 70 | + |
| 71 | +```csharp |
| 72 | +IDms dms = protocol.GetDms(); |
| 73 | +IDma agent = dms.GetAgent(1000); // Obtain Agent where the element should be created. |
| 74 | +IDmsProtocol protocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); // Specify the protocol the element will run. |
| 75 | +
|
| 76 | +IUdp port = new Udp("127.0.0.1", 161); // Configure the SNMP connection. |
| 77 | +
|
| 78 | +ISnmpV1Connection mySnmpV1Connection = new SnmpV1Connection(port); |
| 79 | + |
| 80 | +ElementConfiguration configuration = new ElementConfiguration(dms, "<ElementName>", protocol, new List<IElementConnection> { mySnmpV1Connection }); |
| 81 | + |
| 82 | +DmsElementId id = agent.CreateElement(configuration); |
| 83 | +``` |
| 84 | + |
| 85 | +### Creating an SNMPv2c element |
| 86 | + |
| 87 | +```csharp |
| 88 | +IDms dms = protocol.GetDms(); |
| 89 | +IDma agent = dms.GetAgent(1000); // Obtain Agent where the element should be created. |
| 90 | +IDmsProtocol protocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); // Specify the protocol |
| 91 | +IUdp port = new Udp("127.0.0.1", 161); |
| 92 | + |
| 93 | +ISnmpV2Connection mySnmpV2Connection = new SnmpV2Connection(port); |
| 94 | + |
| 95 | +ElementConfiguration configuration = new ElementConfiguration(dms, "<ElementName>", protocol, new List<IElementConnection> { mySnmpV2Connection }); |
| 96 | + |
| 97 | +DmsElementId id = agent.CreateElement(configuration); |
| 98 | +``` |
| 99 | + |
| 100 | +### Creating an SNMPv3 element |
| 101 | + |
| 102 | +```csharp |
| 103 | +IDms dms = protocol.GetDms(); |
| 104 | +IDma agent = dms.GetAgent(1000); // Obtain Agent where the element should be created. |
| 105 | +IDmsProtocol protocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); |
| 106 | +IUdp port = new Udp("127.0.0.1", 161); |
| 107 | + |
| 108 | +SnmpV3SecurityConfig secConfig = new SnmpV3SecurityConfig("myUserName", "myAuthKey", SnmpV3AuthenticationAlgorithm.Md5, "myEncryptionKey", SnmpV3EncryptionAlgorithm.Aes128); |
| 109 | +ISnmpV3Connection mySnmpV3Connection = new SnmpV3Connection(port, secConfig); |
| 110 | + |
| 111 | +ElementConfiguration configuration = new ElementConfiguration(dms, randomizedElementName, protocol, new List<IElementConnection> { mySnmpV3Connection }); |
| 112 | + |
| 113 | +DmsElementId id = agent.CreateElement(configuration); |
| 114 | +``` |
| 115 | + |
| 116 | +### Creating an HTTP element |
| 117 | + |
| 118 | +The following example illustrates how to create an element with an HTTP connection: |
| 119 | + |
| 120 | +```csharp |
| 121 | +private static void CreateElement(SLProtocol protocol) |
| 122 | +{ |
| 123 | + IDms dms = protocol.GetDms(); |
| 124 | + IDma agent = dms.GetAgent(protocol.DataMinerID); |
| 125 | + |
| 126 | + IDmsProtocol elementProtocol = dms.GetProtocol("<ProtocolName>", "1.0.0.1"); |
| 127 | + |
| 128 | + ITcp port = new Tcp("127.0.0.1", 8888); |
| 129 | + IHttpConnection myHttpConnection = new HttpConnection(port); |
| 130 | + |
| 131 | + var configuration = new ElementConfiguration( |
| 132 | + dms, |
| 133 | + "<ElementName>", |
| 134 | + elementProtocol, |
| 135 | + new List<IElementConnection> { myHttpConnection }); |
| 136 | + |
| 137 | + DmsElementId createdElementId = agent.CreateElement(configuration); |
| 138 | +} |
| 139 | +``` |
0 commit comments