Hi,
I'm using Ansible to create elements via the JSON API. I'm having a problem creating a Microsoft Platform element using protocol version 6.0.0.2
If I create the element in Cube, then grab the element config via API, I get
ok: [localhost] => {
"elementConfig.content": {
"d": {
"AlarmTemplate": "",
"CreateDVEs": true,
"Description": "",
"EnableSnmpAgent": false,
"EnableTelnet": false,
"ForceAgent": null,
"IPAddress": "",
"IPAddressMask": "",
"IsHidden": false,
"IsReadOnly": false,
"IsReplicationActive": false,
"KeepOnline": false,
"Name": "Test Win 1",
"Ports": [
{
"DeviceAddress": "",
"ElementTimeoutTime": 30000,
"GetCommunity": "public",
"IPAddress": "192.168.192.246",
"Network": "0",
"PortNumber": 0,
"Retries": 3,
"SNMPVersion": 1,
"SetCommunity": "private",
"TimeoutTime": 60,
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSNMPPortInfo"
},
{
"Baudrate": 0,
"BusAddress": "",
"Databits": 0,
"ElementTimeoutTime": 30000,
"FlowControl": "No",
"IPAddress": "192.168.192.246",
"IPPort": 0,
"LocalIPPort": 0,
"Network": "0",
"Parity": "No",
"Retries": 0,
"SerialPort": "0",
"Stopbits": 0,
"TimeoutTime": 60000,
"Type": "TCP",
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSerialPortInfo"
}
],
"ProtocolName": "Microsoft Platform",
"ProtocolVersion": "6.0.0.2",
"ReplicationInfo": null,
"SlowPoll": null,
"SnmpReadCommunityString": "",
"SnmpWriteCommunityString": "",
"State": "Active",
"TimeoutTime": 30000,
"TrendTemplate": "",
"Type": "Information Platform",
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementConfiguration"
}
}
}
I get an error around the ports config when I try to create the new elements.
The error I get is
fatal: [localhost]: FAILED! => {
"cache_control": "private",
"changed": false,
"connection": "close",
"content": "{\"Message\":\"Invalid port configuration: expected Serial but received SNMP-Serial.\",\"StackTrace\":\"\",\"ExceptionType\":\"Skyline.DataMiner.Web.Common.WebApiException\"}",
"content_length": "162",
"content_type": "application/json; charset=utf-8",
"date": "Wed, 15 Feb 2023 13:37:37 GMT",
"elapsed": 0,
"json": {
"ExceptionType": "Skyline.DataMiner.Web.Common.WebApiException",
"Message": "Invalid port configuration: expected Serial but received SNMP-Serial.",
"StackTrace": ""
},
"jsonerror": "true",
"msg": "Status code was 500 and not [200]: HTTP Error 500: Internal Server Error",
"redirected": false,
"server": "Microsoft-IIS",
"sl_filter": "ALLOWED (single request, by path), time=2023-2-15 13:37:37",
"status": 500,
"url": "http://dm.redlab01.tv/API/v1/json.asmx/CreateElement"
}
My Ansible code is this:
- name: CreateElement
uri:
url: "{{jsonServer }}{{createElement}}"
return_content: yes
use_proxy: false
body_format: json
method: POST
body: '{
"connection": "{{connection.json.d}}",
"dmaID": "{{item.dmaID}}",
"viewIDs": [-1],
"configuration":
{
"Name": "{{item.Name}}",
"ProtocolName": "{{item.Protocol}}",
"ProtocolVersion": "{{item.Protver}}",
"Ports": [
{
"DeviceAddress": "",
"ElementTimeoutTime": 30000,
"GetCommunity": "public",
"IPAddress": "{{item.SNMP_IP}}",
"Network": "0",
"PortNumber": 0,
"Retries": 3,
"SNMPVersion": 1,
"SetCommunity": "private",
"TimeoutTime": 60,
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSNMPPortInfo"
},
{
"Baudrate": 0,
"BusAddress": "",
"Databits": 0,
"ElementTimeoutTime": 30000,
"FlowControl": "No",
"IPAddress": "{{item.IP}}",
"IPPort": 0,
"LocalIPPort": 0,
"Network": "0",
"Parity": "No",
"Retries": 0,
"SerialPort": "0",
"Stopbits": 0,
"TimeoutTime": 60000,
"Type": "TCP",
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSerialPortInfo"
}] }
}'register: createdElementInfo
So, by using the same format as the API spits out, I get the error. I have successfully created elements which feature IP and SNMP (R&S Prismon) with Ansible.
I can't see where this is going wrong. Any ideas greatly appreciated
Thanks
I've managed to get it to work, more by luck than judgement. The following works
- name: CreateElement
uri:
url: "{{jsonServer }}{{createElement}}"
return_content: yes
use_proxy: false
body_format: json
method: POST
body: '{
"connection": "{{connection.json.d}}",
"dmaID": "{{item.dmaID}}",
"viewIDs": [{{item.viewID}}],
"configuration":
{
"Name": "{{item.Name}}",
"ProtocolName": "{{item.Protocol}}",
"ProtocolVersion": "{{item.Protver}}",
"AlarmTemplate": "{{item.alarmTemplate}}",
"TrendTemplate": "{{item.trendTemplate}}",
"Ports": [
{
"DeviceAddress": "",
"ElementTimeoutTime": 30000,
"GetCommunity": "public",
"IPAddress": "{{item.SNMP_IP}}",
"Network": "0",
"PortNumber": 0,
"Retries": 3,
"SNMPVersion": 1,
"SetCommunity": "private",
"TimeoutTime": 60,
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSNMPPortInfo"
},
{
"Baudrate": 0,
"BusAddress": "",
"Databits": 0,
"ElementTimeoutTime": 30000,
"FlowControl": "No",
"IPAddress": "{{item.IP}}",
"IPPort": 0,
"LocalIPPort": 0,
"Network": "0",
"Parity": "No",
"Retries": 0,
"SerialPort": "0",
"Stopbits": 0,
"TimeoutTime": 60000,
"Type": "TCP",
"__type": "Skyline.DataMiner.Web.Common.v1.DMAElementSerialPortInfo"
}
]
}
}'
register: createdElementInfo
I wish I could post code snippets that keep the formatting.
Regarding code formatting, please vote on the feature suggestion below, spread the word, and lets make Skyline aware that pretty formatted code in questions is an important asset for the community.
Thanks for sharing the solution! What exactly fixed it? Including the “AlarmTemplate” and “TrendTemplate” properties?
Hi Wim, unfortunately I have no idea what fixed it!
I got annoyed, left it for a bit, came back to it later and it worked!
We have also seen this issue before, but we didn't investigate the root cause of this yet. It works when sending the JSON directly via Postman to the JSON API of DataMiner, but for some reason it doesn't work in Ansible.
As a workaround it works when using the SOAP API in Ansible. There's an example of this on docs.dataminer.services.
NOTE: The question engine lost all the formatting from the above!