Pretty output
This commit is contained in:
parent
24c5eac1b9
commit
1bf4ead343
26
colors.py
Normal file
26
colors.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
class Colors:
|
||||||
|
""" ANSI color codes """
|
||||||
|
BLACK = "\033[0;30m"
|
||||||
|
RED = "\033[0;31m"
|
||||||
|
GREEN = "\033[0;32m"
|
||||||
|
BROWN = "\033[0;33m"
|
||||||
|
BLUE = "\033[0;34m"
|
||||||
|
PURPLE = "\033[0;35m"
|
||||||
|
CYAN = "\033[0;36m"
|
||||||
|
LIGHT_GRAY = "\033[0;37m"
|
||||||
|
DARK_GRAY = "\033[1;30m"
|
||||||
|
LIGHT_RED = "\033[1;31m"
|
||||||
|
LIGHT_GREEN = "\033[1;32m"
|
||||||
|
YELLOW = "\033[1;33m"
|
||||||
|
LIGHT_BLUE = "\033[1;34m"
|
||||||
|
LIGHT_PURPLE = "\033[1;35m"
|
||||||
|
LIGHT_CYAN = "\033[1;36m"
|
||||||
|
LIGHT_WHITE = "\033[1;37m"
|
||||||
|
BOLD = "\033[1m"
|
||||||
|
FAINT = "\033[2m"
|
||||||
|
ITALIC = "\033[3m"
|
||||||
|
UNDERLINE = "\033[4m"
|
||||||
|
BLINK = "\033[5m"
|
||||||
|
NEGATIVE = "\033[7m"
|
||||||
|
CROSSED = "\033[9m"
|
||||||
|
END = "\033[0m"
|
||||||
20
monimon.py
20
monimon.py
@ -3,14 +3,22 @@ import yaml
|
|||||||
import pprint
|
import pprint
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('plugins/plugins')
|
sys.path.append('plugins')
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import importlib
|
import importlib
|
||||||
|
from colors import Colors
|
||||||
plugins = {}
|
plugins = {}
|
||||||
for finder, name, ispkg in pkgutil.iter_modules(path=['plugins/plugins']):
|
for finder, name, ispkg in pkgutil.iter_modules(path=['plugins']):
|
||||||
plugins[name] = importlib.import_module(name)
|
plugins[name] = importlib.import_module(name)
|
||||||
row_format = "{:<30} {:<10} {:<6}"
|
row_format = "{:<30} {:<10} {:<6}"
|
||||||
|
|
||||||
|
def translate_status(status):
|
||||||
|
if status:
|
||||||
|
return f"{Colors.GREEN}Success{Colors.END}"
|
||||||
|
else:
|
||||||
|
return f"{Colors.RED}Failure{Colors.END}"
|
||||||
|
|
||||||
|
|
||||||
with open('hosts.yaml', 'r') as file:
|
with open('hosts.yaml', 'r') as file:
|
||||||
hosts = yaml.safe_load(file)
|
hosts = yaml.safe_load(file)
|
||||||
|
|
||||||
@ -33,5 +41,9 @@ for host, details in hosts['hosts'].items():
|
|||||||
#print(arguments)
|
#print(arguments)
|
||||||
result = getattr(plugins[action_name], action_name)(arguments)
|
result = getattr(plugins[action_name], action_name)(arguments)
|
||||||
#print(f"{host}\t{action_name}\t{result[0]}\t{result[1]}")
|
#print(f"{host}\t{action_name}\t{result[0]}\t{result[1]}")
|
||||||
print(row_format.format(host, action_name, result[0]))
|
if type(result) is list:
|
||||||
print(f"{result[1]}")
|
print(row_format.format(f"{Colors.BOLD}{host}{Colors.END}", action_name, translate_status(result[0])))
|
||||||
|
print(f"{Colors.YELLOW}{result[1]}{Colors.END}")
|
||||||
|
else:
|
||||||
|
print(row_format.format(host, action_name, translate_status(result)))
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# TODO: Check return status code
|
||||||
def httpcheck(arguments):
|
def httpcheck(arguments):
|
||||||
try:
|
try:
|
||||||
r = requests.head(f"{arguments['endpoint']}")
|
r = requests.head(f"{arguments['endpoint']}")
|
||||||
return ["Success", f"Status code: {r.status_code}"]
|
return [True, f"Status code: {r.status_code}"]
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
return ["Failure", f"Status code: {r.status_code}"]
|
return [False, f"Status code: {r.status_code}"]
|
||||||
|
|||||||
@ -6,9 +6,9 @@ def ping(arguments):
|
|||||||
response = subprocess.run(["ping","-c","1",arguments['hostname']],
|
response = subprocess.run(["ping","-c","1",arguments['hostname']],
|
||||||
stdout = subprocess.DEVNULL, stderr = subprocess.PIPE)
|
stdout = subprocess.DEVNULL, stderr = subprocess.PIPE)
|
||||||
if response.returncode == 0:
|
if response.returncode == 0:
|
||||||
return ["Success", ""]
|
return True
|
||||||
elif response.stderr:
|
elif response.stderr:
|
||||||
return ["Success", response.stderr.decode("UTF-8")]
|
return [False, response.stderr.decode("UTF-8")]
|
||||||
else:
|
else:
|
||||||
return ["Failure", ""]
|
return False
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user