python merge two lists of dictionaries based on matching key - python-3.x

I have the following two data sets, and I'm looking to merge them in a very specific way:
Stream
stream = {
"sdd": [{
"eid": "e532fcdb-2f3f-4c51-9afb-996b8679a5da",
"nid": "ebef3cb1-9053-4d1e-b409-b682236445b7",
"nname": "client"
}, {
"eid": "901b51b1-851f-448e-b2cc-9730267f824b",
"nid": "0b5d79b5-0d21-4186-b3db-8f4a9f2b25fb",
"nname": "server"
}]
}
Profile
profile = [{
"ackid": "5dfe5dd4-e863-4474-bdad-54231b925f12",
"nid": "ebef3cb1-9053-4d1e-b409-b682236445b7",
"name": "default",
"resources": {
"cpu": {
"min_cores": "2",
"max_cores": "8"
},
"memory": {
"min": "2000",
"max": "10000"
},
"storage": {
"min": "50",
"max": "100"
}
}
}]
What I want to do is add to 'stream' from 'profile' the matching (min) values from 'resources' where both 'nid' match to get something like this:
Output
{
"sdd": [{
"eid": "e532fcdb-2f3f-4c51-9afb-996b8679a5da",
"nid": "ebef3cb1-9053-4d1e-b409-b682236445b7",
"nname": "client",
"cpu": "2",
"mem": "2000",
"storage":"50"
}, {
"eid": "901b51b1-851f-448e-b2cc-9730267f824b",
"nid": "0b5d79b5-0d21-4186-b3db-8f4a9f2b25fb",
"nname": "server"
}]
}

def get_dict(x):
return {'min':x['memory']['min'], 'cpu':x['cpu']['min_cores'],
'storage':x['storage']['min']}
Out = {'ssd':[i|get_dict(j['resources']) if i['nid']==j['nid'] else i for i in
stream['sdd'] for j in profile]}
Out:
{'ssd': [{'eid': 'e532fcdb-2f3f-4c51-9afb-996b8679a5da',
'nid': 'ebef3cb1-9053-4d1e-b409-b682236445b7',
'nname': 'client',
'min': '2000',
'cpu': '2',
'storage': '50'},
{'eid': '901b51b1-851f-448e-b2cc-9730267f824b',
'nid': '0b5d79b5-0d21-4186-b3db-8f4a9f2b25fb',
'nname': 'server'}]}

Try:
tmp = {}
for p in profile:
tmp[p["nid"]] = {
"cpu": p["resources"]["cpu"]["min_cores"],
"memory": p["resources"]["memory"]["min"],
"storage": p["resources"]["storage"]["min"],
}
out = {}
for k, v in stream.items():
out[k] = [{**i, **tmp.get(i["nid"], {})} for i in v]
print(out)
Prints:
{
"sdd": [
{
"eid": "e532fcdb-2f3f-4c51-9afb-996b8679a5da",
"nid": "ebef3cb1-9053-4d1e-b409-b682236445b7",
"nname": "client",
"cpu": "2",
"memory": "2000",
"storage": "50",
},
{
"eid": "901b51b1-851f-448e-b2cc-9730267f824b",
"nid": "0b5d79b5-0d21-4186-b3db-8f4a9f2b25fb",
"nname": "server",
},
]
}

Related

Loop and array within and array within an array to get list of variables

Need to get a list of all accounts by section and the net total of the debit and credit values.  For example:
Section:Revenue
ACC Income: $10,000
Other Income: $5,000
Section Expenses
Advertising: 100
Rent: 20,000
I have used a for...in loop but only get down to the object of the array.  I know I need to loop within a loop but I don't know how to.  Have been trying for 2wks now and still only get down to the Section, not the accounts and values.
{
"cashtb": {
"response": {
"statusCode": 200,
"body": {
"reports": [
{
"reportID": "TrialBalance",
"reportName": "Trial Balance",
"reportType": "TrialBalance",
"reportTitles": [
"Trial Balance",
"Test Org",
"As at 1 July 2022"
],
"reportDate": "27 September 2022",
"rows": [
{
"rowType": "Header",
"cells": [
{
"value": "Account"
},
{
"value": "Debit"
},
{
"value": "Credit"
},
{
"value": "YTD Debit"
},
{
"value": "YTD Credit"
}
]
},
{
"rowType": "Section",
"title": "Revenue",
"rows": [
{
"rowType": "Row",
"cells": [
{
"value": "ACC Income (191)",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "0.00",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
},
{
"value": "13456.25",
"attributes": [
{
"id": "account",
"value": 09dcab5a-152e-4fc2-a983-b80473b4c9f5"
}
]
}
]
},
{
"rowType": "Row",
"cells": [
{
"value": "Eftpos Surcharge Income (193)",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "82.61",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
},
{
"value": "3304.29",
"attributes": [
{
"id": "account",
"value": 9bb9b698-1ced-4ae1-9c29-40f372df2be0"
}
]
}
]
},
{
"rowType": "Row",
"cells": [
{
"value": "Subcontractor Income (192)",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "1086.96",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
},
{
"value": "10088.15",
"attributes": [
{
"id": "account",
"value": e5f36c13-097b-4a01-857a-8400d62ad02d"
}
]
}
]
}
]
},
{
"rowType": "Section",
"title": "Expenses",
"rows": [
{
"rowType": "Row",
"cells": [
{
"value": "Advertising (301)",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "0.00",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "1968.40",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
},
{
"value": "",
"attributes": [
{
"id": "account",
"value": e157460d-76f1-4b34-ac21-b29a9cb446ad"
}
]
}
]
}]}]}]}}}}
I used this code but it only goes to sectione and returns row heading but not the values in the object like account or debit/credit values
let cellstrip = cashtbarray.Reports[0].Rows;
for(let i=0, len=cellstrip.length; i<len; i++){
for (let valuestrip in cellstrip[i]){
console.log(valuestrip, cellstrip[i]
[valuestrip]);
}
}
//you can put another loop in here that starts with
“j” - e.g.
for(let j=0, len=valuestrip.length; j<len; j++){
for (let accountsstrip in valuestrip.Rows[0].Cells[cashtbarray.Reports[0].Rows[k]
.Rows[l].Cells.length - 3].Value !== ''){
//Do something which each value
var accountvalue = accountsstrip;
console.log(accountvalue);
}
}

How to format grafana Alert on teams via webhooks

when the alert is sent to my team’s channel, the pipeline name is truncated [see image below]
alert on teams triggerd on grafana
I would like to know if there is anything I can do to make the entire variable name appear
I’m using grafana v7.5 and my data comes from Azure logs
{
"firing": true,
"state": "pending",
"conditionEvals": "true = true",
"timeMs": "430.287ms",
"matches": [
{
"metric": "n {PipelineName=PPLCRGLOADORLTOAPOSENTEVT}",
"value": 11
}
],
"logs": [
{
"message": "Condition[0]: Query",
"data": {
"from":number,
"queries": [
{
"refId": "A",
"model": {
"appInsights": {
"dimension": [],
"metricName": "select",
"timeGrain": "auto"
},
"azureLogAnalytics": {
"query": "ADFActivityRun\r\n| where (Status == 'Failed') and (substring(ResourceId,135,3) == 'PRD') and TimeGenerated > ago(8h)\r\n| summarize n=count() by bin(TimeGenerated, 5min),PipelineName\r\n\r\n| project n,TimeGenerated,PipelineName",
"resultFormat": "time_series",
"workspace": "workspace"
},
"azureMonitor": {
"aggOptions": [],
"dimensionFilter": "*",
"dimensionFilters": [],
"metricDefinition": "select",
"metricName": "select",
"metricNamespace": "select",
"resourceGroup": "select",
"resourceName": "select",
"timeGrain": "auto",
"timeGrains": [],
"top": "10"
},
"insightsAnalytics": {
"query": "",
"resultFormat": "time_series"
},
"queryType": "Azure Log Analytics",
"refId": "A",
"subscription": "subscription"
},
"datasource": {
"id": 3,
"name": "LA-DATAANALYTICS-PRD"
},
"maxDataPoints": 0,
"intervalMs": 0
}
],
"to": #number
}
},
{
"message": "Condition[0]: Query Result",
"data": {
"fromDataframe": true,
"series": [
{
"name": "n {PipelineName=PPLCRGLOADORLTOAPOSENTEVT}",
"points": [
[
1,
1628064600000
],
[
1,
1628064900000
],
[
1,
1628065200000
],
[
1,
1628065500000
],
[
1,
1628065800000
],
[
1,
1628066100000
],
[
1,
1628066700000
],
[
1,
1628067000000
],
[
1,
1628067300000
],
[
1,
1628067600000
],
[
2,
1628067900000
]
],
"tags": {
"PipelineName": "PPLCRGLOADORLTOAPOSENTEVT"
}
}
]
}
},
{
"message": "Condition[0]: Eval: true, Metric: n {PipelineName=PPLCRGLOADORLTOAPOSENTEVT}, Value: 11.000",
"data": null
}
]
}
Here is the JSON generated by test rule
And the length of pipeline name is something like 25 chars
(PPLCRGLOADORLTOAPOSENTEVT)

How to JOIN into a array inside another array using CosmosDB SQL API?

I have created a sample doc in order to show my issue:
{
"brand": "foobar",
"sellPrice": {
"salesMarkets": [
{
"salesMarket": "DK",
"channels": [
{
"channelId": 1,
"channelName": "Store",
"priceValue": 80,
"currencyISOCode": "DKK"
},
{
"channelId": 2,
"channelName": "Online",
"priceValue": 80,
"currencyISOCode": "DKK"
}
]
},
{
"salesMarket": "SE",
"channels": [
{
"channelId": 1,
"channelName": "Store",
"priceValue": 100,
"currencyISOCode": "SEK"
},
{
"channelId": 2,
"channelName": "Online",
"priceValue": 100,
"currencyISOCode": "SEK"
}
]
}
]
},
"id": "6e9b825d-9154-4bef-b52b-2badb46b3c53"
}
my query looks like follows
SELECT c.brand, sm.salesMarket, ch.channelName
FROM c
JOIN sm IN c.sellPrice.salesMarkets
JOIN ch IN c.sellPrice.salesMarkets.channels
WHERE c.brand = 'foobar'
I expected the output to be as follows:
[
{
"brand": "foobar",
"salesMarket": "DK",
"channels": [
{
"channelName": "Store"
},
{
"channelName": "Online"
}
]
},
{
"brand": "foobar",
"salesMarket": "SE",
"channels": [
{
"channelName": "Store"
},
{
"channelName": "Online",
}
]
}
]
I just cannot figure out how to make the second join do what I need. The first join works as expected but as soon as I add the second one I get 0 results
I'm not sure if you can accept this result.
SELECT c.brand, sm.salesMarket,sm.channels FROM c
JOIN sm IN c.sellPrice.salesMarkets
where c.brand='foobar'
[
{
"brand": "foobar",
"salesMarket": "DK",
"channels": [
{
"channelId": 1,
"channelName": "Store",
"priceValue": 80,
"currencyISOCode": "DKK"
},
{
"channelId": 2,
"channelName": "Online",
"priceValue": 80,
"currencyISOCode": "DKK"
}
]
},
{
"brand": "foobar",
"salesMarket": "SE",
"channels": [
{
"channelId": 1,
"channelName": "Store",
"priceValue": 100,
"currencyISOCode": "SEK"
},
{
"channelId": 2,
"channelName": "Online",
"priceValue": 100,
"currencyISOCode": "SEK"
}
]
}
]

Hyperledger Fabric: Add new organization to existing channel using JsonPath

I want to add a new Organization to an existing Channel in Hyperledger Fabric.
First I obtain the channel configuration in JSON format using the following code snippet:
byte[] configBytes = channel.getChannelConfigurationBytes();
String configtxlator = props.getProperty("configtxlator");
HttpPost httppost = new HttpPost(configtxlator + "/protolator/decode/common.Config");
httppost.setEntity(new ByteArrayEntity(configBytes));
HttpClient httpclient = HttpClients.createDefault();
HttpResponse response = httpclient.execute(httppost);
int statuscode = response.getStatusLine().getStatusCode();
if (statuscode == 200) {
return EntityUtils.toString(response.getEntity());
} else {
return "";
}
The result is the following JSON string:
{
"channel_group": {
"groups": {
"Application": {
"groups": {
"Org1MSP": {
"groups": {},
"mod_policy": "Admins",
"policies": {
"Admins": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "ADMIN"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
}
]
}
},
"version": 0
}
},
"version": "0"
},
"Readers": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "ADMIN"
},
"principal_classification": "ROLE"
},
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "PEER"
},
"principal_classification": "ROLE"
},
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "CLIENT"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
},
{
"signed_by": 1
},
{
"signed_by": 2
}
]
}
},
"version": 0
}
},
"version": "0"
},
"Writers": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "ADMIN"
},
"principal_classification": "ROLE"
},
{
"principal": {
"msp_identifier": "Org1MSP",
"role": "CLIENT"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
},
{
"signed_by": 1
}
]
}
},
"version": 0
}
},
"version": "0"
}
},
"values": {
"AnchorPeers": {
"mod_policy": "Admins",
"value": {
"anchor_peers": [
{
"host": "peer1.org1.isprint.com",
"port": 7051
},
{
"host": "peer2.org1.isprint.com",
"port": 7051
}
]
},
"version": "0"
},
"MSP": {
"mod_policy": "Admins",
"value": {
"config": {
"admins": [],
"crypto_config": {
"identity_identifier_hash_function": "SHA256",
"signature_hash_family": "SHA2"
},
"fabric_node_ous": {
"admin_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "admin"
},
"client_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "client"
},
"enable": true,
"orderer_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "orderer"
},
"peer_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "peer"
}
},
"intermediate_certs": [],
"name": "Org1MSP",
"organizational_unit_identifiers": [],
"revocation_list": [],
"root_certs": [
"..."
],
"signing_identity": null,
"tls_intermediate_certs": [],
"tls_root_certs": [
"..."
]
},
"type": 0
},
"version": "0"
}
},
"version": "1"
}
},
"mod_policy": "Admins",
"policies": {
"Admins": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "MAJORITY",
"sub_policy": "Admins"
}
},
"version": "0"
},
"Readers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Readers"
}
},
"version": "0"
},
"Writers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Writers"
}
},
"version": "0"
}
},
"values": {
"Capabilities": {
"mod_policy": "Admins",
"value": {
"capabilities": {
"V1_4_2": {}
}
},
"version": "0"
}
},
"version": "1"
},
"Orderer": {
"groups": {
"OrdererOrg": {
"groups": {},
"mod_policy": "Admins",
"policies": {
"Admins": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "OrdererMSP",
"role": "ADMIN"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
}
]
}
},
"version": 0
}
},
"version": "0"
},
"Readers": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "OrdererMSP",
"role": "MEMBER"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
}
]
}
},
"version": 0
}
},
"version": "0"
},
"Writers": {
"mod_policy": "Admins",
"policy": {
"type": 1,
"value": {
"identities": [
{
"principal": {
"msp_identifier": "OrdererMSP",
"role": "MEMBER"
},
"principal_classification": "ROLE"
}
],
"rule": {
"n_out_of": {
"n": 1,
"rules": [
{
"signed_by": 0
}
]
}
},
"version": 0
}
},
"version": "0"
}
},
"values": {
"MSP": {
"mod_policy": "Admins",
"value": {
"config": {
"admins": [],
"crypto_config": {
"identity_identifier_hash_function": "SHA256",
"signature_hash_family": "SHA2"
},
"fabric_node_ous": {
"admin_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "admin"
},
"client_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "client"
},
"enable": true,
"orderer_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "orderer"
},
"peer_ou_identifier": {
"certificate": "...",
"organizational_unit_identifier": "peer"
}
},
"intermediate_certs": [],
"name": "OrdererMSP",
"organizational_unit_identifiers": [],
"revocation_list": [],
"root_certs": [
"..."
],
"signing_identity": null,
"tls_intermediate_certs": [],
"tls_root_certs": [
"..."
]
},
"type": 0
},
"version": "0"
}
},
"version": "0"
}
},
"mod_policy": "Admins",
"policies": {
"Admins": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "MAJORITY",
"sub_policy": "Admins"
}
},
"version": "0"
},
"BlockValidation": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Writers"
}
},
"version": "0"
},
"Readers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Readers"
}
},
"version": "0"
},
"Writers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Writers"
}
},
"version": "0"
}
},
"values": {
"BatchSize": {
"mod_policy": "Admins",
"value": {
"absolute_max_bytes": 103809024,
"max_message_count": 100,
"preferred_max_bytes": 524288
},
"version": "0"
},
"BatchTimeout": {
"mod_policy": "Admins",
"value": {
"timeout": "30s"
},
"version": "0"
},
"Capabilities": {
"mod_policy": "Admins",
"value": {
"capabilities": {
"V1_4_2": {}
}
},
"version": "0"
},
"ChannelRestrictions": {
"mod_policy": "Admins",
"value": null,
"version": "0"
},
"ConsensusType": {
"mod_policy": "Admins",
"value": {
"metadata": {
"consenters": [
{
"client_tls_cert": "...",
"host": "orderer1.isprint.com",
"port": 7050,
"server_tls_cert": "..."
},
{
"client_tls_cert": "...",
"host": "orderer2.isprint.com",
"port": 7050,
"server_tls_cert": "..."
},
{
"client_tls_cert": "...",
"host": "orderer3.isprint.com",
"port": 7050,
"server_tls_cert": "..."
}
],
"options": {
"election_tick": 10,
"heartbeat_tick": 1,
"max_inflight_blocks": 5,
"snapshot_interval_size": 20971520,
"tick_interval": "500ms"
}
},
"state": "STATE_NORMAL",
"type": "etcdraft"
},
"version": "0"
}
},
"version": "0"
}
},
"mod_policy": "Admins",
"policies": {
"Admins": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "MAJORITY",
"sub_policy": "Admins"
}
},
"version": "0"
},
"Readers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Readers"
}
},
"version": "0"
},
"Writers": {
"mod_policy": "Admins",
"policy": {
"type": 3,
"value": {
"rule": "ANY",
"sub_policy": "Writers"
}
},
"version": "0"
}
},
"values": {
"BlockDataHashingStructure": {
"mod_policy": "Admins",
"value": {
"width": 4294967295
},
"version": "0"
},
"Capabilities": {
"mod_policy": "Admins",
"value": {
"capabilities": {
"V1_4_3": {}
}
},
"version": "0"
},
"Consortium": {
"mod_policy": "Admins",
"value": {
"name": "SampleConsortium"
},
"version": "0"
},
"HashingAlgorithm": {
"mod_policy": "Admins",
"value": {
"name": "SHA256"
},
"version": "0"
},
"OrdererAddresses": {
"mod_policy": "/Channel/Orderer/Admins",
"value": {
"addresses": [
"orderer1.isprint.com:7050",
"orderer2.isprint.com:7050",
"orderer3.isprint.com:7050"
]
},
"version": "0"
}
},
"version": "0"
},
"sequence": "2"
}
I have written a code snippet using JsonPath:
DocumentContext context = JsonPath.parse(json);
String pathOrg1MSP = "$.channel_group.groups.Application.groups.Org1MSP";
Map<String,Object> mapOrg1MSP = context.read(pathOrg1MSP);
Map<String,Object> mapOrg2MSP = new LinkedHashMap<String,Object>();
mapOrg1MSP.forEach((k,v) -> {
mapOrg2MSP.put(k, v);
});
String pathOrg2MSP = "$.channel_group.groups.Application.groups";
context.put(pathOrg2MSP, "Org2MSP", mapOrg2MSP);
The intention is to create an exact clone first, then change whatever values need to be changed (peers, certs etc), and then splice it into the original Json.
Would this achieve what I intend to do?
What values would I need to change to prevent any possible conflicts with existing organizations?
Generate crypto materials for Org2
Generate Org2-specific configuration materials
Fetch the latest config block from orderer, trim it down and convert it to JSON (I believe u have done this step already)
Add Org2-specific configuration materials to the JSON
Convert original JSON and newly edited JSON to protobuf format
Compute difference between the new and original block (.pb files)
Convert it to JSON format and add back header
Convert it to protobuf format
Sign transaction by Org1
For the detailed commands, you can refer to this official documentation. https://hyperledger-fabric.readthedocs.io/en/release-1.4/channel_update_tutorial.html

Copyindex in deploying dashboard resources Azure ARM

I am deploying a custom Azure Dashboard with a tile that makes use of a resource.
To call the resource I use following code
"[resourceId(parameters('analysisServiceResourceGroup'), '/Microsoft.AnalysisServices/servers', parameters('analysisServiceName'))]"
But in one of the tiles I need multiple resources so I tried something out to make a parameter file with following value
"analysisService": {
"value": [
{
"ResourceGroup": "RG",
"Name": "analysis1",
"Color": "#47BDF5"
},
{
"ResourceGroup": "RG",
"Name": "analysis2",
"Color": "#7E58FF"
},
{
"ResourceGroup": "RG",
"Name": "analysis3",
"Color": "#EB9371"
}
]
},
In my dashboard template i use following code to get the name and resource group.
"resourceId": "[resourceId(parameters('analysisService')[copyIndex()].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex()].Name)]"
The problem I got at the moment my copy object is not placed in the right place. I got this error
'The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details.'"
This says that my copy index block is not used in the right resource bracelet but I don't know where i can place this copy Index , tried to put this in every possible place where the copy index can access this but nothing works does anyone know what I do wrong or what I do wrong. It may be possible that copyindex doesn't work inside a dashboard resource.
Code
"12": {
"position": {
"x": 12,
"y": 9,
"colSpan": 6,
"rowSpan": 4
},
"metadata": {
"inputs": [
{
"name": "sharedTimeRange",
"isOptional": true
},
{
"name": "options",
"value": {
"charts": [
{
"metrics": [
{
"name": "CurrentUserSessions",
"resourceMetadata": {
"resourceId": "[resourceId(parameters('analysisService')[copyIndex()].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex()].Name)]"
},
"aggregationType": 1,
"copy": {
"name": "AnalysisServiceCopy",
"count": "[length(parameters('analysisService'))]"
},
}
],
"title": "Avg Current User Sessions for analysis1, analysis1, and analysis1",
"visualization": {
"chartType": 2,
"legend": {
"isVisible": true,
"position": 2,
"hideSubtitle": false
},
"axis": {
"x": {
"isVisible": true,
"axisType": 2,
"min": 1546508634047,
"max": 1546595034047
},
"y": {
"isVisible": true,
"axisType": 1
}
},
"timeBrushEnable": false
},
"itemDataModel": {
"id": "3464BA29-9AF2-4EAE-9CF4-A246059DDF46",
"chartHeight": 1,
"metrics": [
{
"id": {
"resourceDefinition": {
"id": "[resourceId(parameters('analysisService')[copyIndex()].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex()].Name)]"
},
"name": {
"id": "CurrentUserSessions",
"displayName": "Current User Sessions"
},
"namespace": {
"name": "microsoft.analysisservices/servers"
}
},
"metricAggregation": 4,
"color": "[parameters('analysisService')[copyIndex()].Color]"
,
"copy": {
"name": "AnalysisServiceCopy",
"count": "[length(parameters('analysisService'))]"
},
}
],
"priorPeriod": false,
"horizontalBars": true,
"showOther": false,
"aggregation": 1,
"palette": "multiColor",
"jsonDefinitionId": "59DCE403-7D8D-4E9F-9CDA-7AE7AC9D9220",
"version": {
"major": 1,
"minor": 0,
"build": 0
},
"filters": {
"filterType": 0,
"id": "C81486BB-3934-48C7-9251-A4EE633DB2BB",
"OperandFilters": [],
"LogicalOperator": 0
},
"yAxisOptions": {
"options": 1
},
"title": "Avg Current User Sessions for analysis1, analysis1, and analysis1",
"titleKind": "Auto",
"visualization": {
"chartType": 2,
"legend": {
"isVisible": true,
"position": 2,
"hideSubtitle": false
},
"axis": {
"x": {
"isVisible": true,
"axisType": 2,
"min": 1546508634047,
"max": 1546595034047
},
"y": {
"isVisible": true,
"axisType": 1
}
},
"timeBrushEnable": false
}
}
}
],
"v2charts": true,
"version": 1
},
"isOptional": true
}
],
"type": "Extension/HubsExtension/PartType/MonitorChartPart",
"settings": {
"content": {
"options": {
"charts": [
{
"metrics": [
{
"name": "CurrentUserSessions",
"resourceMetadata": {
"resourceId": "[resourceId(parameters('analysisService')[copyIndex()].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex()].Name)]"
},
"aggregationType": 1
,
"copy": {
"name": "AnalysisServiceCopy",
"count": "[length(parameters('analysisService'))]"
},
}
],
"title": "Avg Current User Sessions for analysis1, analysis1, and analysis1",
"visualization": {
"chartType": 2,
"legend": {
"isVisible": true,
"position": 2,
"hideSubtitle": false
},
"axis": {
"x": {
"isVisible": true,
"axisType": 2,
"min": 1546508634047,
"max": 1546595034047
},
"y": {
"isVisible": true,
"axisType": 1
}
},
"timeBrushEnable": false
},
"itemDataModel": {
"id": "3464BA29-9AF2-4EAE-9CF4-A246059DDF46",
"chartHeight": 1,
"metrics": [
{
"id": {
"resourceDefinition": {
"id": "[resourceId(parameters('analysisService')[copyIndex()].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex()].Name)]"
},
"name": {
"id": "CurrentUserSessions",
"displayName": "Current User Sessions"
},
"namespace": {
"name": "microsoft.analysisservices/servers"
}
},
"metricAggregation": 4,
"color": "[parameters('analysisService')[copyIndex()].Color]"
,
"copy": {
"name": "AnalysisServiceCopy",
"count": "[length(parameters('analysisService'))]"
},
}
],
"priorPeriod": false,
"horizontalBars": true,
"showOther": false,
"aggregation": 1,
"palette": "multiColor",
"jsonDefinitionId": "59DCE403-7D8D-4E9F-9CDA-7AE7AC9D9220",
"version": {
"major": 1,
"minor": 0,
"build": 0
},
"filters": {
"filterType": 0,
"id": "C81486BB-3934-48C7-9251-A4EE633DB2BB",
"OperandFilters": [],
"LogicalOperator": 0
},
"yAxisOptions": {
"options": 1
},
"title": "Avg Current User Sessions for analysis1, analysis1, and analysis1",
"titleKind": "Auto",
"visualization": {
"chartType": 2,
"legend": {
"isVisible": true,
"position": 2,
"hideSubtitle": false
},
"axis": {
"x": {
"isVisible": true,
"axisType": 2,
"min": 1546508634047,
"max": 1546595034047
},
"y": {
"isVisible": true,
"axisType": 1
}
},
"timeBrushEnable": false
}
},
"disablePinning": true
}
],
"v2charts": true,
"version": 1
}
}
}
}
},
"copy": {
"name": "AnalysisServiceCopy",
"count": "[length(parameters('analysisService'))]"
},
so, as a general rule, you can only use copy loop to create arrays, not object, so to construct you metrics array you would do something like this:
"charts": [
{
"copy": [
{
"name": "metrics",
"count": "[length(parameters('analysisService'))]",
"input": {
"name": "CurrentUserSessions",
"resourceMetadata": {
"resourceId": "[resourceId(parameters('analysisService')[copyIndex('metrics')].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex('metrics')].Name)]"
},
"aggregationType": 1
}
}
],
"title": "Avg Current User Sessions for analysis1, analysis1, and analysis1",
"visualization": { redacted for brievity },
"itemDataModel": { redacted for brievity },
"disablePinning": true
}
],
you would need to do this everywhere you need to construct an array. as a workaround (if they are identical) you can use the same construct to create a variable and use that variable:
"variables": {
"copy": [
{
"name": "metrics",
"count": "[length(parameters('analysisService'))]",
"input": {
"name": "CurrentUserSessions",
"resourceMetadata": {
"resourceId": "[resourceId(parameters('analysisService')[copyIndex('metrics')].ResourceGroup, '/Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex('metrics')].Name)]"
},
"aggregationType": 1
}
}
],
}
the above will create a variable called "metrics" which you can use anywhere in the template like so:
"[variables('metrics')]"
#4c74356b41
I tried it like this , I directly get an green error line beneath copy that this varbiable never is used.
"variables": {
"copy": [
{
"name": "metrics",
"count": "[length(parameters('analysisService'))]",
"input": {
"name": "qpu_metric",
"resourceMetadata": {
"resourceId": "[resourceId(parameters('analysisService')[copyIndex('metrics')].ResourceGroup, 'Microsoft.AnalysisServices/servers', parameters('analysisService')[copyIndex('metrics')].Name)]"
},
"aggregationType": 1
}
}
]
},
In my code I call the variable like this
"charts": [
{
"metrics" : "[variables('metrics')]",
"title": "Avg QPU",
"visualization": {

Resources