mirror of https://github.com/Aidaho12/haproxy-wi
parent
b92b3ea34a
commit
05fe5a64d5
|
@ -31,19 +31,6 @@ try:
|
|||
except:
|
||||
pass
|
||||
|
||||
def get_files():
|
||||
import glob
|
||||
file = set()
|
||||
return_files = set()
|
||||
for files in glob.glob(os.path.join(hap_configs_dir,'*.cfg')):
|
||||
file.add(files.split('/')[6])
|
||||
files = sorted(file, reverse=True)
|
||||
for file in files:
|
||||
ip = file.split("-")
|
||||
if serv == ip[0]:
|
||||
return_files.add(file)
|
||||
return sorted(return_files, reverse=True)
|
||||
|
||||
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||
configver = form.getvalue('configver')
|
||||
configver = hap_configs_dir + configver
|
||||
|
@ -68,7 +55,7 @@ output_from_parsed_template = template.render(h2 = 1, title = "Old Versions HAPr
|
|||
user = user,
|
||||
select_id = "serv",
|
||||
serv = serv,
|
||||
return_files = get_files(),
|
||||
return_files = funct.get_files(),
|
||||
aftersave = aftersave,
|
||||
config = config_read,
|
||||
configver = configver,
|
||||
|
|
21
app/funct.py
21
app/funct.py
|
@ -69,7 +69,7 @@ def telegram_send_mess(mess, **kwargs):
|
|||
import sql
|
||||
|
||||
telegrams = sql.get_telegram_by_ip(kwargs.get('ip'))
|
||||
|
||||
|
||||
for telegram in telegrams:
|
||||
token_bot = telegram[1]
|
||||
channel_name = telegram[2]
|
||||
|
@ -78,8 +78,12 @@ def telegram_send_mess(mess, **kwargs):
|
|||
|
||||
if proxy is not None:
|
||||
apihelper.proxy = {'https': proxy}
|
||||
bot = telebot.TeleBot(token=token_bot)
|
||||
bot.send_message(chat_id=channel_name, text=mess)
|
||||
try:
|
||||
bot = telebot.TeleBot(token=token_bot)
|
||||
bot.send_message(chat_id=channel_name, text=mess)
|
||||
except:
|
||||
print("Fatal: Can't send message. Add Telegram chanel before use alerting at this servers group")
|
||||
sys.exit()
|
||||
|
||||
def check_login(**kwargs):
|
||||
import sql
|
||||
|
@ -130,13 +134,7 @@ def page_for_admin(**kwargs):
|
|||
print('<meta http-equiv="refresh" content="10; url=/">')
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
def get_button(button, **kwargs):
|
||||
value = kwargs.get("value")
|
||||
if value is None:
|
||||
value = ""
|
||||
print('<button type="submit" value="%s" name="%s" class="btn btn-default">%s</button>' % (value, value, button))
|
||||
|
||||
|
||||
def ssh_connect(serv, **kwargs):
|
||||
import sql
|
||||
fullpath = get_config_var('main', 'fullpath')
|
||||
|
@ -529,4 +527,5 @@ def get_files():
|
|||
ip = file.split("-")
|
||||
if serv == ip[0]:
|
||||
return_files.add(file)
|
||||
return sorted(return_files, reverse=True)
|
||||
return sorted(return_files, reverse=True)
|
||||
|
|
@ -268,9 +268,6 @@ if serv is not None and form.getvalue('right') is not None:
|
|||
ovw.comapre_show()
|
||||
|
||||
if serv is not None and act == "configShow":
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pytz import timezone
|
||||
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||||
|
||||
if form.getvalue('configver') is None:
|
||||
|
@ -296,8 +293,8 @@ if serv is not None and act == "configShow":
|
|||
print('<input type="hidden" value="%s" name="configver">' % form.getvalue('configver'))
|
||||
print('<input type="hidden" value="1" name="config">')
|
||||
if form.getvalue('view') is None:
|
||||
funct.get_button("Just save", value="save")
|
||||
funct.get_button("Upload and restart")
|
||||
print("<button type='submit' value='save' name='save' class='btn btn-default'>Just save</button>")
|
||||
print("<button type='submit' value='' name='' class='btn btn-default'>Upload and restart</button>")
|
||||
print('</form></center>')
|
||||
|
||||
if form.getvalue('master'):
|
||||
|
|
|
@ -33,7 +33,8 @@ then
|
|||
sudo yum install haproxy socat -y > /dev/null
|
||||
fi
|
||||
fi
|
||||
echo "" > /etc/haproxy/haproxy.cfg
|
||||
|
||||
sudo echo "" > /etc/haproxy/haproxy.cfg
|
||||
sudo bash -c cat << EOF > /etc/haproxy/haproxy.cfg
|
||||
global
|
||||
log 127.0.0.1 local2
|
||||
|
|
27
install.sh
27
install.sh
|
@ -161,6 +161,10 @@ Type=simple
|
|||
WorkingDirectory=/var/www/$HOME_HAPROXY_WI
|
||||
ExecStart=/var/www/$HOME_HAPROXY_WI/tools/checker_master.py
|
||||
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
SyslogIdentifier=checker
|
||||
|
||||
RestartSec=2s
|
||||
Restart=on-failure
|
||||
TimeoutStopSec=1s
|
||||
|
@ -169,8 +173,29 @@ TimeoutStopSec=1s
|
|||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
cat << EOF > /etc/rsyslog.d/checker.conf
|
||||
if $programname startswith 'checker' then /var/www/$HOME_HAPROXY_WI/log/checker-error.log
|
||||
& stop
|
||||
EOF
|
||||
|
||||
cat << EOF > /etc/logrotate.d/checker
|
||||
/var/www/$HOME_HAPROXY_WI/log/checker-error.log {
|
||||
daily
|
||||
rotate 10
|
||||
missingok
|
||||
notifempty
|
||||
sharedscripts
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
sed -i 's/#$UDPServerRun 514/$UDPServerRun 514/g' /etc/rsyslog.conf
|
||||
sed -i 's/#$ModLoad imudp/$ModLoad imudp/g' /etc/rsyslog.conf
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl start checker_haproxy.service
|
||||
systemctl restart logrotate
|
||||
systemctl restart rsyslog
|
||||
systemctl restart checker_haproxy.service
|
||||
systemctl enable checker_haproxy.service
|
||||
|
||||
if hash apt-get 2>/dev/null; then
|
||||
|
|
37
update.sh
37
update.sh
|
@ -9,18 +9,22 @@ mkdir keys
|
|||
mkdir app/certs
|
||||
chmod +x app/*py
|
||||
chmod +x app/tools/*py
|
||||
chown -R apache:apache *
|
||||
|
||||
|
||||
cat << EOF > /etc/systemd/system/multi-user.target.wants/checker_haproxy.service
|
||||
|
||||
at << EOF > /etc/systemd/system/multi-user.target.wants/checker_haproxy.service
|
||||
[Unit]
|
||||
Description=Haproxy backends state checker
|
||||
After=syslog.target network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=/var/www/haproxy-wi/app/
|
||||
ExecStart=/var/www/haproxy-wi/app/tools/checker_master.py
|
||||
WorkingDirectory=$(pwd)/app
|
||||
ExecStart=$(pwd)/app/tools/checker_master.py
|
||||
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
SyslogIdentifier=checker
|
||||
|
||||
RestartSec=2s
|
||||
Restart=on-failure
|
||||
|
@ -30,10 +34,33 @@ TimeoutStopSec=1s
|
|||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
cat << EOF > /etc/rsyslog.d/checker.conf
|
||||
if $programname startswith 'checker' then $(pwd)/log/checker-error.log
|
||||
& stop
|
||||
EOF
|
||||
|
||||
cat << EOF > /etc/logrotate.d/checker
|
||||
$(pwd)/log/checker-error.log {
|
||||
daily
|
||||
rotate 10
|
||||
missingok
|
||||
notifempty
|
||||
sharedscripts
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
sed -i 's/#$UDPServerRun 514/$UDPServerRun 514/g' /etc/rsyslog.conf
|
||||
sed -i 's/#$ModLoad imudp/$ModLoad imudp/g' /etc/rsyslog.conf
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl start checker_haproxy.service
|
||||
systemctl restart logrotate
|
||||
systemctl restart rsyslog
|
||||
systemctl restart checker_haproxy.service
|
||||
systemctl enable checker_haproxy.service
|
||||
|
||||
chown -R apache:apache *
|
||||
|
||||
cd app/
|
||||
./update_db.py
|
||||
|
||||
|
|
Loading…
Reference in New Issue