1
2
3
4
5
6
7 """
8 This is the Dashboard API Module for the Worker Node
9 """
10
11 from ApMon import apmon
12 from ApMon import Logger
13 import time, sys, os
14 from types import DictType, StringType, ListType
15
16
17
18
19
20
21 apmonUseUrl = False
22
23
24 apmonInstance = None
25 apmonInit = False
26
27
28 apmonUrlList = ["http://dashb-atlas-monalisa.cern.ch:40808/ApMonConf"]
29 apmonConf = {'dashb-atlas-monalisa.cern.ch:8884': {'sys_monitoring' : 0, \
30 'general_info' : 0, \
31 'job_monitoring' : 0} }
32
33 apmonLoggingLevel = Logger.Logger.FATAL
34
35
36
37
64
65
66
67
79
80
81
82
84 apm = getApmonInstance()
85 if apm is not None :
86 if not isinstance(params, DictType) and not isinstance(params, ListType) :
87 params = {'unknown' : '0'}
88 if not isinstance(taskid, StringType) :
89 taskid = 'unknown'
90 if not isinstance(jobid, StringType) :
91 jobid = 'unknown'
92 try :
93 apm.sendParameters(taskid, jobid, params)
94 except Exception, e:
95 pass
96
97
98
99
101 msg = str(msg)
102 if not msg.endswith('\n') :
103 msg += '\n'
104 try :
105 fh = open('report.log','a')
106 fh.write(msg)
107 fh.close
108 except Exception, e :
109 pass
110
111
112
113
114
115
116 contextConf = {'MonitorID' : ('MonitorID', 'unknown'),
117 'MonitorJobID' : ('MonitorJobID', 'unknown') }
118
119
120
121
122 -def getContext(overload={}) :
123 if not isinstance(overload, DictType) :
124 overload = {}
125 context = {}
126 for paramName in contextConf.keys() :
127 paramValue = None
128 if overload.has_key(paramName) :
129 paramValue = overload[paramName]
130 if paramValue is None :
131 envVar = contextConf[paramName][0]
132 paramValue = os.getenv(envVar)
133 if paramValue is None :
134 defaultValue = contextConf[paramName][1]
135 paramValue = defaultValue
136 context[paramName] = paramValue
137 return context
138
139
140
141
143 argValues = {}
144 for line in lines :
145 paramName = 'unknown'
146 paramValue = 'unknown'
147 line = line.strip()
148 if line.find('=') != -1 :
149 split = line.split('=')
150 paramName = split[0]
151 paramValue = '='.join(split[1:])
152 else :
153 paramName = line
154 if paramName != '' :
155 argValues[paramName] = paramValue
156 return argValues
157
159
160 contextValues = {}
161 paramValues = {}
162
163 for paramName in argValues.keys() :
164 paramValue = argValues[paramName]
165 if paramValue is not None :
166 if paramName in contextConf.keys() :
167 contextValues[paramName] = paramValue
168 else :
169 paramValues[paramName] = paramValue
170 else :
171 logger('Bad value for parameter :' + paramName)
172
173 return contextValues, paramValues
174
175
176
177
178
180 argValues = readArgs(args)
181 contextArgs, paramArgs = filterArgs(argValues)
182 context = getContext(contextArgs)
183 taskId = context['MonitorID']
184 jobId = context['MonitorJobID']
185 logger('SENDING with Task:%s Job:%s' % (taskId, jobId))
186 logger('params : ' + `paramArgs`)
187 apmonSend(taskId, jobId, paramArgs)
188 apmonFree()
189 print "Parameters sent to Dashboard."
190
191
192
193
194
196 - def __init__(self, monitorId = None, jobMonitorId = None, lookupUrl = None) :
197 self.defaultContext = {}
198 self.defaultContext['MonitorID'] = monitorId
199 self.defaultContext['MonitorJobID'] = jobMonitorId
200
201 self.defaultContext['MonitorLookupURL'] = lookupUrl
202
205
207 contextArgs, paramArgs = filterArgs(message)
208 if taskId is not None :
209 contextArgs['MonitorID'] = taskId
210 if jobId is not None :
211 contextArgs['MonitorJobID'] = jobId
212 for key in contextConf.keys() :
213 if not contextArgs.has_key(key) and self.defaultContext[key] is not None :
214 contextArgs[key] = self.defaultContext[key]
215 context = getContext(contextArgs)
216 taskId = context['MonitorID']
217 jobId = context['MonitorJobID']
218 apmonSend(taskId, jobId, paramArgs)
219
220 - def sendValues(self, message, jobId=None, taskId=None) :
222
225
226
227
228
229 if __name__ == '__main__' :
230 args = sys.argv[1:]
231 if len(args) > 0 and args[0] == 'TEST' :
232 dashboard = DashboardAPI('Test')
233 for i in range(100) :
234
235 dashboard.sendValues({'testparam':i}, 'testjob_' + `i`)
236 dashboard.free()
237 sys.exit(0)
238 report(args)
239 sys.exit(0)
240