diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe6bd50 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv/ +**/__pycache__/ diff --git a/hosts.yaml b/hosts.yaml new file mode 100644 index 0000000..70c9b17 --- /dev/null +++ b/hosts.yaml @@ -0,0 +1,47 @@ +--- +hosts: + webassets: + hostname: webassets.confederationcollege.ca + actions: + - ping + - httpcheck + secureassets: + hostname: secureassets.confederationcollege.ca + actions: + - ping + cognos-test: + hostname: cc-cognotest-01.confederationc.on.ca + port: 9300 + actions: + - ping + Solarwinds Service Desk: + hostname: itsupport.confederationcollege.ca + actions: + - ping + Aruba Mobility Conductor: + hostname: aruba.confederationcollege.ca + port: 4343 + actions: + - ping + cc-aruba-7210-01: + hostname: cc-aruba-7210-01.confederationcollege.ca + port: 4343 + actions: + - ping + cc-aruba-7210-02: + hostname: cc-aruba-7210-02.confederationcollege.ca + port: 4343 + actions: + - ping + barracuda: + hostname: barracuda.confederationcollege.ca + inbound_decrypt: yes + proxy: yes + actions: + - ping + Maintenance Connection: + hostname: facilitymaint.confederationcollege.ca + server: cc-apps-01 + actions: + - ping + diff --git a/monitor.py b/monitor.py new file mode 100755 index 0000000..0e258de --- /dev/null +++ b/monitor.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +import yaml +import pprint +import json +import sys +sys.path.append('plugins') +import pkgutil +import importlib +plugins = {} +for finder, name, ispkg in pkgutil.iter_modules(path=['plugins']): + plugins[name] = importlib.import_module(name) +row_format = "{:<30}{:<10}{:<6}{:<20}" + +with open('hosts.yaml', 'r') as file: + hosts = yaml.safe_load(file) + +for host, details in hosts['hosts'].items(): + for action in details['actions']: + result = getattr(plugins[action], action)(details['hostname']) + print(row_format.format(host, action, result[0], result[1])) diff --git a/plugins/httpcheck.py b/plugins/httpcheck.py new file mode 100644 index 0000000..f666f8d --- /dev/null +++ b/plugins/httpcheck.py @@ -0,0 +1,8 @@ +import requests + +def httpcheck(host): + try: + r = requests.head(f"https://{host}") + return [True, r.status_code] + except requests.ConnectionError: + return [False, r.status_code] diff --git a/plugins/ping.py b/plugins/ping.py new file mode 100644 index 0000000..59d81ee --- /dev/null +++ b/plugins/ping.py @@ -0,0 +1,13 @@ +import os +import subprocess + +def ping(host): + response = subprocess.run(["ping","-c","1",host], + stdout = subprocess.DEVNULL, stderr = subprocess.PIPE) + if response.returncode == 0: + return [True, ""] + elif response.stderr: + return [False, response.stderr] + else: + return [False, ""] +