mirror of https://github.com/Aidaho12/haproxy-wi
parent
59d5ea9913
commit
6eb68b1983
|
@ -432,7 +432,7 @@ def update_db_v_42(**kwargs):
|
||||||
|
|
||||||
def update_ver(**kwargs):
|
def update_ver(**kwargs):
|
||||||
con, cur = get_cur()
|
con, cur = get_cur()
|
||||||
sql = """update version set version = '4.1.0.0'; """
|
sql = """update version set version = '4.2.0.0'; """
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import cgi
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import funct
|
import funct
|
||||||
|
|
159
app/options.py
159
app/options.py
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-"
|
# -*- coding: utf-8 -*-
|
||||||
import os, sys
|
import os, sys
|
||||||
import funct
|
import funct
|
||||||
import sql
|
import sql
|
||||||
|
@ -595,10 +595,10 @@ if form.getvalue('servaction') is not None:
|
||||||
command = [ cmd ]
|
command = [ cmd ]
|
||||||
|
|
||||||
if enable != "show":
|
if enable != "show":
|
||||||
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><h3>You %s %s on HAproxy %s. <a href="viewsttats.py?serv=%s" title="View stat" target="_blank">Look it</a> or <a href="runtimeapi.py" title="RutimeAPI">Edit something else</a></h3><br />' % (enable, backend, serv, serv))
|
||||||
|
|
||||||
print(funct.ssh_command(serv, command, show_log="1"))
|
print(funct.ssh_command(serv, command, show_log="1"))
|
||||||
action = 'edit.py ' + enable + ' ' + backend
|
action = 'runtimeapi.py ' + enable + ' ' + backend
|
||||||
funct.logging(serv, action)
|
funct.logging(serv, action)
|
||||||
|
|
||||||
|
|
||||||
|
@ -641,13 +641,19 @@ if serv is not None and form.getvalue('right') is not None:
|
||||||
if serv is not None and act == "configShow":
|
if serv is not None and act == "configShow":
|
||||||
if form.getvalue('service') == 'keepalived':
|
if form.getvalue('service') == 'keepalived':
|
||||||
configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir')
|
configs_dir = funct.get_config_var('configs', 'kp_save_configs_dir')
|
||||||
|
cfg = '.conf'
|
||||||
elif form.getvalue('service') == 'nginx':
|
elif form.getvalue('service') == 'nginx':
|
||||||
configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir')
|
configs_dir = funct.get_config_var('configs', 'nginx_save_configs_dir')
|
||||||
|
cfg = '.conf'
|
||||||
else:
|
else:
|
||||||
configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||||||
|
cfg = '.cfg'
|
||||||
|
|
||||||
if form.getvalue('configver') is None:
|
if form.getvalue('configver') is None:
|
||||||
cfg = configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
|
cfg = configs_dir + serv + "-" + funct.get_data('config') + cfg
|
||||||
|
if form.getvalue('service') == 'nginx':
|
||||||
|
funct.get_config(serv, cfg, nginx=1)
|
||||||
|
else:
|
||||||
funct.get_config(serv, cfg)
|
funct.get_config(serv, cfg)
|
||||||
else:
|
else:
|
||||||
cfg = configs_dir + form.getvalue('configver')
|
cfg = configs_dir + form.getvalue('configver')
|
||||||
|
@ -842,6 +848,147 @@ if form.getvalue('masteradd'):
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
|
||||||
|
if form.getvalue('install_grafana'):
|
||||||
|
script = "install_grafana.sh"
|
||||||
|
proxy = sql.get_setting('proxy')
|
||||||
|
|
||||||
|
os.system("cp scripts/%s ." % script)
|
||||||
|
|
||||||
|
if proxy is not None and proxy != '' and proxy != 'None':
|
||||||
|
proxy_serv = proxy
|
||||||
|
else:
|
||||||
|
proxy_serv = ''
|
||||||
|
|
||||||
|
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv ]
|
||||||
|
|
||||||
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
if error:
|
||||||
|
funct.logging('localhost', error, haproxywi=1)
|
||||||
|
import socket
|
||||||
|
print('success: Grafana and Prometheus servers were installed. You can find Grafana on http://'+socket.gethostname()+':3000<br>')
|
||||||
|
else:
|
||||||
|
for l in output:
|
||||||
|
if "FAILED" in l:
|
||||||
|
try:
|
||||||
|
l = l.split(':')[1]
|
||||||
|
l = l.split('"')[1]
|
||||||
|
print(l+"<br>")
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print(output)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
import socket
|
||||||
|
print('success: Grafana and Prometheus servers were installed. You can find Grafana on http://'+socket.gethostname()+':3000<br>')
|
||||||
|
|
||||||
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
|
||||||
|
if form.getvalue('haproxy_exp_install'):
|
||||||
|
serv = form.getvalue('haproxy_exp_install')
|
||||||
|
script = "install_haproxy_exporter.sh"
|
||||||
|
stats_port = sql.get_setting('stats_port')
|
||||||
|
server_state_file = sql.get_setting('server_state_file')
|
||||||
|
stats_user = sql.get_setting('stats_user')
|
||||||
|
stats_password = sql.get_setting('stats_password')
|
||||||
|
stat_page = sql.get_setting('stats_page')
|
||||||
|
proxy = sql.get_setting('proxy')
|
||||||
|
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(serv)
|
||||||
|
|
||||||
|
if ssh_enable == 0:
|
||||||
|
ssh_key_name = ''
|
||||||
|
|
||||||
|
servers = sql.select_servers(server=serv)
|
||||||
|
for server in servers:
|
||||||
|
ssh_port = str(server[10])
|
||||||
|
|
||||||
|
os.system("cp scripts/%s ." % script)
|
||||||
|
|
||||||
|
if proxy is not None and proxy != '' and proxy != 'None':
|
||||||
|
proxy_serv = proxy
|
||||||
|
else:
|
||||||
|
proxy_serv = ''
|
||||||
|
|
||||||
|
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+
|
||||||
|
" STAT_PORT="+stats_port+" STAT_FILE="+server_state_file+
|
||||||
|
" SSH_PORT="+ssh_port+" STAT_PAGE="+stat_page+
|
||||||
|
" STATS_USER="+stats_user+" STATS_PASS="+stats_password+" HOST="+serv+
|
||||||
|
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
|
||||||
|
|
||||||
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
if error:
|
||||||
|
funct.logging('localhost', error, haproxywi=1)
|
||||||
|
print('error: '+error)
|
||||||
|
else:
|
||||||
|
for l in output:
|
||||||
|
if "msg" in l or "FAILED" in l:
|
||||||
|
try:
|
||||||
|
l = l.split(':')[1]
|
||||||
|
l = l.split('"')[1]
|
||||||
|
print(l+"<br>")
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print(output)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print('success: HAProxy exporter was installed<br>')
|
||||||
|
|
||||||
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
|
||||||
|
if form.getvalue('nginx_exp_install'):
|
||||||
|
serv = form.getvalue('nginx_exp_install')
|
||||||
|
script = "install_nginx_exporter.sh"
|
||||||
|
stats_user = sql.get_setting('nginx_stats_user')
|
||||||
|
stats_password = sql.get_setting('nginx_stats_password')
|
||||||
|
stats_port = sql.get_setting('nginx_stats_port')
|
||||||
|
stats_page = sql.get_setting('nginx_stats_page')
|
||||||
|
proxy = sql.get_setting('proxy')
|
||||||
|
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(serv)
|
||||||
|
|
||||||
|
if ssh_enable == 0:
|
||||||
|
ssh_key_name = ''
|
||||||
|
|
||||||
|
servers = sql.select_servers(server=serv)
|
||||||
|
for server in servers:
|
||||||
|
ssh_port = str(server[10])
|
||||||
|
|
||||||
|
os.system("cp scripts/%s ." % script)
|
||||||
|
|
||||||
|
if proxy is not None and proxy != '' and proxy != 'None':
|
||||||
|
proxy_serv = proxy
|
||||||
|
else:
|
||||||
|
proxy_serv = ''
|
||||||
|
|
||||||
|
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+
|
||||||
|
" STAT_PORT="+stats_port+" SSH_PORT="+ssh_port+" STAT_PAGE="+stats_page+
|
||||||
|
" STATS_USER="+stats_user+" STATS_PASS="+stats_password+" HOST="+serv+
|
||||||
|
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
|
||||||
|
|
||||||
|
output, error = funct.subprocess_execute(commands[0])
|
||||||
|
|
||||||
|
if error:
|
||||||
|
funct.logging('localhost', error, haproxywi=1)
|
||||||
|
print('error: '+error)
|
||||||
|
else:
|
||||||
|
for l in output:
|
||||||
|
if "msg" in l or "FAILED" in l:
|
||||||
|
try:
|
||||||
|
l = l.split(':')[1]
|
||||||
|
l = l.split('"')[1]
|
||||||
|
print(l+"<br>")
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print(output)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print('success: Nginx exporter was installed<br>')
|
||||||
|
|
||||||
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
|
||||||
if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupupdate'):
|
if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupupdate'):
|
||||||
server = form.getvalue('server')
|
server = form.getvalue('server')
|
||||||
rpath = form.getvalue('rpath')
|
rpath = form.getvalue('rpath')
|
||||||
|
@ -1013,6 +1160,10 @@ if form.getvalue('get_nginx_v'):
|
||||||
print(funct.ssh_command(serv, cmd))
|
print(funct.ssh_command(serv, cmd))
|
||||||
|
|
||||||
|
|
||||||
|
if form.getvalue('get_exporter_v'):
|
||||||
|
print(funct.check_service(serv, form.getvalue('get_exporter_v')))
|
||||||
|
|
||||||
|
|
||||||
if form.getvalue('bwlists'):
|
if form.getvalue('bwlists'):
|
||||||
list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+form.getvalue('color')+"/"+form.getvalue('bwlists')
|
list = os.path.dirname(os.getcwd())+"/"+sql.get_setting('lists_path')+"/"+form.getvalue('group')+"/"+form.getvalue('color')+"/"+form.getvalue('bwlists')
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
- hosts: localhost
|
||||||
|
become: yes
|
||||||
|
become_method: sudo
|
||||||
|
roles:
|
||||||
|
- role: cloudalchemy.prometheus
|
||||||
|
environment:
|
||||||
|
http_proxy: "{{PROXY}}"
|
||||||
|
https_proxy: "{{PROXY}}"
|
||||||
|
vars:
|
||||||
|
prometheus_targets:
|
||||||
|
node:
|
||||||
|
- targets:
|
||||||
|
- "{{ansible_hostname}}:9100"
|
||||||
|
|
||||||
|
- role: cloudalchemy.grafana
|
||||||
|
environment:
|
||||||
|
http_proxy: "{{PROXY}}"
|
||||||
|
https_proxy: "{{PROXY}}"
|
||||||
|
vars:
|
||||||
|
grafana_security:
|
||||||
|
admin_user: admin
|
||||||
|
admin_password: admin
|
||||||
|
grafana_datasources:
|
||||||
|
- name: prometheus
|
||||||
|
type: prometheus
|
||||||
|
url: "http://{{ansible_default_ipv4.address}}:9090"
|
||||||
|
basicAuth: false
|
||||||
|
grafana_dashboards:
|
||||||
|
- dashboard_id: 2428
|
||||||
|
revision_id: 7
|
||||||
|
datasource: prometheus
|
||||||
|
- dashboard_id: 11879
|
||||||
|
revision_id: 3
|
||||||
|
datasource: prometheus
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
- hosts: "{{ variable_host }}"
|
||||||
|
become: yes
|
||||||
|
become_method: sudo
|
||||||
|
tasks:
|
||||||
|
- name: Set SSH port
|
||||||
|
set_fact:
|
||||||
|
ansible_port: "{{SSH_PORT}}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: bdellegrazie.haproxy_exporter
|
||||||
|
vars:
|
||||||
|
haproxy_exporter_options: ['--haproxy.scrape-uri=http://{{STATS_USER}}:{{STATS_PASS}}@{{variable_host}}:{{STAT_PORT}}/{{STAT_PAGE}};csv']
|
|
@ -0,0 +1,15 @@
|
||||||
|
- hosts: "{{ variable_host }}"
|
||||||
|
become: yes
|
||||||
|
become_method: sudo
|
||||||
|
tasks:
|
||||||
|
- name: Set SSH port
|
||||||
|
set_fact:
|
||||||
|
ansible_port: "{{SSH_PORT}}"
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: bdellegrazie.nginx_exporter
|
||||||
|
environment:
|
||||||
|
http_proxy: "{{PROXY}}"
|
||||||
|
https_proxy: "{{PROXY}}"
|
||||||
|
vars:
|
||||||
|
nginx_exporter_options: ['-nginx.scrape-uri http://{{STATS_USER}}:{{STATS_PASS}}@{{variable_host}}:{{STAT_PORT}}/{{STAT_PAGE}}']
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
for ARGUMENT in "$@"
|
||||||
|
do
|
||||||
|
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
||||||
|
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
|
||||||
|
|
||||||
|
case "$KEY" in
|
||||||
|
PROXY) PROXY=${VALUE} ;;
|
||||||
|
*)
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/cloudalchemy.grafana" ]; then
|
||||||
|
if [ ! -z $PROXY ];then
|
||||||
|
export https_proxy="$PROXY"
|
||||||
|
export http_proxy="$PROXY"
|
||||||
|
fi
|
||||||
|
ansible-galaxy install cloudalchemy.grafana --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/cloudalchemy.prometheus" ]; then
|
||||||
|
if [ ! -z $PROXY ];then
|
||||||
|
export https_proxy="$PROXY"
|
||||||
|
export http_proxy="$PROXY"
|
||||||
|
fi
|
||||||
|
ansible-galaxy install cloudalchemy.prometheus --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/
|
||||||
|
fi
|
||||||
|
|
||||||
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||||
|
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
|
||||||
|
export ACTION_WARNINGS=False
|
||||||
|
export LOCALHOST_WARNING=False
|
||||||
|
export COMMAND_WARNINGS=False
|
||||||
|
|
||||||
|
PWD=`pwd`
|
||||||
|
PWD=$PWD/scripts/ansible/
|
||||||
|
|
||||||
|
ansible-playbook $PWD/roles/grafana.yml -e "PROXY=$PROXY"
|
||||||
|
|
||||||
|
if [ $? -gt 0 ]
|
||||||
|
then
|
||||||
|
echo "error: Can't install Grafana and Prometheus services <br /><br />"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! sudo grep -Fxq " - job_name: proxy" /etc/prometheus/prometheus.yml; then
|
||||||
|
sudo echo " - job_name: proxy" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
sudo echo " metrics_path: /metrics" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
sudo echo " static_configs:" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
sudo echo " - targets:" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
fi
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/bin/bash
|
||||||
|
for ARGUMENT in "$@"
|
||||||
|
do
|
||||||
|
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
||||||
|
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
|
||||||
|
|
||||||
|
case "$KEY" in
|
||||||
|
PROXY) PROXY=${VALUE} ;;
|
||||||
|
HOST) HOST=${VALUE} ;;
|
||||||
|
USER) USER=${VALUE} ;;
|
||||||
|
PASS) PASS=${VALUE} ;;
|
||||||
|
KEY) KEY=${VALUE} ;;
|
||||||
|
STAT_PORT) STAT_PORT=${VALUE} ;;
|
||||||
|
STAT_PAGE) STAT_PAGE=${VALUE} ;;
|
||||||
|
STATS_USER) STATS_USER=${VALUE} ;;
|
||||||
|
STATS_PASS) STATS_PASS=${VALUE} ;;
|
||||||
|
SSH_PORT) SSH_PORT=${VALUE} ;;
|
||||||
|
*)
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/bdellegrazie.haproxy_exporter" ]; then
|
||||||
|
if [ ! -z $PROXY ];then
|
||||||
|
export https_proxy="$PROXY"
|
||||||
|
export http_proxy="$PROXY"
|
||||||
|
fi
|
||||||
|
ansible-galaxy install bdellegrazie.haproxy_exporter --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/
|
||||||
|
fi
|
||||||
|
|
||||||
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||||
|
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
|
||||||
|
export ACTION_WARNINGS=False
|
||||||
|
export ANSIBLE_DEPRECATION_WARNINGS=False
|
||||||
|
PWD=`pwd`
|
||||||
|
PWD=$PWD/scripts/ansible/
|
||||||
|
echo $HOST > $PWD/$HOST
|
||||||
|
|
||||||
|
if [[ $KEY == "" ]]; then
|
||||||
|
ansible-playbook $PWD/roles/haproxy_exporter.yml -e "ansible_user=$USER ansible_ssh_pass=$PASS variable_host=$HOST PROXY=$PROXY STAT_PAGE=$STAT_PAGE STAT_PORT=$STAT_PORT STATS_USER=$STATS_USER STATS_PASS=$STATS_PASS SSH_PORT=$SSH_PORT" -i $PWD/$HOST
|
||||||
|
else
|
||||||
|
ansible-playbook $PWD/roles/haproxy_exporter.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST PROXY=$PROXY STAT_PAGE=$STAT_PAGE STAT_PORT=$STAT_PORT STATS_USER=$STATS_USER STATS_PASS=$STATS_PASS SSH_PORT=$SSH_PORT" -i $PWD/$HOST
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $? -gt 0 ]
|
||||||
|
then
|
||||||
|
echo "error: Can't install HAProxy exporter <br /><br />"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo grep -Fxq " - $HOST:9101" /etc/prometheus/prometheus.yml; then
|
||||||
|
sudo echo " - $HOST:9101" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo systemctl reload prometheus
|
||||||
|
rm -f $PWD/$HOST
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/bin/bash
|
||||||
|
for ARGUMENT in "$@"
|
||||||
|
do
|
||||||
|
KEY=$(echo $ARGUMENT | cut -f1 -d=)
|
||||||
|
VALUE=$(echo $ARGUMENT | cut -f2 -d=)
|
||||||
|
|
||||||
|
case "$KEY" in
|
||||||
|
PROXY) PROXY=${VALUE} ;;
|
||||||
|
HOST) HOST=${VALUE} ;;
|
||||||
|
USER) USER=${VALUE} ;;
|
||||||
|
PASS) PASS=${VALUE} ;;
|
||||||
|
KEY) KEY=${VALUE} ;;
|
||||||
|
STAT_PORT) STAT_PORT=${VALUE} ;;
|
||||||
|
STAT_PAGE) STAT_PAGE=${VALUE} ;;
|
||||||
|
STATS_USER) STATS_USER=${VALUE} ;;
|
||||||
|
STATS_PASS) STATS_PASS=${VALUE} ;;
|
||||||
|
SSH_PORT) SSH_PORT=${VALUE} ;;
|
||||||
|
*)
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "/var/www/haproxy-wi/app/scripts/ansible/roles/bdellegrazie.nginx_exporter" ]; then
|
||||||
|
if [ ! -z $PROXY ];then
|
||||||
|
export https_proxy="$PROXY"
|
||||||
|
export http_proxy="$PROXY"
|
||||||
|
fi
|
||||||
|
ansible-galaxy install bdellegrazie.nginx_exporter --roles-path /var/www/haproxy-wi/app/scripts/ansible/roles/
|
||||||
|
fi
|
||||||
|
|
||||||
|
export ANSIBLE_HOST_KEY_CHECKING=False
|
||||||
|
export ANSIBLE_DISPLAY_SKIPPED_HOSTS=False
|
||||||
|
export ACTION_WARNINGS=False
|
||||||
|
export ANSIBLE_DEPRECATION_WARNINGS=False
|
||||||
|
PWD=`pwd`
|
||||||
|
PWD=$PWD/scripts/ansible/
|
||||||
|
echo $HOST > $PWD/$HOST
|
||||||
|
|
||||||
|
if [[ $KEY == "" ]]; then
|
||||||
|
ansible-playbook $PWD/roles/nginx_exporter.yml -e "ansible_user=$USER ansible_ssh_pass=$PASS variable_host=$HOST PROXY=$PROXY STAT_PAGE=$STAT_PAGE STAT_PORT=$STAT_PORT STATS_USER=$STATS_USER STATS_PASS=$STATS_PASS SSH_PORT=$SSH_PORT" -i $PWD/$HOST
|
||||||
|
else
|
||||||
|
ansible-playbook $PWD/roles/nginx_exporter.yml --key-file $KEY -e "ansible_user=$USER variable_host=$HOST PROXY=$PROXY STAT_PAGE=$STAT_PAGE STAT_PORT=$STAT_PORT STATS_USER=$STATS_USER STATS_PASS=$STATS_PASS SSH_PORT=$SSH_PORT" -i $PWD/$HOST
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $? -gt 0 ]
|
||||||
|
then
|
||||||
|
echo "error: Can't install Nginx exporter <br /><br />"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo grep -Fxq " - $HOST:9113" /etc/prometheus/prometheus.yml; then
|
||||||
|
sudo echo " - $HOST:9113" | sudo tee -a /etc/prometheus/prometheus.yml > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo systemctl reload prometheus
|
||||||
|
rm -f $PWD/$HOST
|
|
@ -134,11 +134,11 @@ EOF
|
||||||
sudo mv /tmp/modsecurity.conf $HAPROXY_PATH/waf/modsecurity.conf
|
sudo mv /tmp/modsecurity.conf $HAPROXY_PATH/waf/modsecurity.conf
|
||||||
wget -O /tmp/unicode.mapping https://github.com/SpiderLabs/ModSecurity/raw/v2/master/unicode.mapping
|
wget -O /tmp/unicode.mapping https://github.com/SpiderLabs/ModSecurity/raw/v2/master/unicode.mapping
|
||||||
sudo mv /tmp/unicode.mapping $HAPROXY_PATH/waf/unicode.mapping
|
sudo mv /tmp/unicode.mapping $HAPROXY_PATH/waf/unicode.mapping
|
||||||
wget -O /tmp/owasp.tar.gz https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/v3.0.2.tar.gz
|
wget -O /tmp/owasp.tar.gz https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/2.2.9.tar.gz
|
||||||
cd /tmp/
|
cd /tmp/
|
||||||
sudo tar xf /tmp/owasp.tar.gz
|
sudo tar xf /tmp/owasp.tar.gz
|
||||||
sudo mv /tmp/owasp-modsecurity-crs-3.0.2/crs-setup.conf.example $HAPROXY_PATH/waf/rules/modsecurity_crs_10_setup.conf
|
sudo mv /tmp/owasp-modsecurity-crs-2.2.9/modsecurity_crs_10_setup.conf.example $HAPROXY_PATH/waf/rules/modsecurity_crs_10_setup.conf
|
||||||
sudo mv /tmp/owasp-modsecurity-crs-3.0.2/*rules/* $HAPROXY_PATH/waf/rules/
|
sudo mv /tmp/owasp-modsecurity-crs-2.2.9/*rules/* $HAPROXY_PATH/waf/rules/
|
||||||
sudo sed -i 's/#SecAction/SecAction/' $HAPROXY_PATH/waf/rules/modsecurity_crs_10_setup.conf
|
sudo sed -i 's/#SecAction/SecAction/' $HAPROXY_PATH/waf/rules/modsecurity_crs_10_setup.conf
|
||||||
sudo sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' $HAPROXY_PATH/waf/modsecurity.conf
|
sudo sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' $HAPROXY_PATH/waf/modsecurity.conf
|
||||||
sudo sed -i 's/SecAuditLogParts ABIJDEFHZ/SecAuditLogParts ABIJDEH/' $HAPROXY_PATH/waf/modsecurity.conf
|
sudo sed -i 's/SecAuditLogParts ABIJDEFHZ/SecAuditLogParts ABIJDEH/' $HAPROXY_PATH/waf/modsecurity.conf
|
||||||
|
|
|
@ -12,6 +12,7 @@ funct.page_for_admin(level = 2)
|
||||||
try:
|
try:
|
||||||
user, user_id, role, token, servers = funct.get_users_params()
|
user, user_id, role, token, servers = funct.get_users_params()
|
||||||
ldap_enable = sql.get_setting('ldap_enable')
|
ldap_enable = sql.get_setting('ldap_enable')
|
||||||
|
grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -30,5 +31,6 @@ output_from_parsed_template = template.render(title = "Servers manage",
|
||||||
token = token,
|
token = token,
|
||||||
versions = funct.versions(),
|
versions = funct.versions(),
|
||||||
backups = sql.select_backups(),
|
backups = sql.select_backups(),
|
||||||
|
grafana = ''.join(grafana),
|
||||||
ldap_enable = ldap_enable)
|
ldap_enable = ldap_enable)
|
||||||
print(output_from_parsed_template)
|
print(output_from_parsed_template)
|
||||||
|
|
|
@ -2,25 +2,14 @@
|
||||||
<h4>Config from {{serv}}</h4>
|
<h4>Config from {{serv}}</h4>
|
||||||
<p class="accordion-expand-holder">
|
<p class="accordion-expand-holder">
|
||||||
{% if role %}
|
{% if role %}
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" href="config.py?serv={{serv}}&open=open">Edit</a>
|
<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" href="config.py?service={{service}}&serv={{serv}}&open=open">Edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if service != 'keepalived' and service != 'nginx' %}
|
|
||||||
<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>
|
<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>
|
||||||
<button id="raw">Raw</button>
|
<button id="raw">Raw</button>
|
||||||
<button id="according" style="display: none;">According</button>
|
<button id="according" style="display: none;">According</button>
|
||||||
{% endif %}
|
|
||||||
</p>
|
</p>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
{% if service == 'nginx' %}
|
|
||||||
<div style="margin-left: 20%; border: 1px solid #ddd; padding-left: 50px; width: 60%;">
|
|
||||||
<pre>
|
|
||||||
{%- for line in conf -%}
|
|
||||||
{{ line }}
|
|
||||||
{% endfor %}
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
<div style="margin-left: 16%" class="configShow">
|
<div style="margin-left: 16%" class="configShow">
|
||||||
{% set i = 0 -%}
|
{% set i = 0 -%}
|
||||||
{% set section_name = {} %}
|
{% set section_name = {} %}
|
||||||
|
@ -36,6 +25,42 @@
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if service == 'nginx' %}
|
||||||
|
{%- if "server {" in line -%}
|
||||||
|
{% if i > 1 %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<span class="param">{{ line }}
|
||||||
|
</span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if "listen " in line or "location" in line or "server_name" in line or "}" in line %}
|
||||||
|
{% if "#" not in line %}
|
||||||
|
<span class="numRow">
|
||||||
|
{{ i }}
|
||||||
|
</span>
|
||||||
|
<span class="paramInSec">
|
||||||
|
 {{ line }}
|
||||||
|
</span><br />
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% if "#" in line %}
|
||||||
|
<span class="numRow">
|
||||||
|
{{ i }}
|
||||||
|
</span>
|
||||||
|
<span class="comment">
|
||||||
|
 {{ line }}
|
||||||
|
</span><br />
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line|length > 1 %}
|
||||||
|
<span class="configLine">
|
||||||
|
<span class="numRow">{{ i }}</span>
|
||||||
|
  {{ line }}
|
||||||
|
</span><br />
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
{% if line.startswith('global') %}
|
{% if line.startswith('global') %}
|
||||||
<span class="param">{{ line }}
|
<span class="param">{{ line }}
|
||||||
{% if role %}
|
{% if role %}
|
||||||
|
@ -148,20 +173,20 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if "acl" in line or "option" in line or "server" in line %}
|
{% if "acl" in line or "option" in line or "server" in line %}
|
||||||
{% if "timeout" not in line and "default-server" not in line and "#use_backend" not in line and "#" not in line%}
|
{% if "timeout" not in line and "default-server" not in line and "#use_backend" not in line and "#" not in line%}
|
||||||
<span class="paramInSec">
|
|
||||||
<span class="numRow">
|
<span class="numRow">
|
||||||
{{ i }}
|
{{ i }}
|
||||||
</span>
|
</span>
|
||||||
|
<span class="paramInSec">
|
||||||
{{ line }}
|
{{ line }}
|
||||||
</span><br />
|
</span><br />
|
||||||
{% continue %}
|
{% continue %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if line.startswith("#") %}
|
{% if line.startswith("#") %}
|
||||||
<span class="comment">
|
|
||||||
<span class="numRow">
|
<span class="numRow">
|
||||||
{{ i }}
|
{{ i }}
|
||||||
</span>
|
</span>
|
||||||
|
<span class="comment">
|
||||||
{{ line }}
|
{{ line }}
|
||||||
</span><br />
|
</span><br />
|
||||||
{% continue %}
|
{% continue %}
|
||||||
|
@ -179,10 +204,10 @@
|
||||||
$('#{{-section_name[k]|replace("\n", "")-}}').html('<a href="http://{{-serv-}}:{{-bind[1]|replace("\n", "")-}}" title="Open {{serv-}}:{{-bind[1]|replace("\n", "")-}}" target="_blank">Open</a>')
|
$('#{{-section_name[k]|replace("\n", "")-}}').html('<a href="http://{{-serv-}}:{{-bind[1]|replace("\n", "")-}}" title="Open {{serv-}}:{{-bind[1]|replace("\n", "")-}}" target="_blank">Open</a>')
|
||||||
</script>
|
</script>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
{% if configver %}
|
{% if configver %}
|
||||||
<br>
|
<br>
|
||||||
<center>
|
<center>
|
||||||
|
|
|
@ -17,13 +17,10 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
{% if service != 'keepalived' and service != 'nginx'%}
|
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="Show running config" onclick="showConfig()">Open</a>
|
<a class="ui-button ui-widget ui-corner-all" title="Show running config" onclick="showConfig()">Open</a>
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="Show map" onclick="showMap()">Map</a>
|
|
||||||
{% endif %}
|
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="View stat" onclick="openStats()">Stat</a>
|
<a class="ui-button ui-widget ui-corner-all" title="View stat" onclick="openStats()">Stat</a>
|
||||||
{% if role <= 2 and service == 'nginx'%}
|
{% if service != 'keepalived' and service != 'nginx'%}
|
||||||
<button type="submit" value="open" name="open" class="btn btn-default" title="Edit running config">Edit</button>
|
<a class="ui-button ui-widget ui-corner-all" title="Show map" onclick="showMap()">Map</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if service != 'keepalived' %}
|
{% if service != 'keepalived' %}
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="Compare configs" onclick="showCompareConfigs()">Compare</a>
|
<a class="ui-button ui-widget ui-corner-all" title="Compare configs" onclick="showCompareConfigs()">Compare</a>
|
||||||
|
@ -85,7 +82,7 @@
|
||||||
if (cur_url[1].split('&')[1] == 'showCompare' || cur_url[1].split('&')[2] == 'showCompare') {
|
if (cur_url[1].split('&')[1] == 'showCompare' || cur_url[1].split('&')[2] == 'showCompare') {
|
||||||
showCompareConfigs();
|
showCompareConfigs();
|
||||||
}
|
}
|
||||||
if (cur_url[1].split('&')[1] == 'showConfig') {
|
if (cur_url[1].split('&')[2] == 'showConfig') {
|
||||||
showConfig();
|
showConfig();
|
||||||
}
|
}
|
||||||
$('textarea').linenumbers({col_width: '25px'});
|
$('textarea').linenumbers({col_width: '25px'});
|
||||||
|
|
|
@ -152,11 +152,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="server-act-links">
|
<div class="server-act-links">
|
||||||
{% if service != 'nginx' %}
|
<a href="/app/config.py?service={{service}}&serv={{s.2}}&showConfig" class="ui-button ui-widget ui-corner-all" title="Open running config">Open</a>
|
||||||
<a href="/app/config.py?serv={{s.2}}&showConfig" class="ui-button ui-widget ui-corner-all" title="Open running config">Open</a>
|
|
||||||
{% else %}
|
|
||||||
<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" href="config.py?service={{service}}&serv={{s.2}}&open=open">Edit</a>
|
|
||||||
{% endif %}
|
|
||||||
<a href="/app/config.py?service={{service}}&serv={{s.2}}&showCompare" class="ui-button ui-widget ui-corner-all" title="Compare configs">Compare</a>
|
<a href="/app/config.py?service={{service}}&serv={{s.2}}&showCompare" class="ui-button ui-widget ui-corner-all" title="Compare configs">Compare</a>
|
||||||
{% if service != 'nginx' %}
|
{% if service != 'nginx' %}
|
||||||
<a href="/app/config.py?serv={{s.2}}&showMap" class="ui-button ui-widget ui-corner-all" title="Show map">Map</a>
|
<a href="/app/config.py?serv={{s.2}}&showMap" class="ui-button ui-widget ui-corner-all" title="Show map">Map</a>
|
||||||
|
|
|
@ -277,8 +277,8 @@
|
||||||
<caption><h3>Install HAProxy</h3></caption>
|
<caption><h3>Install HAProxy</h3></caption>
|
||||||
<tr class="overviewHead">
|
<tr class="overviewHead">
|
||||||
<td class="padding10 first-collumn">Current version</td>
|
<td class="padding10 first-collumn">Current version</td>
|
||||||
<td class="padding10 first-collumn" style="width: 25%;">Available Versions</td>
|
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||||
<td class="padding10 first-collumn" style="width: 35%;">Server</td>
|
<td class="padding10 first-collumn" style="width: 30%;">Server</td>
|
||||||
<td>SYN flood protect</td>
|
<td>SYN flood protect</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -310,8 +310,8 @@
|
||||||
<caption><h3>Install Nginx</h3></caption>
|
<caption><h3>Install Nginx</h3></caption>
|
||||||
<tr class="overviewHead">
|
<tr class="overviewHead">
|
||||||
<td class="padding10 first-collumn">Current version</td>
|
<td class="padding10 first-collumn">Current version</td>
|
||||||
<td class="padding10 first-collumn" style="width: 25%;">Available Versions</td>
|
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||||
<td class="padding10 first-collumn" style="width: 35%;">Server</td>
|
<td class="padding10 first-collumn" style="width: 30%;">Server</td>
|
||||||
<td>SYN flood protect</td>
|
<td>SYN flood protect</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -337,6 +337,99 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<table>
|
||||||
|
<caption><h3>Install Grafana and Prometheus servers</h3></caption>
|
||||||
|
<tr class="overviewHead">
|
||||||
|
<td class="padding10 first-collumn">Current instalation</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Note</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td id="cur_grafana_ver" class="padding10 first-collumn">
|
||||||
|
{% if grafana == "Active:" %}
|
||||||
|
Grafana and Prometheus servers have already installed
|
||||||
|
{% else %}
|
||||||
|
There are no Grafana and Prometheus servers
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 20%;">
|
||||||
|
HAProxy-WI will try to install the latest Grafana and Prometheus server versions
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn">
|
||||||
|
Before Install any Exporters install Grafana and Prometheus servers first
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% if grafana != "Active:" %}
|
||||||
|
<a class="ui-button ui-widget ui-corner-all" id="grafna_install" title="Install Grafana and Prometheus server">Install</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<table>
|
||||||
|
<caption><h3>Install HAProxy Exporter</h3></caption>
|
||||||
|
<tr class="overviewHead">
|
||||||
|
<td class="padding10 first-collumn">Current instalation</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Server</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td id="cur_haproxy_exp_ver" class="padding10 first-collumn">
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 20%;">
|
||||||
|
HAProxy-WI will try to install the latest HAProxy Exporter version
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn">
|
||||||
|
<select autofocus required name="haproxy_exp_addserv" id="haproxy_exp_addserv">
|
||||||
|
<option disabled selected>Choose server</option>
|
||||||
|
{% for select in servers %}
|
||||||
|
<option value="{{ select.2 }}">{{ select.1 }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="ui-button ui-widget ui-corner-all" id="haproxy_exp_install" title="Install HAProxy Exporter">Install</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<table>
|
||||||
|
<caption><h3>Install Nginx Exporter</h3></caption>
|
||||||
|
<tr class="overviewHead">
|
||||||
|
<td class="padding10 first-collumn">Current instalation</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Available Versions</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 30%;">Server</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td id="cur_nginx_exp_ver" class="padding10 first-collumn">
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn" style="width: 20%;">
|
||||||
|
HAProxy-WI will try to install the latest Nginx Exporter version
|
||||||
|
</td>
|
||||||
|
<td class="padding10 first-collumn">
|
||||||
|
<select autofocus required name="nginx_exp_addserv" id="nginx_exp_addserv">
|
||||||
|
<option disabled selected>Choose server</option>
|
||||||
|
{% for select in servers %}
|
||||||
|
<option value="{{ select.2 }}">{{ select.1 }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="ui-button ui-widget ui-corner-all" id="nginx_exp_install" title="Install Nginx Exporter">Install</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<div id="ajax"></div>
|
<div id="ajax"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -469,6 +562,8 @@
|
||||||
$('#hapver').selectmenu('enable');
|
$('#hapver').selectmenu('enable');
|
||||||
$('#haproxyaddserv').selectmenu('enable');
|
$('#haproxyaddserv').selectmenu('enable');
|
||||||
$('#nginxaddserv').selectmenu('enable');
|
$('#nginxaddserv').selectmenu('enable');
|
||||||
|
$('#haproxy_exp_addserv').selectmenu('enable');
|
||||||
|
$('#nginx_exp_addserv').selectmenu('enable');
|
||||||
$('#syn_flood').checkboxradio('enable');
|
$('#syn_flood').checkboxradio('enable');
|
||||||
$('#nginx_syn_flood').checkboxradio('enable');
|
$('#nginx_syn_flood').checkboxradio('enable');
|
||||||
}, 500 );
|
}, 500 );
|
||||||
|
|
Loading…
Reference in New Issue