...
|
...
|
@@ -5,13 +5,12 @@
|
5
|
5
|
# Module: radmonAgent.py
|
6
|
6
|
#
|
7
|
7
|
# Description: This module acts as an agent between the radiation monitoring
|
8
|
|
-# device and the Internet web server. The agent periodically sends an http
|
|
8
|
+# device and Internet web services. The agent periodically sends an http
|
9
|
9
|
# request to the radiation monitoring device and processes the response from
|
10
|
10
|
# the device and performs a number of operations:
|
11
|
|
-# - conversion of data itemsq
|
|
11
|
+# - conversion of data items
|
12
|
12
|
# - update a round robin (rrdtool) database with the radiation data
|
13
|
13
|
# - periodically generate graphic charts for display in html documents
|
14
|
|
-# - forward the radiation data to other services
|
15
|
14
|
# - write the processed weather data to a JSON file for use by html
|
16
|
15
|
# documents
|
17
|
16
|
#
|
...
|
...
|
@@ -56,7 +55,7 @@ _USER = os.environ['USER']
|
56
|
55
|
_DEFAULT_RADIATION_MONITOR_URL = "{your radiation monitor url}"
|
57
|
56
|
# url if this is a mirror server
|
58
|
57
|
_PRIMARY_SERVER_URL = "{your primary server url}" \
|
59
|
|
- "/{user}/radmon/dynamic/radmonInputData.dat"
|
|
58
|
+ "/radmon/dynamic/radmonInputData.dat"
|
60
|
59
|
|
61
|
60
|
### FILE AND FOLDER LOCATIONS ###
|
62
|
61
|
|
...
|
...
|
@@ -72,6 +71,7 @@ _OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonOutputData.js"
|
72
|
71
|
_RRD_FILE = "/home/%s/database/radmonData.rrd" % _USER
|
73
|
72
|
|
74
|
73
|
### GLOBAL CONSTANTS ###
|
|
74
|
+
|
75
|
75
|
# max number of failed data requests allowed
|
76
|
76
|
_MAX_FAILED_DATA_REQUESTS = 2
|
77
|
77
|
# interval in seconds between data requests to radiation monitor
|
...
|
...
|
@@ -91,10 +91,16 @@ _CHART_HEIGHT = 150
|
91
|
91
|
|
92
|
92
|
# turn on or off of verbose debugging information
|
93
|
93
|
debugOption = False
|
94
|
|
-# used for detecting system faults and radiation monitor
|
95
|
|
-# online or offline status
|
|
94
|
+verboseDebug = False
|
|
95
|
+
|
|
96
|
+# The following two items are used for detecting system faults
|
|
97
|
+# and radiation monitor online or offline status.
|
|
98
|
+
|
|
99
|
+# count of failed attempts to get data from radiation monitor
|
96
|
100
|
failedUpdateCount = 0
|
|
101
|
+# detected status of radiation monitor device
|
97
|
102
|
stationOnline = True
|
|
103
|
+
|
98
|
104
|
# status of reset command to radiation monitor
|
99
|
105
|
remoteDeviceReset = False
|
100
|
106
|
# ip address of radiation monitor
|
...
|
...
|
@@ -106,41 +112,49 @@ dataRequestInterval = _DEFAULT_DATA_REQUEST_INTERVAL
|
106
|
112
|
|
107
|
113
|
def getTimeStamp():
|
108
|
114
|
"""
|
109
|
|
- Sets the error message time stamp to the local system time.
|
|
115
|
+ Set the error message time stamp to the local system time.
|
110
|
116
|
Parameters: none
|
111
|
|
- Returns string containing the time stamp.
|
|
117
|
+ Returns: string containing the time stamp
|
112
|
118
|
"""
|
113
|
119
|
return time.strftime( "%m/%d/%Y %T", time.localtime() )
|
114
|
120
|
##end def
|
115
|
121
|
|
116
|
122
|
def setStatusToOffline():
|
117
|
|
- """Set the status of the the upstream device to "offline" and sends
|
118
|
|
- blank data to the downstream clients.
|
119
|
|
- Parameters:
|
120
|
|
- dData - dictionary object containing weather data
|
121
|
|
- Returns nothing.
|
|
123
|
+ """Set the detected status of the radiation monitor to
|
|
124
|
+ "offline" and inform downstream clients by removing input
|
|
125
|
+ and output data files.
|
|
126
|
+ Parameters: none
|
|
127
|
+ Returns: nothing
|
122
|
128
|
"""
|
123
|
129
|
global stationOnline
|
124
|
130
|
|
|
131
|
+ # Inform downstream clients by removing input and output
|
|
132
|
+ # data files.
|
125
|
133
|
if os.path.exists(_INPUT_DATA_FILE):
|
126
|
134
|
os.remove(_INPUT_DATA_FILE)
|
127
|
135
|
if os.path.exists(_OUTPUT_DATA_FILE):
|
128
|
136
|
os.remove(_OUTPUT_DATA_FILE)
|
129
|
137
|
|
130
|
|
- # If the radiation monitor was previously online, then send a message
|
131
|
|
- # that we are now offline.
|
|
138
|
+ # If the radiation monitor was previously online, then send
|
|
139
|
+ # a message that we are now offline.
|
132
|
140
|
if stationOnline:
|
133
|
141
|
print '%s radiation monitor offline' % getTimeStamp()
|
134
|
142
|
stationOnline = False
|
135
|
143
|
##end def
|
136
|
144
|
|
137
|
145
|
def terminateAgentProcess(signal, frame):
|
138
|
|
- """Send message to log when process killed
|
139
|
|
- Parameters: signal, frame - sigint parameters
|
|
146
|
+ """Send a message to log when the agent process gets killed
|
|
147
|
+ by the operating system. Inform downstream clients
|
|
148
|
+ by removing input and output data files.
|
|
149
|
+ Parameters:
|
|
150
|
+ signal, frame - dummy parameters
|
140
|
151
|
Returns: nothing
|
141
|
152
|
"""
|
142
|
153
|
print '%s terminating radmon agent process' % \
|
143
|
154
|
(getTimeStamp())
|
|
155
|
+
|
|
156
|
+ # Inform downstream clients by removing input and output
|
|
157
|
+ # data files.
|
144
|
158
|
if os.path.exists(_OUTPUT_DATA_FILE):
|
145
|
159
|
os.remove(_OUTPUT_DATA_FILE)
|
146
|
160
|
if os.path.exists(_INPUT_DATA_FILE):
|
...
|
...
|
@@ -151,15 +165,12 @@ def terminateAgentProcess(signal, frame):
|
151
|
165
|
### PUBLIC METHODS ###
|
152
|
166
|
|
153
|
167
|
def getRadiationData():
|
154
|
|
- """Send http request to radiation monitoring device. The response
|
155
|
|
- from the device contains the radiation data. The data is formatted
|
156
|
|
- as an html document.
|
157
|
|
- Parameters:
|
158
|
|
- radiationMonitorUrl - url of radiation monitoring device
|
159
|
|
- HttpRequesttimeout - how long to wait for device
|
160
|
|
- to respond to http request
|
161
|
|
- Returns a string containing the radiation data, or None if
|
162
|
|
- not successful.
|
|
168
|
+ """Send http request to radiation monitoring device. The
|
|
169
|
+ response from the device contains the radiation data as
|
|
170
|
+ unformatted ascii text.
|
|
171
|
+ Parameters: none
|
|
172
|
+ Returns: a string containing the radiation data if successful,
|
|
173
|
+ or None if not successful
|
163
|
174
|
"""
|
164
|
175
|
global remoteDeviceReset
|
165
|
176
|
|
...
|
...
|
@@ -168,9 +179,9 @@ def getRadiationData():
|
168
|
179
|
else:
|
169
|
180
|
sUrl = radiationMonitorUrl
|
170
|
181
|
if remoteDeviceReset:
|
171
|
|
- sUrl += "/reset"
|
|
182
|
+ sUrl += "/reset" # reboot the radiation monitor
|
172
|
183
|
else:
|
173
|
|
- sUrl += "/rdata"
|
|
184
|
+ sUrl += "/rdata" # request data from the monitor
|
174
|
185
|
|