remove other than hooks

This commit is contained in:
Your Name 2024-02-28 11:44:32 +05:00
parent c871e4d99d
commit 4f663bb7a5
6 changed files with 0 additions and 262 deletions

View File

@ -1,68 +0,0 @@
#!/bin/bash
# Define variables for easier modifications and readability
GIT_REPO="https://git.maxprint.io/MaxApex/ticket_ai_flask_app.git"
APP_DIR="/opt/ticket-ai"
VENV_DIR="$APP_DIR/venv"
SERVICE_FILE="/etc/systemd/system/ticket-ai.service"
PYTHON_BIN="$VENV_DIR/bin/python3"
ACTIVATE_SCRIPT="$VENV_DIR/bin/activate"
IPTABLES_RULES=("83.136.253.122") # Add IPs as needed
# Ensure the script is run as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Installing git
yum install -y git || { echo "Failed to install git. Exiting."; exit 1; }
# Clone the repository if it doesn't exist
if [ ! -d "$APP_DIR" ]; then
git clone $GIT_REPO $APP_DIR || { echo "Failed to clone repository. Exiting."; exit 1; }
else
echo "$APP_DIR already exists. Skipping clone."
fi
# Navigate to the repo directory
cd $APP_DIR || { echo "Failed to navigate to $APP_DIR. Exiting."; exit 1; }
# Create virtual environment if it doesn't exist
if [ ! -d "$VENV_DIR" ]; then
python3 -m venv $VENV_DIR
else
echo "$VENV_DIR already exists. Skipping virtual environment creation."
fi
# Activate virtual environment and install dependencies
source $ACTIVATE_SCRIPT
pip install Flask flask_jwt_extended || { echo "Failed to install Flask or flask_jwt_extended. Exiting."; exit 1; }
# Create systemd service file
cat <<EOF > $SERVICE_FILE
[Unit]
Description=Ticket AI
[Service]
Type=simple
ExecStart=$PYTHON_BIN $APP_DIR/src/app.py
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd to recognize the new service and start it
systemctl daemon-reload
systemctl start ticket-ai.service || { echo "Failed to start ticket-ai.service. Exiting."; exit 1; }
# Add firewall rules to accept traffic
for IP in "${IPTABLES_RULES[@]}"; do
iptables -A INPUT -p tcp -m tcp -s $IP --dport 5000 -j ACCEPT
done
# Save iptables rules and restart the service to apply changes
service iptables save
service iptables restart || { echo "Failed to restart iptables. Exiting."; exit 1; }
echo "Setup completed successfully."

View File

@ -1 +0,0 @@
this is a error log from file 'A'

View File

@ -1 +0,0 @@
this is a error log from file 'B'

View File

@ -1,22 +0,0 @@
# install packages
pip install Flask
pip install flask_jwt_extended
# run application
python app.py
# call api
http://127.0.0.1:5000/get_logs?issue_type=Demo
# sample response
{
"/var/log/db.log": "Last 50 lines of db.log...",
"/var/log/db_error.log": "Last 30 lines of db_error.log...",
"top": "Output of the top command..."
}
# run installation script
./install.sh
# run application
./run.sh

View File

@ -1,59 +0,0 @@
from flask import Flask, request, jsonify
import json
import subprocess
from flask_jwt_extended import JWTManager, create_access_token
import os
import datetime
app = Flask(__name__)
# Setup the Flask-JWT-Extended extension
app.config["JWT_SECRET_KEY"] = os.environ.get("JWT_SECRET_KEY", "default-secret-key")
jwt = JWTManager(app)
def split_directory_and_file(path):
directory, file_with_wildcard = os.path.split(path)
file_name = file_with_wildcard.split('*')[0] # Get the part before the wildcard
return directory, file_name
def read_log_from_dir(dir_path, pattern, lines):
ret_var = ""
three_hours_ago = datetime.datetime.now() - datetime.timedelta(hours=3)
log_files = [f for f in os.listdir(dir_path) if pattern in f and datetime.datetime.fromtimestamp(os.path.getmtime(os.path.join(dir_path, f))) > three_hours_ago]
for file_name in log_files:
file_path = os.path.join(dir_path, file_name)
ret_var += f"{file_name}\n{subprocess.check_output(['tail', '-n', str(lines), file_path]).decode('utf-8')}\n\n"
return ret_var
def read_log(log_file, lines):
return subprocess.check_output(['tail', '-n', str(lines), log_file]).decode('utf-8')
def read_top():
return subprocess.check_output(['top', '-b', '-n', '1']).decode('utf-8')
@app.route('/login', methods=['POST'])
def login():
username = request.json.get("username")
password = request.json.get("password")
if username != "admin" or password != "password":
return jsonify({"msg": "Bad username or password"}), 401
access_token = create_access_token(identity=username)
return jsonify(access_token=access_token)
@app.route('/get_logs', methods=['GET'])
def get_logs():
issue_type = request.args.get("issue_type")
try:
with open('/opt/ticket-ai/src/config.json') as config_file:
config = json.load(config_file)
if issue_type not in config:
return jsonify({"error": "Invalid issue type"})
issue_config = config[issue_type]
response = {log.get('log_file').split('*')[0]: read_log_from_dir(*split_directory_and_file(log.get('log_file')), log['lines']) if '*' in log.get('log_file') else read_log(log['log_file'], log['lines']) for log in issue_config['logs']}
response.update({comm.get('tag'): os.popen(comm.get('comm')).read() for comm in issue_config['commands']})
except Exception as e:
return jsonify({"error": str(e)})
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0")

View File

@ -1,111 +0,0 @@
{
"--Select Issue Type--": {
"commands": [],
"logs": []
},
"Password Reset Request": {
"commands": [],
"logs": []
},
"Domain Mapping": {
"commands": [],
"logs": []
},
"Wallet/Reverse Proxy Required": {
"commands": [],
"logs": []
},
"Others": {
"commands": [],
"logs": []
},
"Email Problem": {
"commands": [],
"logs": [
{
"log_file": "/var/log/messages",
"lines": 50
}
]
},
"Jasper Reports": {
"commands": [
{
"comm": "top -b -n 1",
"tag": "top"
}
],
"logs": [
{
"log_file": "/opt/tomcat/logs/catalina.out",
"lines": 50
},
{
"log_file": "/var/log/messages",
"lines": 50
}
]
},
"Server Unavailable": {
"commands": [],
"logs": [
{
"log_file": "/opt/tomcat/logs/catalina.out",
"lines": 50
},
{
"log_file": "/opt/oracle/diag/rdbms/xe/XE/trace/alert_XE.log",
"lines": 50
},
{
"log_file": "/var/log/messages",
"lines": 50
}
]
},
"Demo1": {
"commands": [],
"logs": [
{
"log_file": "/home/arehman/Documents/Projects/Python/Maxapex/ticket_ai_flask_app/logs/*_error.log",
"lines": 50
}
]
},
"Demo2": {
"commands": [],
"logs": [
{
"log_file": "/home/arehman/Documents/Projects/Python/Maxapex/ticket_ai_flask_app/logs/a_error.log",
"lines": 50
}
]
},
"Demo3": {
"commands": [
{
"comm": "top -b -n 1",
"tag": "top"
}
],
"logs": []
},
"Demo": {
"commands": [
{
"comm": "top -b -n 1",
"tag": "top"
}
],
"logs": [
{
"log_file": "/home/arehman/Documents/Projects/Python/Maxapex/ticket_ai_flask_app/logs/a_error.log",
"lines": 50
},
{
"log_file": "/home/arehman/Documents/Projects/Python/Maxapex/ticket_ai_flask_app/logs/*_error.log",
"lines": 50
}
]
}
}