var data = JSON.parse(value);
var itemList = data.itemList,
hostList = data.hostList;
var exists=0;
// a row is an array
// var row = [];
// item array including the host friendly name
var itemsIncludingHostname = [];
// go through item list. every item will have hostid, but we do not know what is host name
// finding the host name is the whole point of this loop
// take one full itemid containing all characteristics like key_, units, name
for (i in itemList) {
// the mapping has not been found so far
exists=0;
// iterate through host array to find the matching host title
for (h in hostList) {
// check if there is a match between the hostid which belongs at item level and the host array
if (itemList[i].hostid === hostList[h].hostid) {
// if there is a match then write a flag that it exists
exists=1;
var row = {};
row = itemList[i];
itemsIncludingHostname.push(row);
row["hostTechnicalName"] = hostList[h].host;
itemsIncludingHostname.push(row);
row["hostVisiableName"] = hostList[h].name;
itemsIncludingHostname.push(row);
break;
}
}
}
return JSON.stringify(itemsIncludingHostname);
No comments:
Post a Comment