1 |
< |
#!/usr/bin/python |
2 |
< |
|
3 |
< |
""" |
4 |
< |
This is a simple test program for the 'apmon' Python module. |
5 |
< |
|
6 |
< |
""" |
7 |
< |
|
8 |
< |
import apmon |
9 |
< |
import time, sys, os |
10 |
< |
|
11 |
< |
apmonInstance = None |
12 |
< |
def getApmonInstance() : |
13 |
< |
global apmonInstance |
14 |
< |
if apmonInstance is None : |
15 |
< |
#apmonUrl = 'http://monalisa.cern.ch/ARDA/apmon.cms' |
16 |
< |
apmonUrl = ('192.91.245.5:58884',) |
17 |
< |
logger("ApmReport: Creating ApMon with " + `apmonUrl`) |
18 |
< |
apmonInstance = apmon.ApMon(apmonUrl) |
19 |
< |
return apmonInstance |
20 |
< |
|
21 |
< |
def getParamValues(lines, retDict=None) : |
22 |
< |
readAll = False |
23 |
< |
if retDict is None : |
24 |
< |
retDict = {} |
25 |
< |
readAll = True |
26 |
< |
elif retDict == {} : |
27 |
< |
readAll = True |
28 |
< |
for line in lines : |
29 |
< |
line = line.strip() |
30 |
< |
if line.find('=') != -1 : |
31 |
< |
split = line.split('=') |
32 |
< |
if len(split) > 2 : |
33 |
< |
split = [split[0], '='.join(split[1:])] |
34 |
< |
split = [x.strip() for x in split] |
35 |
< |
if readAll or split[0] in retDict.keys() : |
36 |
< |
retDict[split[0]] = split[1] |
37 |
< |
return retDict |
38 |
< |
|
39 |
< |
def readFileContent(fileName) : |
40 |
< |
lines = None |
41 |
< |
if os.path.exists(fileName) : |
42 |
< |
fh = open(fileName, 'r') |
43 |
< |
lines = fh.readlines() |
44 |
< |
fh.close() |
45 |
< |
return lines |
46 |
< |
|
47 |
< |
def readParamValues(fileNameArr, retDict=None) : |
48 |
< |
for fileName in fileNameArr : |
49 |
< |
lines = readFileContent(fileName) |
50 |
< |
if lines is not None : |
51 |
< |
return getParamValues(lines, retDict) |
52 |
< |
return retDict |
53 |
< |
|
54 |
< |
def readTaskIdFile(filename='TASK_ID') : |
55 |
< |
taskId = None |
56 |
< |
taskIdFile = readFileContent(filename) |
57 |
< |
if taskIdFile is not None and len(taskIdFile) > 0 : |
58 |
< |
taskId = taskIdFile[0].strip() |
59 |
< |
return taskId |
60 |
< |
|
61 |
< |
def logger(msg) : |
62 |
< |
msg = `msg` |
63 |
< |
if not msg.endswith('\n') : |
64 |
< |
msg = msg + '\n' |
65 |
< |
fh = open('report.log','a') |
66 |
< |
fh.write(msg) |
67 |
< |
fh.close |
68 |
< |
#print msg |
69 |
< |
|
70 |
< |
def getJobID(id, jobId='UNKNOWN') : |
71 |
< |
if id.find('.') != -1 : |
72 |
< |
split = id.split('.') |
73 |
< |
if split[0].find('_') : |
74 |
< |
jobId = split[0].split('_')[-1] |
75 |
< |
elif len(split[0]) >= 6 : |
76 |
< |
jobId = split[0][-6:] |
77 |
< |
else : |
78 |
< |
jobId = split[0] |
79 |
< |
return jobId |
80 |
< |
|
81 |
< |
def mlSend(task, job, paramDict) : |
82 |
< |
apm = getApmonInstance() |
83 |
< |
#logger("ApmReport: Destinations:", apm.destinations) |
84 |
< |
logger("ApmReport: Sending:"+`task`+":"+`job`+":"+`paramDict`) |
85 |
< |
apm.sendParameters(task, job, paramDict) |
86 |
< |
|
1 |
> |
#!/usr/bin/env python |
2 |
> |
|
3 |
|
## |
4 |
|
## MAIN PROGRAM |
5 |
|
## |
90 |
– |
if __name__ == '__main__' : |
91 |
– |
# Default file names and initial values |
92 |
– |
mlConfigFileArr = ['MonalisaParameters', '.orcarc'] |
93 |
– |
# mlDefaultDict = { 'SyncGridName' : os.popen("grid-proxy-info -identity") , |
94 |
– |
# 'SyncGridJobId' : os.environ['EDG_WL_JOBID'] } |
95 |
– |
mlDefaultDict = { 'SyncGridName' : 'gigio', |
96 |
– |
'SyncGridJobId' : 'pippo' } |
6 |
|
|
7 |
< |
args = sys.argv[1:] |
8 |
< |
|
100 |
< |
# Read values from file(s) and cmdline |
101 |
< |
mlDict = readParamValues(mlConfigFileArr, mlDefaultDict) |
102 |
< |
paramDict = getParamValues(args) |
103 |
< |
if len(paramDict) == 0 : |
104 |
< |
sys.exit(0) |
105 |
< |
# Report |
106 |
< |
mlSend(mlDict['SyncGridName'], mlDict['SyncGridJobId'], paramDict) |
7 |
> |
import sys |
8 |
> |
from DashboardAPI import report |
9 |
|
|
10 |
< |
# Exit |
10 |
> |
if __name__ == '__main__' : |
11 |
> |
args = sys.argv[1:] |
12 |
> |
report(args) |
13 |
|
sys.exit(0) |