I am looking to save a count of how many times a particular funciton ran within a job. How can I do that within the IDE?
counter = 0
def something(input):
counter = counter + 1
//do your code using input
print(counter) // output = 0
something("bob")
something("tim")
print(counter) // output = 2
I don't know the use case, and the above code isn't tested, but do you mean something like that?
Apologies if I misunderstand the question
My goal is to count the number of times my script performed a certain action so I can provide metrics on usefulness. We are currently using a linux server to run python scripts and I normally use something like:
# Increment the counter
counter += 1
# Open the file for writing (this will overwrite the existing content)
with open(file_path, 'w') as file:
# Write the new counter value to the file
file.write(str(counter))
print(f'Counter updated to: {counter}')
However, I do not seem to be able to write to a manager file from a job. I just wanted to see if anyone else has done something like this using a job, and not a playbook.
Your high level is ok, but in SOAR we don't suggest/allow using the filesystem (you might find a way to do it, but I recommend against it)
Yeah, I dont expect to use filesystem, but I'm asking if there is a built in way to save a variable/text for use the next time the job runs.
Some jobs do have ways to store persistent data, though they differ, so I often read in the IDE. I see that SNOW "Sync Table Record Comments" uses "fetch_timestamp"
https://www.googlecloudcommunity.com/gc/SecOps-SOAR/Saving-the-time-stamp/m-p/638685
You might also look at Global context vars, though I've never used them through IDE in a job, but it's worth trying. Usual Context disclaimer: keys are indexed so don't use millions of them, and values are not to be used as a data store, no big objects please.