Skip to content

Commit a4e1040

Browse files
author
root
committed
utils.py merged with miniprobe.py - probe.py cleanmem fix - probe_installer fix - DS18B20 defult enable fix - Various minor fixes
1 parent d6d0eda commit a4e1040

File tree

6 files changed

+63
-94
lines changed

6 files changed

+63
-94
lines changed

miniprobe.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
import importlib
3131
import gc
3232
import logging
33-
33+
import subprocess
34+
import os
3435

3536
# import own modules
3637
sys.path.append('./')
@@ -136,4 +137,13 @@ def build_announce(self, sensor_list):
136137
sensors_avail = []
137138
for sensor in sensor_list:
138139
sensors_avail.append(sensor.get_sensordef())
139-
return sensors_avail
140+
return sensors_avail
141+
142+
@staticmethod
143+
def clean_mem():
144+
"""Ugly brute force method to clean up Mem"""
145+
subprocess.call("sync", shell=False)
146+
os.popen("sysctl vm.drop_caches=1")
147+
os.popen("sysctl vm.drop_caches=2")
148+
os.popen("sysctl vm.drop_caches=3")
149+

probe.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import gc
3232
import logging
3333
import socket
34+
import warnings
35+
from requests.packages.urllib3 import exceptions
3436

3537
# import own modules
3638
sys.path.append('./')
@@ -60,6 +62,10 @@ def main():
6062
config['debug'] = True
6163
else:
6264
config['debug'] = False
65+
if config['cleanmem'] == "True":
66+
config['cleanmem'] = True
67+
else:
68+
config['cleanmem'] = False
6369
# Doing some startup logging
6470
logging.info("PRTG Small Probe '%s' starting on '%s'" % (config['name'], socket.gethostname()))
6571
logging.info("Connecting to PRTG Core Server at %s:%s" % (config['server'], config['port']))
@@ -75,7 +81,9 @@ def main():
7581
while not announce:
7682
try:
7783
# announcing the probe and all sensors
78-
request_announce = requests.get(url_announce, params=data_announce, verify=False)
84+
with warnings.catch_warnings():
85+
warnings.simplefilter("ignore", exceptions.InsecureRequestWarning)
86+
request_announce = requests.get(url_announce, params=data_announce, verify=False)
7987
announce = True
8088
logging.info("ANNOUNCE request successfully sent to PRTG Core Server at %s:%s."
8189
% (config["server"], config["port"]))
@@ -100,7 +108,9 @@ def main():
100108
while not task:
101109
json_payload_data = []
102110
try:
103-
request_task = requests.get(url_task, params=task_data, verify=False)
111+
with warnings.catch_warnings():
112+
warnings.simplefilter("ignore", exceptions.InsecureRequestWarning)
113+
request_task = requests.get(url_task, params=task_data, verify=False)
104114
if config['debug']:
105115
logging.debug(request_task.headers)
106116
logging.debug(request_task.text)
@@ -154,8 +164,7 @@ def main():
154164

155165
if config['cleanmem']:
156166
# checking if the clean memory option has been chosen during install then call the method to flush mem
157-
from utils import Utils
158-
Utils.clean_mem()
167+
mini_probe.clean_mem()
159168
sys.exit()
160169

161170
if __name__ == "__main__":

probe_installer.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ class bcolor:
3434
END = '\033[0m'
3535

3636
probe_conf = {}
37+
config_old = {}
38+
config_old['name'] = "Python MiniProbe"
39+
config_old['gid'] = str(uuid.uuid4())
40+
config_old['server'] = ""
41+
config_old['port'] = "443"
42+
config_old['baseinterval'] = "60"
43+
config_old['key'] = ""
44+
config_old['cleanmem'] = ""
45+
config_old['announced'] = "0"
46+
config_old['protocol'] = "1"
47+
config_old['debug'] = ""
48+
3749
if sys.version_info < (2, 7):
3850
print bcolor.RED + "Python version too old! Please install at least version 2.7" + bcolor.END
3951
print "Exiting"
@@ -133,6 +145,8 @@ def install_w1_module():
133145
print "%s.Please install the same" % e
134146
print "Exiting"
135147
sys.exit(1)
148+
else:
149+
return False
136150
else:
137151
print bcolor.RED + "Found hardware matching " + os.uname()[4][:3] + bcolor.END
138152
return False
@@ -181,21 +195,21 @@ def get_config_user(default="root"):
181195
else:
182196
return default
183197

184-
def get_config_name(default="Python MiniProbe"):
198+
def get_config_name(default):
185199
tmpName = "%s" % str(raw_input(bcolor.GREEN + "Please provide the desired name of your Mini Probe [" + default + "]: " + bcolor.END)).rstrip().lstrip()
186200
if not tmpName == "":
187201
return tmpName
188202
else:
189203
return default
190204

191-
def get_config_gid(default=str(uuid.uuid4())):
205+
def get_config_gid(default):
192206
tmpGid = "%s" % str(raw_input(bcolor.GREEN + "Please provide the Probe GID [" + default + "]: " + bcolor.END)).rstrip().lstrip()
193207
if not tmpGid == "":
194208
return tmpGid
195209
else:
196210
return default
197211

198-
def get_config_ip(default=""):
212+
def get_config_ip(default):
199213
tmpIP = "%s" % str(raw_input(bcolor.GREEN + "Please provide the IP/DNS name of the PRTG Core Server [" + default + "]: " + bcolor.END)).rstrip().lstrip()
200214
if not (tmpIP == "") or not (default == ""):
201215
if (tmpIP == "") and not (default == ""):
@@ -213,21 +227,21 @@ def get_config_ip(default=""):
213227
print bcolor.YELLOW + "You have not provided an IP/DNS name of the PRTG Core Server." + bcolor.END
214228
return get_config_ip()
215229

216-
def get_config_port(default="443"):
230+
def get_config_port(default):
217231
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()
218232
if not tmpPort == "":
219233
return tmpPort
220234
else:
221235
return default
222236

223-
def get_config_base_interval(default="60"):
237+
def get_config_base_interval(default):
224238
tmpInterval = "%s" % str(raw_input(bcolor.GREEN + "Please provide the base interval for your sensors [" + default + "]: " + bcolor.END)).rstrip().lstrip()
225239
if not tmpInterval == "":
226240
return tmpInterval
227241
else:
228242
return default
229243

230-
def get_config_access_key(default=""):
244+
def get_config_access_key(default):
231245
tmpAccessKey = "%s" % str(raw_input(bcolor.GREEN + "Please provide the Probe Access Key as defined on the PRTG Core [" + default + "]: " + bcolor.END)).rstrip().lstrip()
232246
if not (tmpAccessKey == "") or not (default == ""):
233247
if (tmpAccessKey == "") and not (default == ""):
@@ -252,14 +266,14 @@ def get_config_clean_memory(default=""):
252266
return "False"
253267

254268
#For future use
255-
def get_config_announced(default="0"):
269+
def get_config_announced(default):
256270
return "0"
257271

258272
#For future use
259-
def get_config_protocol(default="1"):
273+
def get_config_protocol(default):
260274
return "1"
261275

262-
def get_config_debug(default=""):
276+
def get_config_debug(default):
263277
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()
264278
if tmpDebug.lower() == "y":
265279
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()
@@ -270,7 +284,7 @@ def get_config_debug(default=""):
270284
else:
271285
return "False"
272286

273-
def get_config(config_old = {}):
287+
def get_config(config_old):
274288
print ""
275289
print bcolor.YELLOW + "Checking for necessary modules and Python Version" + bcolor.END
276290
try:
@@ -289,11 +303,11 @@ def get_config(config_old = {}):
289303
sys.exit(1)
290304
print bcolor.GREEN + "Successfully imported modules." + bcolor.END
291305
print ""
292-
install_w1_module()
293-
sensors = get_w1_sensors()
294-
if not sensors == "":
295-
print bcolor.GREEN + "Adding DS18B20.py and selected sensors to /sensors/__init__.py" + bcolor.END
296-
add_sensor_to_load_list(sensors)
306+
if install_w1_module():
307+
sensors = get_w1_sensors()
308+
if not sensors == "":
309+
print bcolor.GREEN + "Adding DS18B20.py and selected sensors to /sensors/__init__.py" + bcolor.END
310+
add_sensor_to_load_list(sensors)
297311
print ""
298312
try:
299313
probe_user = get_config_user()
@@ -362,7 +376,7 @@ def remove_config():
362376
else:
363377
conf_avail = True
364378
else:
365-
conf_avail = get_config()
379+
conf_avail = get_config(config_old)
366380
if conf_avail:
367381
print subprocess.call("update-rc.d probe.sh defaults", shell=True)
368382
print bcolor.GREEN + "Starting Mini Probe" + bcolor.END

sensors/ds18b20.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2121

2222
import gc
23+
import os
2324
import logging
2425
import time
2526
import __init__
@@ -40,15 +41,19 @@ def get_sensordef():
4041
"""
4142
Definition of the sensor and data to be shown in the PRTG WebGUI
4243
"""
44+
if os.path.isdir("/sys/bus/w1/devices"):
45+
default = "yes"
46+
else:
47+
default = "no"
4348
sensordefinition = {
4449
"kind": DS18B20.get_kind(),
4550
"name": "DS18B20 Temperature",
4651
"description": "Returns the temperature measured by an attached DS18B20 temperature sensor on pin 4",
47-
"default": "yes",
52+
"default": default,
4853
"help": "Returns the temperature measured by an attached DS18B20 temperature sensor on pin 4",
4954
"tag": "mpds18b20sensor",
50-
"fields": [],
51-
"groups": []
55+
"groups": [
56+
]
5257
}
5358
return sensordefinition
5459

test.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

utils.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)