mirror of https://github.com/Aidaho12/haproxy-wi
parent
299894442d
commit
bee9685e96
17
README.md
17
README.md
|
@ -7,14 +7,15 @@ A simple web interface(user-frendly web GUI) for managing Haproxy servers
|
|||
1. View statistics of all servers in one place
|
||||
2. Server and service statsus in one place
|
||||
3. View logs of all servers in one place
|
||||
4. Disabling / enabling the backend servers without reboot (after reboot, will work as specified in the config), viewing server state data
|
||||
5. Browsing Configs
|
||||
6. Add sections: listen, frontend, backend from web interface
|
||||
7. Editing configs
|
||||
8. Rollback to previous versions of the config
|
||||
9. Comparing versions of configs
|
||||
10. Users roles: admin, editor, viewer
|
||||
11. Telegram notification
|
||||
4. Map frontend, backends and servers
|
||||
5. Disabling / enabling the backend servers without reboot (after reboot, will work as specified in the config), viewing server state data
|
||||
6. Browsing Configs
|
||||
7. Add sections: listen, frontend, backend from web interface
|
||||
8. Editing configs
|
||||
9. Rollback to previous versions of the config
|
||||
10. Comparing versions of configs
|
||||
11. Users roles: admin, editor, viewer
|
||||
12. Telegram notification
|
||||
|
||||
# Install
|
||||
Can be used as a service, or via fastaci apache + fastCGI(recommend, because it works faster), how to use the service:
|
||||
|
|
|
@ -82,11 +82,13 @@ if form.getvalue('servaction') is not None:
|
|||
cmd='echo "%s %s" |nc %s 1999' % (enable, backend, serv)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
|
||||
stdout, stderr = p.communicate()
|
||||
err = stderr.splitlines()
|
||||
output = stdout.splitlines()
|
||||
|
||||
print('<center><h3>You %s %s on HAproxy %s. <a href="viewsttats.py?serv=%s" title="View stat" target="_blank">Look it</a> or <a href="edit.py" title="Edit">Edit something else</a></h3><br />' % (enable, backend, serv, serv))
|
||||
print('<center>'.join(map(str, output)))
|
||||
|
||||
if err:
|
||||
print('<center>'.join(map(str, err)))
|
||||
action = 'edit.py ' + enable + ' ' + backend
|
||||
funct.logging(serv, action)
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ def links():
|
|||
'<li><a href=/cgi-bin/viewsttats.py title="View Stats">Stats</a> </li>'
|
||||
'<li><a href="http://172.28.5.106:3000/d/000000002/haproxy?refresh=1m&orgId=1" title="Mon" target="_blanck">Monitoring</a> </li>'
|
||||
'<li><a href=/cgi-bin/logs.py title="View logs">Logs</a></li>'
|
||||
'<li><a href=/cgi-bin/map.py title="View map">Map</a></li>'
|
||||
'</ul>'
|
||||
'</li>'
|
||||
'<li><a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> </li>'
|
||||
|
@ -107,7 +108,7 @@ def links():
|
|||
'<li><a href=/cgi-bin/add.py#listner title="Add single listen">Add listen</a></li>'
|
||||
'<li><a href=/cgi-bin/add.py#frontend title="Add single frontend">Add frontend</a></li>'
|
||||
'<li><a href=/cgi-bin/add.py#backend title="Add single backend">Add backend</a></li>'
|
||||
'<li><a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> </li>'
|
||||
'<li><a href=/cgi-bin/config.py title="Edit Config">Edit</a> </li>'
|
||||
'</ul>'
|
||||
'</li>'
|
||||
'<li><a href="#">Versions</a>'
|
||||
|
@ -293,7 +294,6 @@ def compare(stdout):
|
|||
print('</div></div>')
|
||||
|
||||
def show_log(stdout):
|
||||
#print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
|
||||
i = 0
|
||||
for line in stdout:
|
||||
i = i + 1
|
||||
|
@ -302,21 +302,6 @@ def show_log(stdout):
|
|||
else:
|
||||
print('<div class="line">' + line + '</div>')
|
||||
|
||||
def show_log_tailf(channel, serv):
|
||||
import select
|
||||
print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
|
||||
print('<pre>')
|
||||
while 1:
|
||||
rl, wl, xl = select.select([channel],[],[],0.0)
|
||||
if len(rl) > 0:
|
||||
print(channel.recv(200).decode(encoding='UTF-8'))
|
||||
print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
|
||||
#i = i + 1
|
||||
#if i % 2 == 0:
|
||||
# print('<div class="line3">' + line + '</div>')
|
||||
#else:
|
||||
# print('<div class="line">' + line + '</div>')
|
||||
|
||||
def show_ip(stdout):
|
||||
for line in stdout:
|
||||
print(line)
|
||||
|
@ -329,13 +314,6 @@ def server_status(stdout):
|
|||
|
||||
def ssh_command(serv, commands, **kwargs):
|
||||
ssh = ssh_connect(serv)
|
||||
|
||||
if kwargs.get("tailf") == "1":
|
||||
transport = ssh.get_transport()
|
||||
channel = transport.open_session()
|
||||
channel.exec_command('tail -f /var/log/haproxy.log')
|
||||
show_log_tailf(channel, serv)
|
||||
|
||||
|
||||
for command in commands:
|
||||
try:
|
||||
|
|
|
@ -56,7 +56,7 @@ if form.getvalue('grep') is not None:
|
|||
else:
|
||||
grep = ' '
|
||||
|
||||
print('</td><td><input type="text" name="rows" %s class="form-control" required></td>' % rows)
|
||||
print('</td><td><input type="number" name="rows" %s class="form-control" required></td>' % rows)
|
||||
print('<td><input type="text" name="grep" class="form-control" %s >' % grep)
|
||||
print('</td></tr>'
|
||||
'<tr style="border:none;">'
|
||||
|
@ -86,6 +86,6 @@ if form.getvalue('serv') is not None:
|
|||
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
|
||||
syslog_server = config.get('logs', 'syslog_server')
|
||||
|
||||
funct.ssh_command(syslog_server, commands, show_log="1", tailf="0")
|
||||
funct.ssh_command(syslog_server, commands, show_log="1")
|
||||
|
||||
funct.footer()
|
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env python3
|
||||
import html
|
||||
import cgi
|
||||
import os
|
||||
import funct
|
||||
import configparser
|
||||
from datetime import datetime
|
||||
from pytz import timezone
|
||||
import networkx as nx
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
form = cgi.FieldStorage()
|
||||
serv = form.getvalue('serv')
|
||||
servNew = form.getvalue('serNew')
|
||||
|
||||
funct.head("Show HAproxy config")
|
||||
funct.check_config()
|
||||
funct.check_login()
|
||||
|
||||
path_config = "haproxy-webintarface.config"
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path_config)
|
||||
time_zone = config.get('main', 'time_zone')
|
||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
|
||||
|
||||
if serv is not None:
|
||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||
now_utc = datetime.now(timezone(time_zone))
|
||||
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
|
||||
|
||||
funct.chooseServer("map.py#map", "Show HAproxy map", "n")
|
||||
|
||||
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
||||
print('<a name="map"></a>')
|
||||
print("<h3>Map from %s</h3><br />" % serv)
|
||||
|
||||
G = nx.DiGraph()
|
||||
|
||||
funct.get_config(serv, cfg)
|
||||
conf = open(cfg, "r")
|
||||
|
||||
node = ""
|
||||
line_new2 = [1,""]
|
||||
i = 1200
|
||||
k = 1200
|
||||
j = 0
|
||||
for line in conf:
|
||||
if "listen" in line or "frontend" in line or line.find("backend") == 0:
|
||||
if "stats" not in line:
|
||||
G.add_node(line,pos=(k,i),label_pos=(k,i+150))
|
||||
node = line
|
||||
i = i - 100
|
||||
if "server " in line or "use_backend" in line or "default_backend" in line:
|
||||
if "timeout" not in line and "default-server" not in line and "#use_backend" not in line:
|
||||
i = i - 300
|
||||
j = j + 1
|
||||
if "check" in line:
|
||||
line_new = line.split("check")
|
||||
else:
|
||||
line_new = line.split("if")
|
||||
if "server" in line:
|
||||
line_new1 = line_new[0].split("server")
|
||||
line_new[0] = line_new1[1]
|
||||
line_new2 = line_new[0].split(":")
|
||||
line_new[0] = line_new2[0]
|
||||
|
||||
line_new[0] = line_new[0].strip(' \t\n\r')
|
||||
line_new2[1] = line_new2[1].strip(' \t\n\r')
|
||||
if j % 2 == 0:
|
||||
G.add_node(line_new[0],pos=(k+250,i-350),label_pos=(k+225,i-100))
|
||||
else:
|
||||
G.add_node(line_new[0],pos=(k-250,i-50),label_pos=(k-225,i+180))
|
||||
if line_new2[1] != "":
|
||||
G.add_edge(node, line_new[0], port=line_new2[1])
|
||||
else:
|
||||
G.add_edge(node,line_new[0])
|
||||
|
||||
os.system("/bin/rm -f " + cfg)
|
||||
os.chdir("/var/www/haproxy-wi/cgi-bin/")
|
||||
|
||||
pos=nx.get_node_attributes(G,'pos')
|
||||
pos_label=nx.get_node_attributes(G,'label_pos')
|
||||
edge_labels = nx.get_edge_attributes(G,'port')
|
||||
|
||||
try:
|
||||
plt.figure(10,figsize=(9.5,15))
|
||||
nx.draw(G, pos, with_labels=False, font_weight='bold', width=3, alpha=0.1,linewidths=5)
|
||||
nx.draw_networkx_nodes(G,pos, node_color="skyblue", node_size=100, alpha=0.8, node_shape="p")
|
||||
nx.draw_networkx_edges(G,pos, width=0.5,alpha=0.5, edge_color="#5D9CEB",arrows=False)
|
||||
nx.draw_networkx_labels(G,pos=pos_label, alpha=1, font_color="green", font_size=10)
|
||||
nx.draw_networkx_edge_labels(G, pos,label_pos=0.5,font_color="blue", labels=edge_labels, font_size=8)
|
||||
|
||||
plt.savefig("map.png")
|
||||
plt.show()
|
||||
except Exception as e:
|
||||
print("!!! There was an issue, " + str(e))
|
||||
|
||||
commands = [ "mv /var/www/haproxy-wi/cgi-bin/map.png /var/www/haproxy-wi/" ]
|
||||
funct.ssh_command("localhost", commands)
|
||||
print('<img src="/map.png" alt="map">')
|
||||
|
||||
funct.footer()
|
Binary file not shown.
After Width: | Height: | Size: 255 KiB |
|
@ -15,6 +15,7 @@
|
|||
<a href="cgi-bin/overview.py" title="Server and service status">Overview</a> <br />
|
||||
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
|
||||
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
|
||||
<a href="cgi-bin/map.py" title="View map">Map</a> <br />
|
||||
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</a> <br />
|
||||
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
|
||||
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
|
||||
|
@ -23,7 +24,7 @@
|
|||
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
|
||||
<a href="cgi-bin/delver.py" title="Upload old config">Delete old config</a> <br />
|
||||
<div class="copyright">
|
||||
HAproxy Web Interface v1.6.3
|
||||
HAproxy Web Interface v1.7
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
@ -4,4 +4,8 @@ pytz==2017.3
|
|||
requests==2.18.4
|
||||
requests_toolbelt==0.8.0
|
||||
telegram==0.0.1
|
||||
dump==0.0.3
|
||||
dump==0.0.3
|
||||
networkx==2.1
|
||||
numpy==1.14.0
|
||||
matplotlib==2.1.2
|
||||
urllib3==1.22
|
Loading…
Reference in New Issue