Skip to content

Commit d8a585d

Browse files
committed
Merge pull request #2 from eagle00789/master
Installer improvements
2 parents 9891a7b + f323085 commit d8a585d

File tree

1 file changed

+84
-79
lines changed

1 file changed

+84
-79
lines changed

probe_installer.py

100644100755
Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
import time
2626
import subprocess
2727

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

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

72+
def get_config():
73+
print ""
74+
print "No configuration file found. Creating."
75+
print ""
76+
try:
77+
probe_user = "%s" % str(
78+
raw_input("Please provide the username the script should run under "
79+
"(please use 'root' for now): ")).rstrip().lstrip()
80+
probe_conf['name'] = "%s" % str(
81+
raw_input("Please provide the desired name of your Mini Probe [Python MiniProbe]: ")).rstrip().lstrip()
82+
probe_conf['gid'] = "%s" % str(
83+
raw_input("Please provide the Probe GID (any unique alphanumerical string): ")).rstrip().lstrip()
84+
probe_conf['server'] = "%s" % str(
85+
raw_input("Please provide the IP/DNS name of the PRTG Core Server: ")).rstrip().lstrip()
86+
probe_conf['port'] = "%s" % str(raw_input(
87+
"Please provide the port the PRTG web server is listening to "
88+
"(IMPORTANT: Only SSL is supported)[443]: ")).rstrip().lstrip()
89+
probe_conf['baseinterval'] = "%s" % str(
90+
raw_input("Please provide the base interval for your sensors [60]: ")).rstrip().lstrip()
91+
probe_conf['key'] = "%s" % str(
92+
raw_input("Please provide the Probe Access Key as defined on the PRTG Core: ")).rstrip().lstrip()
93+
probe_path = "%s" % str(
94+
raw_input("Please provide the path the probe files are located: ")).rstrip().lstrip()
95+
probe_cleanmem = "%s" % str(
96+
raw_input("Do you want the mini probe flushing buffered and cached memory [y/N]: ")).rstrip().lstrip()
97+
probe_conf['announced'] = "0"
98+
probe_conf['protocol'] = "1"
99+
probe_conf['debug'] = ""
100+
# Handling some default values if nothing is provided
101+
if probe_cleanmem == "y":
102+
probe_conf['cleanmem'] = "True"
103+
else:
104+
probe_conf['cleanmem'] = "False"
105+
if not probe_conf['baseinterval']:
106+
probe_conf['baseinterval'] = "60"
107+
if not probe_conf['name']:
108+
probe_conf['name'] = "Python MiniProbe"
109+
if not probe_conf['port']:
110+
probe_conf['port'] = "443"
111+
response = os.system("ping -c 1 " + probe_conf['server'] + " > /dev/null")
112+
if not response == 0:
113+
print "\033[91mPRTG Server can not be reached. Please make sure the server is reachable.\033[0m"
114+
go_on = "%s" % str(
115+
raw_input("Do you still want to continue using this server [y/N]: ")).rstrip().lstrip()
116+
if not go_on == "y":
117+
sys.exit()
118+
if not (probe_conf['gid'] or probe_conf['server']):
119+
print "No values for GID or CORE SERVER given. Script will now exit"
120+
sys.exit()
121+
else:
122+
file_create(path)
123+
write_config(probe_conf)
124+
print "Config file successfully created"
125+
logpath = "%s/logs" % probe_path
126+
if not (file_check(logpath)):
127+
os.makedirs(logpath)
128+
return True
129+
path_rotate = "/etc/logrotate.d/MiniProbe"
130+
path_init = "/etc/init.d/probe.sh"
131+
print "Creating Logrotation Config"
132+
write_file(path_rotate, logrotation(probe_path))
133+
print "Setting up runlevel"
134+
write_file(path_init, init_script(probe_path, probe_user))
135+
print "Changing File Permissions"
136+
os.chmod('%s/probe.py' % probe_path, 0755)
137+
os.chmod('/etc/init.d/probe.sh', 0755)
138+
except Exception, e:
139+
print "%s. Exiting!" % e
140+
return False
141+
71142
if __name__ == '__main__':
72143
conf_avail = False
73-
print"""
74-
Welcome to the Miniprobe (Python) for PRTG installer
75-
"""
76-
print """
77-
Checking for necessary modules and Python Version
78-
"""
79-
print "."
144+
print "Welcome to the Miniprobe (Python) for PRTG installer"
145+
print ""
146+
print "Checking for necessary modules and Python Version"
80147
try:
81148
sys.path.append('./')
82149
import hashlib
@@ -91,82 +158,20 @@ def init_script(script_path, user):
91158
print "%s.Please install the same" % e
92159
print "Exiting"
93160
sys.exit(1)
94-
time.sleep(1)
95-
print "."
96-
time.sleep(1)
97-
print "."
161+
print "Successfully imported modules."
98162
path = './probe.conf'
99-
print """
100-
Successfully imported modules.
101-
"""
102163
if file_check(path):
103-
print "Config file found. Skipping Configuration."
164+
probe_config_exists = "%s" % str(
165+
raw_input("A config file was already found. Do you want to reconfigure [y/N]: ")).rstrip().lstrip()
166+
if probe_config_exists == "y":
167+
get_config()
168+
conf_avail = True
104169
else:
105-
print "No configuration file found. Creating."
106-
try:
107-
probe_conf = {}
108-
file_create(path)
109-
probe_user = "%s" % str(
110-
raw_input("Please provide the username the script should run under "
111-
"(please use 'root' for now): ")).rstrip().lstrip()
112-
probe_conf['name'] = "%s" % str(
113-
raw_input("Please provide the desired name of your Mini Probe [Python MiniProbe]: ")).rstrip().lstrip()
114-
probe_conf['gid'] = "%s" % str(
115-
raw_input("Please provide the Probe GID (any unique alphanumerical string): ")).rstrip().lstrip()
116-
probe_conf['server'] = "%s" % str(
117-
raw_input("Please provide the IP/DNS name of the PRTG Core Server: ")).rstrip().lstrip()
118-
probe_conf['port'] = "%s" % str(raw_input(
119-
"Please provide the port the PRTG web server is listening to "
120-
"(IMPORTANT: Only SSL is supported)[443]: ")).rstrip().lstrip()
121-
probe_conf['baseinterval'] = "%s" % str(
122-
raw_input("Please provide the base interval for your sensors [60]: ")).rstrip().lstrip()
123-
probe_conf['key'] = "%s" % str(
124-
raw_input("Please provide the Probe Access Key as defined on the PRTG Core: ")).rstrip().lstrip()
125-
probe_path = "%s" % str(
126-
raw_input("Please provide the path the probe files are located: ")).rstrip().lstrip()
127-
probe_cleanmem = "%s" % str(
128-
raw_input("Do you want the mini probe flushing buffered and cached memory [y/N]: ")).rstrip().lstrip()
129-
probe_conf['announced'] = "0"
130-
probe_conf['protocol'] = "1"
131-
probe_conf['debug'] = ""
132-
# Handling some default values if nothing is provided
133-
if probe_cleanmem == "y":
134-
probe_conf['cleanmem'] = "True"
135-
else:
136-
probe_conf['cleanmem'] = "False"
137-
if not probe_conf['baseinterval']:
138-
probe_conf['baseinterval'] = "60"
139-
if not probe_conf['name']:
140-
probe_conf['name'] = "Python MiniProbe"
141-
if not probe_conf['port']:
142-
probe_conf['port'] = "443"
143-
if not probe_conf['baseinterval']:
144-
probe_conf['baseinterval'] = "443"
145-
if not (probe_conf['gid'] or probe_conf['server']):
146-
print "No values for GID or CORE SERVER given. Script will now exit"
147-
sys.exit()
148-
else:
149-
write_config(probe_conf)
150-
print "Config file successfully created"
151-
logpath = "%s/logs" % probe_path
152-
if not (file_check(logpath)):
153-
os.makedirs(logpath)
154-
conf_avail = True
155-
except Exception, e:
156-
print "%s. Exiting!" % e
157-
conf_avail = False
170+
conf_avail = get_config()
171+
158172

159173
if conf_avail:
160-
path_rotate = "/etc/logrotate.d/MiniProbe"
161-
path_init = "/etc/init.d/probe.sh"
162-
print "Creating Logrotation Config"
163-
write_file(path_rotate, logrotation(probe_path))
164-
print "Setting up runlevel"
165-
write_file(path_init, init_script(probe_path, probe_user))
166-
print "Changing File Permissions"
167-
os.chmod('%s/probe.py' % probe_path, 0755)
168-
os.chmod('/etc/init.d/probe.sh', 0755)
169-
print subprocess.call(["update-rc.d", "probe.sh", "defaults"], shell=True)
174+
print subprocess.call("update-rc.d probe.sh defaults", shell=True)
170175
print "Starting Mini Probe"
171176
print subprocess.call("/etc/init.d/probe.sh start", shell=True)
172177
print "Done. You now can start/stop the Mini Probe using '/etc/init.d/probe.sh start' " \

0 commit comments

Comments
 (0)