Compare commits
8 Commits
ReadIPs
...
dc9c7eabc6
| Author | SHA1 | Date | |
|---|---|---|---|
| dc9c7eabc6 | |||
| e976c48103 | |||
|
|
aad6fb97a6 | ||
|
|
6ab6224ff6 | ||
|
|
2b986eeabb | ||
|
|
90a7cb8581 | ||
|
|
7bccab9455 | ||
| 03b7177ecf |
0
Jenkinsfile
vendored
Normal file
0
Jenkinsfile
vendored
Normal file
22
status.py
22
status.py
@@ -2,10 +2,10 @@ import argparse
|
||||
from pythonping import ping
|
||||
import ipaddress
|
||||
import requests
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import logging
|
||||
|
||||
load_dotenv()
|
||||
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:
|
||||
@@ -43,35 +43,33 @@ 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():
|
||||
print(False)
|
||||
logging.info(f"Bad ping: {host}")
|
||||
send_discord_message(f"Ping fallido para el host: {host}")
|
||||
else:
|
||||
print(True)
|
||||
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):
|
||||
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
|
||||
data = {
|
||||
"content": message
|
||||
}
|
||||
try:
|
||||
response = requests.post(webhook_url, json=data)
|
||||
response = requests.post(DISCORD_WEBHOOK_URL, json=data)
|
||||
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()
|
||||
ips_and_hosts = set()
|
||||
if args.host:
|
||||
ips_and_hosts.update(toIP(read_document(args.host)))
|
||||
print(ips_and_hosts)
|
||||
if args.web:
|
||||
print("Hay webs")
|
||||
# Parsear correctamente
|
||||
|
||||
Reference in New Issue
Block a user