Commit 600f2754 authored by jithu.tagore's avatar jithu.tagore

initial commit

parent fbccaa4e
[kairos]
IP=192.168.0.220
[type]
server=False
camera=False
[infra_alert_manager]
ram_usage=False
disk_usage=False
service_status=True
docker_container_status=True
[service]
service_list=docker
include_active_status=False
include_restart_status = True
restart_max_count=3
use_cloud_mail_gateway=True
is_redis_as_docker=False
env_name=DEV
url= DEV
IP=192.168.0.220
[mqtt]
mqtt_enable=True
mqtt_broker=test.mosquitto.org
mqtt_port=1883
mqtt_topic=newtopic
[ram]
ram_threshold_value=90
include_ram=False
[disk]
filesystem=""
threshold_value=80
include_all_filesystem=False
[kafka]
meta_file_path = /tmp/kafka-logs/
meta_file_name = /tmp/kafka-logs/meta.properties
IP=192.168.0.220
port=9092
[user_info]
subject=Infra Alert
sender_email = devopsilens@gmail.com
receiver_email = jithu.tagore@knowledgelens.com
password = aWxlbnNAMjAyMQ==
[telegram]
enable_alerts =False
bot_token=5701133680:AAGeOaJ2F0Mi0AiBsamtjyZ03T4boEdVKa4
bot_chatID=-1001656619117
[kairos]
IP=192.168.0.220
[type]
server=False
camera=False
[infra_alert_manager]
ram_usage=False
disk_usage=False
service_status=True
docker_container_status=True
[service]
service_list=docker
include_active_status=False
include_restart_status = True
restart_max_count=3
use_cloud_mail_gateway=True
is_redis_as_docker=False
env_name=DEV
url= DEV
IP=192.168.0.220
[mqtt]
mqtt_enable=True
mqtt_broker=test.mosquitto.org
mqtt_port=1883
mqtt_topic=newtopic
[ram]
ram_threshold_value=90
include_ram=False
[disk]
filesystem=""
threshold_value=80
include_all_filesystem=False
[kafka]
meta_file_path = /tmp/kafka-logs/
meta_file_name = /tmp/kafka-logs/meta.properties
IP=192.168.0.220
port=9092
[user_info]
subject=Infra Alert
sender_email = devopsilens@gmail.com
receiver_email = jithu.tagore@knowledgelens.com
password = aWxlbnNAMjAyMQ==
[telegram]
enable_alerts =False
bot_token=5701133680:AAGeOaJ2F0Mi0AiBsamtjyZ03T4boEdVKa4
bot_chatID=-1001656619117
#!/bin/bash
THRESHOLD_VALUE_ALERT=$1
IFS=', ' read -r -a FILE_SYSTEMS <<< "$2"
SHOW_ALL_FILE_SYSTEMS=$3
disk_usage() {
if [ "$FILE_SYSTEMS" == '""' ]; then
partition_name=($(df -H | grep -vE 'overlay|shm' | awk '{ print $1 }' | awk '{if(NR>1)print}'))
used_storage_percentage=($(df -H | grep -vE 'overlay|shm' | awk '{ print $5 }' | cut -d'%' -f1 | awk '{if(NR>1)print}'))
else
printf -v file_system_string '|%s' "${FILE_SYSTEMS[@]}"
file_system_string="${file_system_string:1}"
partition_name=($(df -H | grep -vE 'overlay|shm' | awk '{ print $1 }' | grep -E ${file_system_string}))
used_storage_percentage=($(df -H | grep -vE 'overlay|shm' | awk '{ print $1,$5 }' | grep -E ${file_system_string} | awk '{ print $2 }' | cut -d'%' -f1))
fi
exceeded_storage_names=()
if [ "$SHOW_ALL_FILE_SYSTEMS" == True ]; then
exceeded_storage_names=( "${partition_name[@]}" )
else
for i in "${!used_storage_percentage[@]}"; do
if [ ${used_storage_percentage[$i]} -ge $THRESHOLD_VALUE_ALERT ]; then
exceeded_storage_names+=(${partition_name[$i]})
fi
done
fi
printf -v partition_name_string '|%s' "${exceeded_storage_names[@]}"
partition_name_string="${partition_name_string:1}"
df -H | grep -vE 'overlay|shm' | grep -E ${partition_name_string} >>usage.txt
}
touch usage.txt
disk_usage
exit 0
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
**command:** python kafka_restart_script.py -p=9092 -ip=127.0.0.1 -S=kafka
Update `meta_file_path` and `meta_file_name` variable in the kafka_restart_script.py
Value for the above variables can be obtained in `/home/kafka/kafka/config/server.properties` file of that env, open the file and search for `log.dirs`, the value of `log.dirs` should be mentiones as `meta_file_path`
import argparse
import os
import sys
import time
from datetime import datetime
ap = argparse.ArgumentParser()
meta_file_path = "/tmp/kafka-logs/"
meta_file_name = "/tmp/kafka-logs/meta.properties"
def kafka_specific_fun():
try:
date = datetime.now().strftime("%Y-%m-%d-%I:%M:%S-%p")
new_file_path = os.path.join(meta_file_path, f'meta.properties_{date}')
os.rename(meta_file_name, new_file_path)
except Exception as e:
print(f"Exception Occurred while renaming the meta.properties file {e.args}")
def _restart_and_check_status_service(service_name):
try:
kafka_service_status = True if os.system(
f"sudo service {service_name} status") is 0 else False
print(kafka_service_status)
if not kafka_service_status:
os.system(f"sudo service {service_name} restart")
time.sleep(6)
kafka_service_status = True if os.system(
f"sudo service {service_name} status") is 0 else False
return kafka_service_status
except Exception as e:
print(f"Failed to restart the system service {service_name} as {e.args}")
return False
if __name__ == "__main__":
ap.add_argument(
"--host",
"-ip",
required=False,
help="Check the Host Whether it is accessible or not...",
)
ap.add_argument(
"--service_name",
"-S",
required=False,
help="Checks the Service Status...",
)
ap.add_argument(
"--port",
"-p",
required=False,
help="Checks the Service Status...",
)
arguments = vars(ap.parse_args())
print(f"Given Host ---> {arguments['host']}")
print(f"Given service details ---> {arguments['service_name']}")
print(f"Given port details ---> {arguments.get('port')}")
# sys.exit()
HOST_UP = True if os.system("ping -c 1 " + f'{arguments["host"]}') == 0 else False
print(HOST_UP)
_service_status = False
port_number = arguments.get('port')
if HOST_UP:
for _ in range(0, 2):
_service_status = _restart_and_check_status_service(service_name=arguments['service_name'])
if _service_status:
_port_status = True if os.system(f"sudo netstat -nlp | grep :{port_number}") == 0 else False
if _port_status:
sys.exit()
else:
os.system(f"sudo service {arguments['service_name']} restart")
_service_status = _restart_and_check_status_service(service_name=arguments['service_name'])
print(_service_status)
if not _service_status:
_port_status = True if os.system(f"sudo netstat -nlp | grep :{port_number}") == 0 else False
if _port_status:
os.system(f'kill -9 $(lsof -t -i:{port_number})')
elif arguments['service_name'] in {"kafka"} and not _port_status:
print("Changing meta.properties file name")
kafka_specific_fun()
_restart_and_check_status_service(service_name=arguments['service_name'])
#!/bin/bash
touch Ram_uasge.txt
THRESHOLD=$1
INCLUDE_RAM=$2
RAM_TOTAL=$(free -g | grep Mem | awk '{print $2}')
RAM_AVAIL=$(free -g | grep Mem | awk '{print $7}')
RAM_USED=$(free -g | grep Mem | awk '{print $3}')
THRESHOLD_RAM=$(echo $(( $RAM_TOTAL*$THRESHOLD/100 )))
if [ "$INCLUDE_RAM" == True ]; then
free -g | awk '{ print $1 " " $2 " " $3 " " $4 " " $5 " " $6 }' | awk '{if(NR>1)print}' | grep Mem | awk '{ print $2 " " $3 "["int($3/$2*100)"%" "] " $4 "["int($4/$2*100)"%" "] " $5 " " $6}' >Ram_uasge.txt
else
if [ $RAM_USED -ge $THRESHOLD_RAM ]; then
free -g | awk '{ print $1 " " $2 " " $3 " " $4 " " $5 " " $6 }' | awk '{if(NR>1)print}' | grep Mem | awk '{ print $2 " " $3 "["int($3/$2*100)"%" "] " $4 "["int($4/$2*100)"%" "] " $5 " " $6}' >Ram_uasge.txt
fi
fi
prettytable==2.1.0
requests==2.25.1
psutil==5.8.0
configparser==5.0.2
python-telegram-bot
paho-mqtt
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment