Different responses for Query

122 views Asked by At

I do have a RestAPI call which is going to list all servers defined in our environment. Because of different use cases the RestAPI call will not always return the same amount of attributes.

Response 1:

[
  {
    "OperatingSystem": "Windows Server 2019 Datacenter Microsoft Windows NT 10.0.17763.0",
    "ManagedBy": "Team1",
    "Category": "Cloud",
    "Phase": "prd",
    "Size": "Standard_B4ms",
    "LastSeen": "2021-03-28T14:44:05.898Z[UTC]",
    "Created": "2021-03-08T10:00:58Z",
    "Name": "Servername1",
    "LastModified": "2021-03-28T14:44:05.898Z[UTC]",
    "Item": "VirtualMachine",
    "SupportedBy": "Team2",
    "AssetID": "188a44a12ab6bfe3eca809792b9833c3",
    "AssetLifecycleStatus": "Deployed",
    "Tags": "{xxx.com.automation.application=DBServer, xxx.com.automation.application-phase=prd, xxx.com.automation.infrastructure-environment=prd, xxx.com.cmdb.managed-by=team3, xxx.com.cmdb.operated-by=team4, xxx.com.cmdb.owned-by=team1, xxx.com.cmdb.sre.lifecycle-status=Deployed, xxx.com.cmdb.sre.status-reason=In Production, xxx.com.cmdb.supported-by=team2}",
    "Status": "Deployed",
    "InstanceId": "FE-951f27b59b836aff12dc6893a4c1dfaf",
    "StatusReason": "In Production",
    "OwnedBy": "team3",
    "isValid": false,
    "Hostname": "server1",
    "LastSync": "2021-03-08T10:00:58Z",
    "Type": "Infrastructure",
    "IaasId": "c1a3f42d-cb09-446a-9339-a2aacbd290ff",
    "OperatedBy": "team2",
    "Application": "DBServer"
  }
]

Response 2:

[
  {
    "ManagedBy": "Team1",
    "Category": "Cloud",
    "InstanceId": "OI-a3086dcaa67d4b04869de7522495e96f",
    "StatusReason": "In Production",
    "OwnedBy": "Team2",
    "LastSync": "2020-12-03T21:27Z",
    "Name": "server2",
    "LastModified": "2020-12-03T21:27Z",
    "Item": "VirtualMachine",
    "Type": "Infrastructure",
    "OperatedBy": "team3",
    "SupportedBy": "team4",
    "AssetLifecycleStatus": "Deployed"
  }
]

Response 3:

[
  {
    "OperatingSystem": "null null",
    "Category": "Cloud",
    "InstanceId": "FE-3778140b61308de34f921d99aa1a15df",
    "Size": "Standard_DS1_v2",
    "isValid": false,
    "Hostname": "server3",
    "LastSeen": "2021-03-28T14:44:03.028Z[UTC]",
    "Created": "2021-03-08T09:46:52.890Z[UTC]",
    "Name": "server3",
    "LastModified": "2021-03-28T14:44:03.028Z[UTC]",
    "Item": "VirtualMachine",
    "Type": "Infrastructure",
    "IaasId": "639d781e-828a-4d3f-84fb-dd1c6ca8494d",
    "AssetID": "b315bb55136fc36d02e2b37be3c9869f",
    "Tags": "{owner=name1, poc=name2}"
  }
]

Response 4:

[
  {
    "OperatingSystem": "null null",
    "Category": "Cloud",
    "InstanceId": "FE-3778140b61308de34f921d99aa1a15df",
    "Size": "Standard_DS1_v2",
    "isValid": false,
    "Hostname": "server 4",
    "LastSeen": "2021-03-28T14:44:03.028Z[UTC]",
    "Created": "2021-03-08T09:46:52.890Z[UTC]",
    "Name": "server4",
    "LastModified": "2021-03-28T14:44:03.028Z[UTC]",
    "Item": "VirtualMachine",
    "Type": "Infrastructure",
    "IaasId": "639d781e-828a-4d3f-84fb-dd1c6ca8494d",
    "AssetID": "b315bb55136fc36d02e2b37be3c9869f",
    "Tags": "{}"
  }
]

The problem I am facing now is that now all values are going to be returned every time. Therefore I need a method to declare which one I expect to be present all time.

I have tried the * match contains but without success

How can I do this?

0

There are 0 answers