2016-10-05 74 views
1

我使用javascript SDK查詢Splunk。在searchParams中,我給出了輸出模式爲「json_rows」。未從Splunk獲取JSON格式的數據Javascript sdk

var searchParams = { 
    exec_mode: "normal", 
    output_mode: "json_rows" 
}; 

但仍然當我得到輸出,我不明白它在一個JSON格式。輸出以數組的形式出現。

任何想法是什麼問題?我試過「json_cols」,只有「json」。同樣的結果。

在此先感謝。

編輯:2

一些更多的代碼

var service = new splunkjs.Service({ 
    username:"xxx", 
    password:"xxxx", 
    scheme:"https", 
    host:"xxxxxx.com", 
    port:"5500", 
    version:"5.0" 
    }); 

var searchQuery = 'search index=sn impact=1 OR impact=2 | eval time = round(strptime(impact_start,"%Y-%m-%d %H:%M:%S"), 0)| where time >= ' + 14334627 + ' AND time<=' + 14568862 + '| bucket time span=1d | stats values(number) as incident_name by time'; 
var searchParams = { 
    exec_mode: "normal", 
    output_mode: "JSON" 
}; 
service.oneshotSearch(
    searchQuery, 
    searchParams, 
    function(err, results) { 
     if (results) { 
      var incidentResp = {}; 
      incidentResp["data"] = results.rows; 
      incidentResp["error"] = null; 
      callback(null, incidentResp); 
      return; 
     } 
     else { 
      var errResp = {}; 
      errResp["data"] = null; 
      errResp["error"] =err; 
      callback(null, errResp); 
      return; 
     } 

    } 
); 
+1

你能展示更多的代碼嗎? – Shakeel

回答

0

我不是100%肯定你問什麼,但讓我嘗試幫助的。

output_mode只是告訴REST API如何序列化並返回結果,通常或者JSON,XML或CSV

鑑於你使用JavaScript SDK將數據拉入你的應用程序,而不是實際上有結果寫入文件,我會保持原樣(JSON默認值)

您會在響應的「結果」中找到實際數據。

例如。

service.oneshotSearch(query, params, 
    function(err, response) { 
     if (err) throw new Error (err); 
     console.log(response.results); 
}); 

嘗試改變這一行:

incidentResp["data"] = results.rows;: 

要這樣:

incidentResp["data"] = results.results; 

...但是,是的,這將是結果的數組。

希望這可以幫助