如何提取 kwrgs 中的嵌套变量?

发布于 2025-01-11 12:06:48 字数 794 浏览 0 评论 0原文

我有一个函数应该从远程服务器获取查询并在 OsQuery 上运行它。我已经能够对其进行配置,以便从远程服务器发送数据并在 kwargs 数据结构中接收数据。

当我运行 print(kwargs) 时,它显示一个很长的字典,其中我有一个名为 'osquery_query' 的字段,我想提取并打印出来。

输出如下所示:

 'object_type': 4, 'principal': {'display_name': 'XXXX', 'id': 1, 'name': 'XXXX', 'type': 'user'}, 'properties': {**'osquery_query': 'select * from logged_on_users'**}, 'row': None, 'task': None, 'type_info': {'artifact': {'fields': {'relating_incidents': {'id': 121, 'values': {}}, 'summary': {'id': 122, 'values': {}}

我尝试使用 kwargs.get 提取数据,如下所示:

def _osquery_handler_function(self, event, *args, **kwargs):
    query = kwargs.get('osquery_query')
    print("Query Is: %s", query)

但这并没有真正捕获任何内容(只是显示它是空的)我如何从字典中提取数据并将其打印出来?

I have a function which is supposed to grab a query from a remote server and run it on OsQuery. I have been able to configure it so that the data is sent from the remote server and is received in the kwargs data structure.

When I run print(kwargs) it shows a long dict, in it I have a field called 'osquery_query' which I'd like to extract and print out .

The output looks like this:

 'object_type': 4, 'principal': {'display_name': 'XXXX', 'id': 1, 'name': 'XXXX', 'type': 'user'}, 'properties': {**'osquery_query': 'select * from logged_on_users'**}, 'row': None, 'task': None, 'type_info': {'artifact': {'fields': {'relating_incidents': {'id': 121, 'values': {}}, 'summary': {'id': 122, 'values': {}}

I have attempted to extract the data using kwargs.get like so:

def _osquery_handler_function(self, event, *args, **kwargs):
    query = kwargs.get('osquery_query')
    print("Query Is: %s", query)

but that doesn't really catch anything (just shows me that it's empty) how could I extract the data from the dictionary and print it out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2025-01-18 12:06:48

要从嵌套字典或其他嵌套数据结构中获取值,您需要单独为每个级别建立索引,如下所示:

def _osquery_handler_function(self, event, *args, **kwargs):
     query = kwargs['properties']['osquery_query']
     print("Query Is: %s", query)

To get a value from nested dictionaries or other nested datastructures, you need to index each level separately, like so:

def _osquery_handler_function(self, event, *args, **kwargs):
     query = kwargs['properties']['osquery_query']
     print("Query Is: %s", query)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文