-
code:
output- json:
what's can I to do??? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @NSH531 -
If you want the call all on one line, it would need to look something like: last_seen_result = F1.hosts.Hosts(client_id=client_id, client_secret=secret).query_devices_by_filter(filter=f"hostname:*'*{myid}*'",sort='hostname.asc') I don't recommend that pattern, as it is difficult to read. If I were to refactor the method above, it would look something like this: # Import the Service Class at the top of the file
from falconpy import Hosts
# Other code happens here, including the retrieval of our client_id and secret.
hosts_sdk = Hosts(client_id=client_id, client_secret=secret)
# This object is then available to our method when it is called.
# ... other code and methods
# Note: You don't need to filter for last_seen before "now". That is the same as the default.
@app.route("/hosts/last_seen/<myid>")
def hst(myid: str) -> dict:
return hosts_sdk.query_devices_by_filter(filter=f"hostname:*'*{myid}*'", sort='hostname.asc') Thank you for the question! |
Beta Was this translation helpful? Give feedback.
Hi @NSH531 -
response
is defined as an instance of the Hosts Service Class. It is properly created (assumingclient_id
andsecret
are valid andfalconpy
is imported outside of this method), but then it goes unused. The call to setlast_seen_result
is malformed by calling the module, then the class, then the method directly. (The way it is written, it is making a call to an uninstantiated object and does not reference the constructor.)If you want the call all on one line, it would need to look something like:
I don't recommend that patter…