Skip to content

Add example file read_JOB_FINISH_submitExt.py #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions read_JOB_FINISH_submitExt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3

from pythonlsf import lsf
import sys

# Define function to get key and pair values from the eventrec.eventLog.jobFinishLog.submitExt
def get_pair_from_submit_ext(submit_ext, id):
if submit_ext is None:
return None


values_as_list = lsf.string_array_to_pylist(submit_ext.values, submit_ext.num)
for i in range(submit_ext.num):
key = lsf.intArray_getitem(submit_ext.keys, i)
if key == id:
return values_as_list[i]

return None


def display(eventrec):
"""
display event record, this example to get the user group (-G) value from the JOB_FINISH record
"""
if eventrec.type == lsf.EVENT_JOB_FINISH:
jobid = eventrec.eventLog.jobFinishLog.jobId
fromHost = eventrec.eventLog.jobFinishLog.fromHost
submit_ext=eventrec.eventLog.jobFinishLog.submitExt
userGroup = get_pair_from_submit_ext(submit_ext,lsf.JDATA_EXT_USRGROUP)
# jobgroup = eventrec.eventLog.jobFinishLog.jgroup
# jobgroup = eventrec.eventLog.jobFinishLog.submitExt.values[1075]
print("EVENT_JOB_FINISH jobid<%d>, fromHost<%s>, to jobgroup <%s>" %(jobid, fromHost, userGroup))
else:
print("event type is %d" %(eventrec.type))

def read_eventrec(path):
"""
read lsb.events
"""
lineNum = lsf.new_intp()
lsf.intp_assign(lineNum, 0)
fp = lsf.fopen(path, "r")
if fp is None:
print("The file %s does not exist." % path)
sys.exit(1)

flag = 1

if lsf.lsb_init("test") > 0:
exit(1)

while flag > 0:
log = lsf.lsb_geteventrec(fp, lineNum)
if log:
display(log)
else:
flag = 0


if __name__ == '__main__':
if len(sys.argv) == 1:
print("Usage: %s full_path_lsb.events_file" % (sys.argv[0]))
sys.exit(0)

print("LSF Clustername is :", lsf.ls_getclustername())
#read_eventrec("/opt/lsf8.0.1/work/cluster1/logdir/lsb.events")
read_eventrec(sys.argv[1])