{
"Instances": [
{
"Name": "DataMiner Main",
"IPAddress": "70.10.10.1",
"Id": 74947982479,
"CreatedFromTemplate": false,
"Status": "ACTIVE"
},
{
"Name": "DataMiner Backup",
"IPAddress": "10.10.10.2",
"Id": 76428745692,
"CreatedFromTemplate": true,
"Status": "STANDBY"
}
]
}
this is the data i want to get in table and that's what i am getting
mentioning the csharp code as well
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Newtonsoft.Json;
using Skyline.DataMiner.Scripting;
public static class Parameter
{
public static class Instances
{
public const int tablePid = 300; // Replace with the correct table PID
}
}
/// <summary>
/// DataMiner QAction Class: parse data.
/// </summary>
public static class QAction
{
/// <summary>
/// The QAction entry point.
/// </summary>
/// <param name="protocol">Link with SLProtocol process.</param>
public static void Run(SLProtocol protocol)
{
try
{
// Get Text based json data as a string.
string source = Convert.ToString(protocol.GetParameter(200));
// Deserialize Json contents
Rootobject rootObjects = JsonConvert.DeserializeObject<Rootobject>(source);
List<object[]> instances = new List<object[]>();
// Convert Generated class into Connector Row data.
foreach (Instance instance in rootObjects.Instances)
{
instances.Add(new InstancesQActionRow
{
Instancesid_301 = instance.Id,
Instancesname_302 = instance.Name,
Instancesipaddress_303 = instance.IPAddress,
Instancescreatedfromtemplate_304 = instance.CreatedFromTemplate,
InstancesStatus_305 = instance.Status,
}.ToObjectArray());
}
protocol.FillArray(Parameter.Instances.tablePid, instances, NotifyProtocol.SaveOption.Full);
}
catch (Exception ex)
{
protocol.Log("QA" + protocol.QActionID + "|" + protocol.GetTriggerParameter() + "|Run|Deserializing JSON text failed due to:" + Environment.NewLine + ex, LogType.Error, LogLevel.NoLogging);
}
}
}
public class Rootobject
{
public Instance[] Instances { get; set; }
}
public class Instance
{
public string Name { get; set; }
public string IPAddress { get; set; }
public long Id { get; set; }
public bool CreatedFromTemplate { get; set; }
public string Status { get; set; }
}
public class InstancesQActionRow
{
public long Instancesid_301 { get; set; }
public string Instancesname_302 { get; set; }
public string Instancesipaddress_303 { get; set; }
public bool Instancescreatedfromtemplate_304 { get; set; }
public string InstancesStatus_305 { get; set; }
// Convert the properties to an object array for table insertion
public object[] ToObjectArray()
{
return new object[]
{
Instancesid_301,
Instancesname_302,
Instancesipaddress_303,
Instancescreatedfromtemplate_304,
InstancesStatus_305,
};
}
}
so what mistakes i m doing and how to fix that and appreciable if get content for improvement this process.
Hi Chirangee,
Could you share your parameter definition with us in the protocol.xml file?
I would guess you have them all defined as double/numeric types while for some of your data, you would need to define them as type string.
As I suspected you have some definitions incompatible with your data.
You can reference this docs page for help https://docs.dataminer.services/develop/schemadoc/Protocol/Protocol.Params.Param.Measurement.html
But for your specific use case:
Instanceid
You should change your interprete to be RawType other and Type string
Then in the QAction you should define the primary key as a string as well
In your parameters Instancesname, Instancesname and data table nameStatus
RawType other
Type string
For the status and Instancescreatedfromtemplate you could consider using type discreet (see more https://docs.dataminer.services/develop/schemadoc/Protocol/Protocol.Params.Param.Measurement.Discreets.html)