如何从splunk mvc.createService()。get()函数中获取可变?
很抱歉发布此信息,但我需要一些帮助和另一只眼睛。我必须承认,我在Stackoverflow,Splunk Docs和Splunk社区的答案上找到的所有内容,当然尝试过,这使我失败了。
我要实现的是从自定义配置文件(下面的文件详细信息)中读取,并将其在代码的其他部分中使用以进行双检查。
conf文件详细信息: 名称config.conf
, 该节命名为下载
, 该属性称为版本
,其值可能为new
或旧
。
该代码是:
define(["jquery", "react", "splunkjs/mvc", "splunkjs/splunk"], function ($, react, mvc, splunk_js_sdk) {
const e = react.createElement;
const useEffect = react.useEffect;
// Get version from conf file
var version;
mvc.createService().get("/servicesNS/-/my_app/properties/config/download", {}, function (err, response) {
if (err) {
console.log("Error:" + err);
return;
} else {
version = response.data.entry[0].content;
console.log("Version from conf: " + version);
}
return version
});
...........Rest of the code (React)..........
});
...哪个在cons.log 版本中从conf:old
内部函数中显示版本,但是我的真实问题(我看不到它)是我例如,无法弄清楚如何将结果弄清到一个变量中:
var version = old
这看起来像是有希望的异步功能(不确定),但是我的知识(我必须承认)在这方面并不是那么好。
我从在这里,我已经为自己的需求进行了一些调整。
最后,我要预先感谢任何在这里为我带来一点灯光的人。
谢谢你, 乔治
sorry for posting this, but I need some help and another pair of eyes. I must admit that everything that I have found here on stackoverflow, splunk docs and splunk community answers, and of course tried, it failed on me.
What I want to achieve is to read from a custom config file (file details below) and get that result out to be used in other part of the code for a double check.
Conf file details:
name config.conf
,
the stanza is named download
,
the property is called version
which may have value of new
or old
.
The code is:
define(["jquery", "react", "splunkjs/mvc", "splunkjs/splunk"], function ($, react, mvc, splunk_js_sdk) {
const e = react.createElement;
const useEffect = react.useEffect;
// Get version from conf file
var version;
mvc.createService().get("/servicesNS/-/my_app/properties/config/download", {}, function (err, response) {
if (err) {
console.log("Error:" + err);
return;
} else {
version = response.data.entry[0].content;
console.log("Version from conf: " + version);
}
return version
});
...........Rest of the code (React)..........
});
...which works and displays the version in the console.log Version from conf: old
inside function, but my real issue (which I am not able to see it) is that I am not able to figure it how to get out that result into a variable, for example:
var version = old
This looks like an asynchronous function with a promise (not sure) but my knowledge (I must admit) is not so great in this area.
I have found my inspiration from here and I have adjusted a bit for my needs.
In the end I am thanking in advance to anyone who will shed a bit of light for me here.
Thank you,
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这不是最好的想法,或者解决方案,但是我将变量暴露于页面中隐藏的字段值中,从那里我可以在代码页面中的任何地方使用它。
直到弹出另一个想法之前,我对解决方案感到满意。
多亏了任何对此的看法,以及任何会进一步做出贡献的人。
maybe this is not the best idea, or solution, but I have exposed the variable into a hidden field value in my page and from there I was able to use it anywhere in my code pages.
Until another idea will pop up, I am satisfied with my solution.
Thanks to anybody that have had a look on this and to anybody who will contribute further on this.