Skip to content

Commit d4011dc

Browse files
committed
see version history in readme
1 parent aa171f1 commit d4011dc

File tree

8 files changed

+130
-301
lines changed

8 files changed

+130
-301
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ This will enable detailed logging to folder "logs" which is as sub folder of the
5353

5454
Changelog
5555
=========
56+
24-02-2015
57+
----------
58+
- Added support for multiprocessing, now sensors are spawned as subprocesses (merged branch experimental with master)
59+
- fixed some indentation stuff (tabs instead of whitespaces)
60+
- fixed function get_config_key in probe_installer.py as key was set to None type all the time, fixed some sensors to put return data in the queue rather than simply returning it.
61+
- other minor fixes resp. code cleanup
62+
- preparation for a workflow (no direct commits to master any more)
63+
5664
14-02-2015
5765
----------
5866
- Added full support for the DS18B20 and a lot of cleanup and fixes

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15.1.2
1+
15.1.3

probe.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def main():
5858
announce = False
5959
# read configuration file (existence check done in probe_controller.py)
6060
config = mini_probe.read_config('./probe.conf')
61-
if config['debug'] == "True":
61+
if config['debug'] == "True":
6262
config['debug'] = True
63-
else:
64-
config['debug'] = False
65-
if config['cleanmem'] == "True":
63+
else:
64+
config['debug'] = False
65+
if config['cleanmem'] == "True":
6666
config['cleanmem'] = True
67-
else:
68-
config['cleanmem'] = False
67+
else:
68+
config['cleanmem'] = False
6969
# Doing some startup logging
7070
logging.info("PRTG Small Probe '%s' starting on '%s'" % (config['name'], socket.gethostname()))
7171
logging.info("Connecting to PRTG Core Server at %s:%s" % (config['server'], config['port']))
@@ -84,6 +84,7 @@ def main():
8484
with warnings.catch_warnings():
8585
warnings.simplefilter("ignore", exceptions.InsecureRequestWarning)
8686
request_announce = requests.get(url_announce, params=data_announce, verify=False)
87+
8788
announce = True
8889
logging.info("ANNOUNCE request successfully sent to PRTG Core Server at %s:%s."
8990
% (config["server"], config["port"]))

probe_installer.py

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class bcolor:
4545
config_old['announced'] = "0"
4646
config_old['protocol'] = "1"
4747
config_old['debug'] = ""
48+
config_old['subprocs'] = "10"
4849

4950
if sys.version_info < (2, 7):
5051
print bcolor.RED + "Python version too old! Please install at least version 2.7" + bcolor.END
@@ -135,16 +136,16 @@ def add_sensor_to_load_list(sensors):
135136
def install_w1_module():
136137
print bcolor.YELLOW + "Checking the hardware for Raspberry Pi." + bcolor.END
137138
if os.uname()[4][:3] == 'arm':
138-
print bcolor.GREEN + "Found hardware matching " + os.uname()[4][:3] + bcolor.END
139+
print bcolor.GREEN + "Found hardware matching " + os.uname()[4][:3] + bcolor.END
139140
tmpUseRaspberry = "%s" % str(raw_input(bcolor.GREEN + "Do you want to enable the Raspberry Pi temperature sensor [Y/n]: " + bcolor.END)).rstrip().lstrip()
140141
if not tmpUseRaspberry.lower() == "n":
141-
try:
142-
install_kernel_module()
142+
try:
143+
install_kernel_module()
143144
return True
144-
except Exception, e:
145-
print "%s.Please install the same" % e
146-
print "Exiting"
147-
sys.exit(1)
145+
except Exception, e:
146+
print "%s.Please install the same" % e
147+
print "Exiting"
148+
sys.exit(1)
148149
else:
149150
return False
150151
else:
@@ -162,38 +163,38 @@ def install_kernel_module():
162163
f.close()
163164
if not found:
164165
print bcolor.GREEN + "Line not found. Now adding the dtoverlay line to /boot/config.txt" + bcolor.END
165-
f = open('/boot/config.txt','a')
166+
f = open('/boot/config.txt','a')
166167
f.write('\n#w1-gpio added by PRTG MiniProbe install script\n')
167168
f.write('dtoverlay=w1-gpio')
168169
f.close()
169170
print bcolor.GREEN + "Please restart the installscript after the Raspberry Pi has been rebooted!" + bcolor.END
170171
print bcolor.GREEN + "Now rebooting..." + bcolor.END
171-
print subprocess.call("reboot", shell=True)
172-
sys.exit(2)
172+
print subprocess.call("reboot", shell=True)
173+
sys.exit(2)
173174

174175
def get_w1_sensors():
175176
sensors = ""
176177
print bcolor.GREEN + "Finding all W1 sensors" + bcolor.END
177178
f = open('/sys/devices/w1_bus_master1/w1_master_slaves','r')
178179
for line in f.readlines():
179180
print bcolor.GREEN + "Found: " + bcolor.YELLOW + line[3:].strip() + bcolor.END
180-
sensors = sensors + "," + "\"" + line[3:].strip() + "\""
181+
sensors = sensors + "," + "\"" + line[3:].strip() + "\""
181182
f.close()
182183
sens = "%s" % str(raw_input(bcolor.GREEN + "Please enter the id's of the temperature sensors you want to use from the list above, seperated with a , [" + sensors[1:].strip("\"") + "]: " + bcolor.END)).rstrip().lstrip()
183184
if not sens == "":
184-
tmpSens = ""
185-
for i in sens.split(","):
186-
tmpSens = tmpSens + ",\"" + i + "\""
185+
tmpSens = ""
186+
for i in sens.split(","):
187+
tmpSens = tmpSens + ",\"" + i + "\""
187188
return tmpSens[1:].strip()
188189
else:
189-
return sensors[1:]
190+
return sensors[1:]
190191

191192
def get_config_user(default="root"):
192193
tmpUser = "%s" % str(raw_input(bcolor.GREEN + "Please provide the username the script should run under [" + default + "]: " + bcolor.END)).rstrip().lstrip()
193194
if not tmpUser == "":
194195
return tmpUser
195196
else:
196-
return default
197+
return default
197198

198199
def get_config_name(default):
199200
tmpName = "%s" % str(raw_input(bcolor.GREEN + "Please provide the desired name of your Mini Probe [" + default + "]: " + bcolor.END)).rstrip().lstrip()
@@ -212,20 +213,20 @@ def get_config_gid(default):
212213
def get_config_ip(default):
213214
tmpIP = "%s" % str(raw_input(bcolor.GREEN + "Please provide the IP/DNS name of the PRTG Core Server [" + default + "]: " + bcolor.END)).rstrip().lstrip()
214215
if not (tmpIP == "") or not (default == ""):
215-
if (tmpIP == "") and not (default == ""):
216-
tmpIP = default
217-
response = os.system("ping -c 1 " + tmpIP + " > /dev/null")
218-
if not response == 0:
219-
print bcolor.YELLOW + "PRTG Server can not be reached. Please make sure the server is reachable." + bcolor.END
220-
go_on = "%s" % str(raw_input(bcolor.YELLOW + "Do you still want to continue using this server [y/N]: " + bcolor.END)).rstrip().lstrip()
216+
if (tmpIP == "") and not (default == ""):
217+
tmpIP = default
218+
response = os.system("ping -c 1 " + tmpIP + " > /dev/null")
219+
if not response == 0:
220+
print bcolor.YELLOW + "PRTG Server can not be reached. Please make sure the server is reachable." + bcolor.END
221+
go_on = "%s" % str(raw_input(bcolor.YELLOW + "Do you still want to continue using this server [y/N]: " + bcolor.END)).rstrip().lstrip()
221222
if not go_on.lower() == "y":
222-
return get_config_ip()
223-
else:
224-
print bcolor.GREEN + "PRTG Server can be reached. Continuing..." + bcolor.END
225-
return tmpIP
223+
return get_config_ip()
224+
else:
225+
print bcolor.GREEN + "PRTG Server can be reached. Continuing..." + bcolor.END
226+
return tmpIP
226227
else:
227-
print bcolor.YELLOW + "You have not provided an IP/DNS name of the PRTG Core Server." + bcolor.END
228-
return get_config_ip()
228+
print bcolor.YELLOW + "You have not provided an IP/DNS name of the PRTG Core Server." + bcolor.END
229+
return get_config_ip()
229230

230231
def get_config_port(default):
231232
tmpPort = "%s" % str(raw_input(bcolor.GREEN + "Please provide the port the PRTG web server is listening to (IMPORTANT: Only SSL is supported)[" + default + "]: " + bcolor.END)).rstrip().lstrip()
@@ -243,13 +244,11 @@ def get_config_base_interval(default):
243244

244245
def get_config_access_key(default):
245246
tmpAccessKey = "%s" % str(raw_input(bcolor.GREEN + "Please provide the Probe Access Key as defined on the PRTG Core [" + default + "]: " + bcolor.END)).rstrip().lstrip()
246-
if not (tmpAccessKey == "") or not (default == ""):
247-
if (tmpAccessKey == "") and not (default == ""):
248-
tmpAccessKey = default
249-
return tmpAccessKey
247+
if (tmpAccessKey == "") and not (default == ""):
248+
tmpAccessKey = default
250249
else:
251-
print bcolor.YELLOW + "You have not provided the Probe Access Key as defined on the PRTG Core." + bcolor.END
252-
return get_config_access_key()
250+
print bcolor.YELLOW + "You have not provided the Probe Access Key as defined on the PRTG Core." + bcolor.END
251+
return tmpAccessKey
253252

254253
def get_config_path(default=os.path.dirname(os.path.abspath(__file__))):
255254
tmpPath = "%s" % str(raw_input(bcolor.GREEN + "Please provide the path where the probe files are located [" + default + "]: " + bcolor.END)).rstrip().lstrip()
@@ -265,6 +264,13 @@ def get_config_clean_memory(default=""):
265264
else:
266265
return "False"
267266

267+
def get_config_subprocs(default="10"):
268+
tmpSubprocs = "%s" % str(raw_input(bcolor.GREEN + "How much subprocesses should be spawned for scanning [" + default +"]: " + bcolor.END)).rstrip().lstrip()
269+
if not tmpSubprocs == "10" or tmpSubprocs == "":
270+
return tmpSubprocs
271+
else:
272+
return default
273+
268274
#For future use
269275
def get_config_announced(default):
270276
return "0"
@@ -276,11 +282,11 @@ def get_config_protocol(default):
276282
def get_config_debug(default):
277283
tmpDebug = "%s" % str(raw_input(bcolor.GREEN + "Do you want to enable debug logging (" + bcolor.YELLOW + "can create massive logfiles!" + bcolor.GREEN + ") [y/N]: " + bcolor.END)).rstrip().lstrip()
278284
if tmpDebug.lower() == "y":
279-
tmpDebug1 = "%s" % str(raw_input(bcolor.YELLOW + "Are you sure you want to enable debug logging? This will create massive logfiles [y/N]: " + bcolor.END)).rstrip().lstrip()
280-
if tmpDebug1.lower() == "y":
285+
tmpDebug1 = "%s" % str(raw_input(bcolor.YELLOW + "Are you sure you want to enable debug logging? This will create massive logfiles [y/N]: " + bcolor.END)).rstrip().lstrip()
286+
if tmpDebug1.lower() == "y":
281287
return "True"
282-
else:
283-
return "False"
288+
else:
289+
return "False"
284290
else:
285291
return "False"
286292

@@ -304,8 +310,8 @@ def get_config(config_old):
304310
print bcolor.GREEN + "Successfully imported modules." + bcolor.END
305311
print ""
306312
if install_w1_module():
307-
sensors = get_w1_sensors()
308-
if not sensors == "":
313+
sensors = get_w1_sensors()
314+
if not sensors == "":
309315
print bcolor.GREEN + "Adding DS18B20.py and selected sensors to /sensors/__init__.py" + bcolor.END
310316
add_sensor_to_load_list(sensors)
311317
print ""
@@ -322,7 +328,8 @@ def get_config(config_old):
322328
probe_conf['announced'] = get_config_announced(config_old['announced'])
323329
probe_conf['protocol'] = get_config_protocol(config_old['protocol'])
324330
probe_conf['debug'] = get_config_debug(config_old['debug'])
325-
print ""
331+
probe_conf['subprocs'] = get_config_subprocs(config_old['subprocs'])
332+
print ""
326333
file_create(path)
327334
write_config(probe_conf)
328335
logpath = "%s/logs" % probe_path
@@ -337,17 +344,17 @@ def get_config(config_old):
337344
print bcolor.GREEN + "Changing File Permissions" + bcolor.END
338345
os.chmod('%s/probe.py' % probe_path, 0755)
339346
os.chmod('/etc/init.d/probe.sh', 0755)
340-
return True
347+
return True
341348
except Exception, e:
342349
print bcolor.RED + "%s. Exiting!" % e + bcolor.END
343350
return False
344351

345352
def remove_config():
346353
try:
347-
print subprocess.call("/etc/init.d/probe.sh stop", shell=True)
348-
os.remove('/etc/init.d/probe.sh')
349-
os.remove('/etc/logrotate.d/MiniProbe')
350-
os.remove('./probe.conf')
354+
print subprocess.call("/etc/init.d/probe.sh stop", shell=True)
355+
os.remove('/etc/init.d/probe.sh')
356+
os.remove('/etc/logrotate.d/MiniProbe')
357+
os.remove('./probe.conf')
351358
except Exception, e:
352359
print "%s. Exiting!" % e
353360
return False
@@ -366,22 +373,22 @@ def remove_config():
366373
probe_config_exists = "%s" % str(raw_input(bcolor.YELLOW + "A config file was already found. Do you want to reconfigure [y/N]: " + bcolor.END)).rstrip().lstrip()
367374
if probe_config_exists.lower() == "y":
368375
config_old = read_config(path)
369-
get_config(config_old)
370-
else:
371-
print ""
376+
get_config(config_old)
377+
else:
378+
print ""
372379
uninstall = "%s" % str(raw_input(bcolor.YELLOW + "Do you want to Uninstall or Restart the service [u/R]: " + bcolor.END)).rstrip().lstrip()
373-
if uninstall.lower() == "u":
374-
remove_config()
375-
conf_avail = False
376-
else:
377-
conf_avail = True
380+
if uninstall.lower() == "u":
381+
remove_config()
382+
conf_avail = False
383+
else:
384+
conf_avail = True
378385
else:
379-
conf_avail = get_config(config_old)
380-
if conf_avail:
381-
print subprocess.call("update-rc.d probe.sh defaults", shell=True)
382-
print bcolor.GREEN + "Starting Mini Probe" + bcolor.END
383-
print subprocess.call("/etc/init.d/probe.sh start", shell=True)
384-
print bcolor.GREEN + "Done. You now can start/stop the Mini Probe using '/etc/init.d/probe.sh start' or '/etc/init.d/probe.sh stop'" + bcolor.END
385-
else:
386-
print "Exiting!"
387-
sys.exit()
386+
conf_avail = get_config(config_old)
387+
if conf_avail:
388+
print subprocess.call("update-rc.d probe.sh defaults", shell=True)
389+
print bcolor.GREEN + "Starting Mini Probe" + bcolor.END
390+
print subprocess.call("/etc/init.d/probe.sh start", shell=True)
391+
print bcolor.GREEN + "Done. You now can start/stop the Mini Probe using '/etc/init.d/probe.sh start' or '/etc/init.d/probe.sh stop'" + bcolor.END
392+
else:
393+
print "Exiting!"
394+
sys.exit()

sensors/cputemp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def get_sensordef():
7171
return sensordefinition
7272

7373
@staticmethod
74-
def get_data(data):
74+
def get_data(data, out_queue):
7575
temperature = CPUTemp()
7676
logging.info("Running sensor: %s" % temperature.get_kind())
7777
try:
@@ -85,7 +85,7 @@ def get_data(data):
8585
"code": 1,
8686
"message": "CPUTemp sensor failed. See log for details"
8787
}
88-
return data
88+
return out_queue.put(data)
8989
tempdata = []
9090
for element in temp:
9191
tempdata.append(element)
@@ -96,11 +96,11 @@ def get_data(data):
9696
}
9797
del temperature
9898
gc.collect()
99-
return data
99+
out_queue.put(data)
100100

101101
@staticmethod
102102
def read_temp(config):
103-
data = []
103+
data = []
104104
chandata = []
105105
temp = open("/sys/class/thermal/thermal_zone0/temp", "r")
106106
lines = temp.readlines()

0 commit comments

Comments
 (0)