示例#1
0
def main():
    client = Client("cream_jobPurge", "1.0")
    client.createParser()
    client.readOptions()

    try:
        client.checkProxy()

        jobId = client.jobSubmit()

        client.debug("job id: " + jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    terminalStates = ['DONE-OK', 'DONE-FAILED', 'ABORTED', 'CANCELLED']

    lastStatus=""

    while not lastStatus in terminalStates:
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)

    try:       
        client.jobPurge(jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    while (1):
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.OK, "OK: job purged")
示例#2
0
def main():
    client = Client("cream_serviceInfo", "1.0")
    client.createParser("FALSE")
    client.readOptions()

    try:
        client.checkProxy()

        data = client.serviceInfo()
        datv = data.split("\n")
        client.nagiosExit(client.OK, "OK: " + datv[1])
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)
示例#3
0
def main():
    client = Client("cream_allowedSubmission", "1.0")
    client.createParser("FALSE")
    client.readOptions()

    try:
        client.checkProxy()

        data = client.allowedSubmission()
        client.nagiosExit(client.OK, "OK: " + data)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)
示例#4
0
def main():
    client = Client("cream-jobSubmit", "1.0")
    client.createParser()
    client.optionParser.add_option("-m",
                         "--metrics",
                         dest="metrics_list",
                         help="The metrics file path")
    client.readOptions()

    if not client.options.metrics_list:
        optionParser.error("metrics file path not specified")

    try:
        with open(client.options.metrics_list) as infile:
            data = infile.read()

        metrics = data.splitlines()
    except Exception as ex:
        client.nagiosExit(client.CRITICAL, ex)
 
    try:
        client.checkProxy()

        jobId = client.jobSubmit()

        client.debug("job id: " + jobId)
    except Exception as ex:
        client.nagiosExit(client.CRITICAL, ex)

    terminalStates = ['DONE-OK', 'DONE-FAILED', 'ABORTED', 'CANCELLED']
    lastStatus = ""
    exitCode = None

    while not lastStatus in terminalStates:
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.CRITICAL, ex)

    try:
        client.dir = "/var/spool/cream/" + client.hostname
        if not os.path.isdir(client.dir):
            os.makedirs(client.dir)

        osbdir = client.getOutputSandbox(jobId)

        client.debug("output sandbox dir: " + osbdir)

        outfiles = dircache.listdir(osbdir)

    except Exception as ex:
        client.nagiosExit(client.CRITICAL, ex)

    for metric in metrics:
        client.debug("metric is " + metric)
        outfilename = osbdir + "/" + metric + ".out"
        resfilename = osbdir + "/" + metric + ".res"
        client.debug("outfile is " + outfilename)
        client.debug("resfile is " + resfilename)
        if os.path.isfile(outfilename) and os.path.isfile(resfilename) :
            with open(outfilename) as outfile:
                data = outfile.read()
            output = data.splitlines()

            outmsg = ""
            sep = "\\\\n"
            for line in output:
                outmsg += line + "\\\\n"

            with open(resfilename) as resfile:
                data = resfile.read()
            exitvalue = data.splitlines()

            currtime = str(int(time.mktime(time.localtime())))
            
            nagmsg = "[" + currtime + "] PROCESS_SERVICE_CHECK_RESULT;" + client.hostname + \
                  ";eu.egi.sec.WN-" + metric + "-ops;" + exitvalue[0] + ";" + outmsg + '\n'
            client.debug("Results submitted to nagios: " + nagmsg)
            with open(nagcmd, 'a') as nagcmdfile:
                  nagcmdfile.write(nagmsg)

        else:
            currtime = str(int(time.mktime(time.localtime())))
            nagmsg = "[" + currtime + "] PROCESS_SERVICE_CHECK_RESULT;" + client.hostname + \
                  ";eu.egi.sec.WN-" + metric + "-ops;" + "3;(No output returned from plugin)" + '\n'
            client.debug("Results submitted to nagios: " + nagmsg)
            with open(nagcmd, 'a') as nagcmdfile:
                  nagcmdfile.write(nagmsg)

    try:       
        client.jobPurge(jobId)
    except Exception as ex:
        client.debug("cannot purge the job" + ex)

    if lastStatus == terminalStates[0] :
        client.nagiosExit(client.OK, "Job terminated with status=" + lastStatus)
    else:
        client.nagiosExit(client.CRITICAL, "Job terminated with status=" + lastStatus)
示例#5
0
def main():
    client = Client("cream-jobSubmit", "1.0")
    client.createParser()
    client.readOptions()

    try:
        client.checkProxy()

        jobId = client.jobSubmit()

        client.debug("job id: " + jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    terminalStates = ['DONE-OK', 'DONE-FAILED', 'ABORTED', 'CANCELLED']
    lastStatus = ""
    exitCode = None

    while not lastStatus in terminalStates:
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)


    outputSandbox = None
    lastLine = None

    #if lastStatus == "DONE-OK":
    try:
        osbdir = client.getOutputSandbox(jobId)

        client.debug("output sandbox dir: " + osbdir)

        dir = dircache.listdir(osbdir)

        outputSandbox = ""
        lastLine = ""

        for file in dir:
            with open(osbdir + "/" + file) as infile:
                outputSandbox += "\n-------------------------\n" + file + "\n-------------------------\n"

                for line in infile:
                     outputSandbox += line
                     lastLine = line

        shutil.rmtree(osbdir)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    try:       
        client.jobPurge(jobId)
    except Exception as ex:
        client.debug("cannot purge the job" + ex)

    if lastStatus == terminalStates[0] and exitCode == "0":
        client.nagiosExit(client.OK, lastStatus + ": " + lastLine)
    else:
        client.nagiosExit(client.UNKNOWN, "Job terminated with status=" + lastStatus + " and exitCode=" + exitCode + outputSandbox)
示例#6
0
def main():
    client = Client("cream_jobCancel", "1.0")
    client.createParser()
    client.readOptions()

    try:
        client.checkProxy()

        jobId = client.jobSubmit()

        client.debug("job id: " + jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    activeStates = ['PENDING', 'RUNNING', 'REALLY-RUNNING']
    terminalStates = ['DONE-OK', 'DONE-FAILED', 'ABORTED', 'CANCELLED']

    lastStatus=""

    while not lastStatus in activeStates:
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)
            client.debug("job status: " + lastStatus)

            if lastStatus in terminalStates:
                client.nagiosExit(client.UNKNOWN, "job already terminated")
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)

    try:       
        client.jobCancel(jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)


    while not lastStatus == "CANCELLED":
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)

    try:
        client.jobPurge(jobId)
    except Exception as ex:
        client.debug("cannot purge the job")

    client.nagiosExit(client.OK, "OK: job cancelled")