Añadido sistema de logs
This commit is contained in:
11
status.py
11
status.py
@@ -2,8 +2,10 @@ import argparse
|
||||
from pythonping import ping
|
||||
import ipaddress
|
||||
import requests
|
||||
import logging
|
||||
|
||||
DISCORD_WEBHOOK_URL='https://discord.com/api/webhooks/1229025346385608824/kIt2dp2znu0jR85QbOPmoMAteHaB9BCJDTMfn0cHE9mwpxHkbUNc9By2Y7n6gpufoyco'
|
||||
logging.basicConfig(filename='/var/log/status.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
def read_document(document_name):
|
||||
with open(document_name, 'r') as file:
|
||||
@@ -41,12 +43,14 @@ def toIP(hosts):
|
||||
def check_ping(hosts):
|
||||
for host in hosts:
|
||||
try:
|
||||
print(f'Pingin host: {host}')
|
||||
response = ping(str(host), count=4, timeout=2) # verbose=True -> Para ver la respuesta del ping
|
||||
if not response.success():
|
||||
logging.info(f"Bad ping: {host}")
|
||||
send_discord_message(f"Ping fallido para el host: {host}")
|
||||
elif response.success():
|
||||
logging.info(f"Ping correct: {host}")
|
||||
except Exception as e:
|
||||
print(f"Error making ping to {host}: {e}")
|
||||
logging.info(f"Bad ping: {host}")
|
||||
|
||||
def send_discord_message(message):
|
||||
data = {
|
||||
@@ -57,8 +61,9 @@ def send_discord_message(message):
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error sending Discord message: {e}")
|
||||
logging.info(f"Error sending Discord message: {e}")
|
||||
else:
|
||||
print("Discord message sent successfully!")
|
||||
logging.info("Discord message sent successfully!")
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parseArguments()
|
||||
|
||||
Reference in New Issue
Block a user