Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 84 additions & 79 deletions probe_installer.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import time
import subprocess

probe_conf = {}
if sys.version_info < (2, 7):
print "Python version too old! Please install at least version 2.7"
print "\033[91mPython version too old! Please install at least version 2.7\033[0m"
print "Exiting"
sys.exit(2)

Expand Down Expand Up @@ -68,15 +69,81 @@ def init_script(script_path, user):
init_script_tpl = open("./scripts/probe.tpl")
return init_script_tpl.read() % (script_path, user)

def get_config():
print ""
print "No configuration file found. Creating."
print ""
try:
probe_user = "%s" % str(
raw_input("Please provide the username the script should run under "
"(please use 'root' for now): ")).rstrip().lstrip()
probe_conf['name'] = "%s" % str(
raw_input("Please provide the desired name of your Mini Probe [Python MiniProbe]: ")).rstrip().lstrip()
probe_conf['gid'] = "%s" % str(
raw_input("Please provide the Probe GID (any unique alphanumerical string): ")).rstrip().lstrip()
probe_conf['server'] = "%s" % str(
raw_input("Please provide the IP/DNS name of the PRTG Core Server: ")).rstrip().lstrip()
probe_conf['port'] = "%s" % str(raw_input(
"Please provide the port the PRTG web server is listening to "
"(IMPORTANT: Only SSL is supported)[443]: ")).rstrip().lstrip()
probe_conf['baseinterval'] = "%s" % str(
raw_input("Please provide the base interval for your sensors [60]: ")).rstrip().lstrip()
probe_conf['key'] = "%s" % str(
raw_input("Please provide the Probe Access Key as defined on the PRTG Core: ")).rstrip().lstrip()
probe_path = "%s" % str(
raw_input("Please provide the path the probe files are located: ")).rstrip().lstrip()
probe_cleanmem = "%s" % str(
raw_input("Do you want the mini probe flushing buffered and cached memory [y/N]: ")).rstrip().lstrip()
probe_conf['announced'] = "0"
probe_conf['protocol'] = "1"
probe_conf['debug'] = ""
# Handling some default values if nothing is provided
if probe_cleanmem == "y":
probe_conf['cleanmem'] = "True"
else:
probe_conf['cleanmem'] = "False"
if not probe_conf['baseinterval']:
probe_conf['baseinterval'] = "60"
if not probe_conf['name']:
probe_conf['name'] = "Python MiniProbe"
if not probe_conf['port']:
probe_conf['port'] = "443"
response = os.system("ping -c 1 " + probe_conf['server'] + " > /dev/null")
if not response == 0:
print "\033[91mPRTG Server can not be reached. Please make sure the server is reachable.\033[0m"
go_on = "%s" % str(
raw_input("Do you still want to continue using this server [y/N]: ")).rstrip().lstrip()
if not go_on == "y":
sys.exit()
if not (probe_conf['gid'] or probe_conf['server']):
print "No values for GID or CORE SERVER given. Script will now exit"
sys.exit()
else:
file_create(path)
write_config(probe_conf)
print "Config file successfully created"
logpath = "%s/logs" % probe_path
if not (file_check(logpath)):
os.makedirs(logpath)
return True
path_rotate = "/etc/logrotate.d/MiniProbe"
path_init = "/etc/init.d/probe.sh"
print "Creating Logrotation Config"
write_file(path_rotate, logrotation(probe_path))
print "Setting up runlevel"
write_file(path_init, init_script(probe_path, probe_user))
print "Changing File Permissions"
os.chmod('%s/probe.py' % probe_path, 0755)
os.chmod('/etc/init.d/probe.sh', 0755)
except Exception, e:
print "%s. Exiting!" % e
return False

if __name__ == '__main__':
conf_avail = False
print"""
Welcome to the Miniprobe (Python) for PRTG installer
"""
print """
Checking for necessary modules and Python Version
"""
print "."
print "Welcome to the Miniprobe (Python) for PRTG installer"
print ""
print "Checking for necessary modules and Python Version"
try:
sys.path.append('./')
import hashlib
Expand All @@ -91,82 +158,20 @@ def init_script(script_path, user):
print "%s.Please install the same" % e
print "Exiting"
sys.exit(1)
time.sleep(1)
print "."
time.sleep(1)
print "."
print "Successfully imported modules."
path = './probe.conf'
print """
Successfully imported modules.
"""
if file_check(path):
print "Config file found. Skipping Configuration."
probe_config_exists = "%s" % str(
raw_input("A config file was already found. Do you want to reconfigure [y/N]: ")).rstrip().lstrip()
if probe_config_exists == "y":
get_config()
conf_avail = True
else:
print "No configuration file found. Creating."
try:
probe_conf = {}
file_create(path)
probe_user = "%s" % str(
raw_input("Please provide the username the script should run under "
"(please use 'root' for now): ")).rstrip().lstrip()
probe_conf['name'] = "%s" % str(
raw_input("Please provide the desired name of your Mini Probe [Python MiniProbe]: ")).rstrip().lstrip()
probe_conf['gid'] = "%s" % str(
raw_input("Please provide the Probe GID (any unique alphanumerical string): ")).rstrip().lstrip()
probe_conf['server'] = "%s" % str(
raw_input("Please provide the IP/DNS name of the PRTG Core Server: ")).rstrip().lstrip()
probe_conf['port'] = "%s" % str(raw_input(
"Please provide the port the PRTG web server is listening to "
"(IMPORTANT: Only SSL is supported)[443]: ")).rstrip().lstrip()
probe_conf['baseinterval'] = "%s" % str(
raw_input("Please provide the base interval for your sensors [60]: ")).rstrip().lstrip()
probe_conf['key'] = "%s" % str(
raw_input("Please provide the Probe Access Key as defined on the PRTG Core: ")).rstrip().lstrip()
probe_path = "%s" % str(
raw_input("Please provide the path the probe files are located: ")).rstrip().lstrip()
probe_cleanmem = "%s" % str(
raw_input("Do you want the mini probe flushing buffered and cached memory [y/N]: ")).rstrip().lstrip()
probe_conf['announced'] = "0"
probe_conf['protocol'] = "1"
probe_conf['debug'] = ""
# Handling some default values if nothing is provided
if probe_cleanmem == "y":
probe_conf['cleanmem'] = "True"
else:
probe_conf['cleanmem'] = "False"
if not probe_conf['baseinterval']:
probe_conf['baseinterval'] = "60"
if not probe_conf['name']:
probe_conf['name'] = "Python MiniProbe"
if not probe_conf['port']:
probe_conf['port'] = "443"
if not probe_conf['baseinterval']:
probe_conf['baseinterval'] = "443"
if not (probe_conf['gid'] or probe_conf['server']):
print "No values for GID or CORE SERVER given. Script will now exit"
sys.exit()
else:
write_config(probe_conf)
print "Config file successfully created"
logpath = "%s/logs" % probe_path
if not (file_check(logpath)):
os.makedirs(logpath)
conf_avail = True
except Exception, e:
print "%s. Exiting!" % e
conf_avail = False
conf_avail = get_config()


if conf_avail:
path_rotate = "/etc/logrotate.d/MiniProbe"
path_init = "/etc/init.d/probe.sh"
print "Creating Logrotation Config"
write_file(path_rotate, logrotation(probe_path))
print "Setting up runlevel"
write_file(path_init, init_script(probe_path, probe_user))
print "Changing File Permissions"
os.chmod('%s/probe.py' % probe_path, 0755)
os.chmod('/etc/init.d/probe.sh', 0755)
print subprocess.call(["update-rc.d", "probe.sh", "defaults"], shell=True)
print subprocess.call("update-rc.d probe.sh defaults", shell=True)
print "Starting Mini Probe"
print subprocess.call("/etc/init.d/probe.sh start", shell=True)
print "Done. You now can start/stop the Mini Probe using '/etc/init.d/probe.sh start' " \
Expand Down