[英]Parse Json data (from Azure)
我試圖解析這個 json,試圖獲取一個表格,其中包含列數和行數以及此數據中的計算機名稱。
{
"alertId": "raxhighcpu",
"Description": "",
"NotificationType": "public",
"LinkToSearchResults": "https://portal.azure.",
"searchInterval": "00:05:00",
"alertValue": "0",
"alertName": "On-Premise CPU Alert",
"IncludeSearchResults": true,
"SearchQuery": "Perf\n| where _ResourceId == ''\n| where ObjectName == 'Processor' and CounterName contains 'Processor Time' and InstanceName == '_Total' and Computer in ((Perf | where CounterName == 'Processor Queue Length'| summarize AVGQUEUE = avg(CounterValue) by Computer| where AVGQUEUE>1)) | summarize AVGCPU = avg(CounterValue) by Computer\n| where AVGCPU>60\n| project Computer, AVGCPU",
"SearchResults": {
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "Computer",
"type": "string"
},
{
"name": "AVGCPU",
"type": "real"
}
],
"rows": [
[
".ci.corp",
66.60977770487469
],
[
".ci.corp",
60.13546142578125
],
[
".ci.corp",
62.83857485453288
]
]
}
],
"statistics": {
"query": {
"executionTime": 0.640761,
"resourceUsage": {
"cache": {
"memory": {
"hits": 15169,
"misses": 0,
"total": 15169
},
"disk": {
"hits": 0,
"misses": 0,
"total": 0
},
"shards": {
"hot": {
"hitbytes": 0,
"missbytes": 0,
"retrievebytes": 0
},
"cold": {
"hitbytes": 0,
"missbytes": 0,
"retrievebytes": 0
},
"bypassbytes": 0
}
},
"cpu": {
"user": "00:00:01.1718750",
"kernel": "00:00:00.0781250",
"totalCpu": "00:00:01.2500000"
},
"memory": {
"peakPerNode": 117441760
}
},
"inputDatasetStatistics": {
"extents": {
"total": 3566,
"scanned": 10,
"scannedMinDatetime": "2020-09-10T19:28:59.5588356Z",
"scannedMaxDatetime": "2020-09-10T19:28:59.5608906Z"
},
"rows": {
"total": 80516126072,
"scanned": 6433282
},
"rowstores": {
"scannedRows": 2095190,
"scannedValuesSize": 153591356
},
"shards": {
"queriesGeneric": 0,
"queriesSpecialized": 0
}
},
"datasetStatistics": [
{
"tableRowCount": 3,
"tableSize": 116
}
]
}
},
"dataSources": [
{
"resourceId": "/resourcegroups/ci-euwe01-siem-oms-01/providers/microsoft.operationalinsights/workspaces/",
"region": "westeurope",
"tables": [
"Perf"
]
}
]
}
}
我在這里陷入了循環:
var clist ="";
clist = event.SearchResults.tables[0].rows;
if(event.SearchResult != '') {
var comm ="";
var SearchResultsw = event.SearchResults;
var SearchResultsw = "";
for (var i = 0; i < SearchResultsw.length; i++) {
comm += SearchResultsw.tables[i];
for (var j = 0; j < impactedServices[i].tables.columns.length; j++) {
if (j != 0) {
comm += "\n";
}
comm += SearchResultsw[i].tables[j].rows;
}
comm += "\n";
}
var formatfinal = "\n\ninfo:\n" + comm;
} // ?
我不確定你想要什么,但這里有一個獲取列數、行數和計算機信息的代碼:
if(event.SearchResults != '') {
var comm = "";
var numColumns = 0;
var numRows = 0;
var results = event.SearchResults;
//check how many columns there are
for (var i = 0; i < results.tables[0].columns.length; i++) {
numColumns++;
}
//check how many rows there are
for (var j = 0; j < results.tables[0].rows.length; j++) {
numRows++;
//write the computer info(?) in the variable comm
comm += results.tables[0].rows[j][0] + " " + results.tables[0].rows[j][1] + "\n"
}
var formatfinal = "\n\ninfo:\n" + comm + "\ncolumns number: " + numColumns + "\nrows number: " + numRows;
console.log(formatfinal)
}
這將是變量formatfinal
:
info:
.ci.corp 66.60977770487469
.ci.corp 60.13546142578125
.ci.corp 62.83857485453288
columns number: 2
rows number: 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.