Started implementing Plugin class, doesn't do anyhting yet
This commit is contained in:
parent
d5d0c068fc
commit
3a0567ef0c
0
__init__.py
Normal file
0
__init__.py
Normal file
@ -6,15 +6,18 @@ hosts:
|
|||||||
- ping
|
- ping
|
||||||
- httpcheck:
|
- httpcheck:
|
||||||
endpoint: https://webassets.confederationcollege.ca
|
endpoint: https://webassets.confederationcollege.ca
|
||||||
|
- cert_expiration:
|
||||||
|
endpoint: webassets.confederationcollege.ca
|
||||||
secureassets:
|
secureassets:
|
||||||
hostname: secureassets.confederationcollege.ca
|
hostname: secureassets.confederationcollege.ca
|
||||||
actions:
|
actions:
|
||||||
- ping
|
- ping
|
||||||
cognos-test:
|
cognos-test:
|
||||||
hostname: cc-cognotest-01.confederationc.on.ca
|
hostname: cc-cognotest-01.confederationc.on.ca
|
||||||
port: 9300
|
|
||||||
actions:
|
actions:
|
||||||
- ping
|
- ping
|
||||||
|
- cert_expiration:
|
||||||
|
endpoint: cc-cognotest-01.confederationc.on.ca:9300
|
||||||
Solarwinds Service Desk:
|
Solarwinds Service Desk:
|
||||||
hostname: itsupport.confederationcollege.ca
|
hostname: itsupport.confederationcollege.ca
|
||||||
actions:
|
actions:
|
||||||
|
|||||||
@ -3,11 +3,11 @@ import yaml
|
|||||||
import pprint
|
import pprint
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('plugins')
|
sys.path.append('plugins/plugins')
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import importlib
|
import importlib
|
||||||
plugins = {}
|
plugins = {}
|
||||||
for finder, name, ispkg in pkgutil.iter_modules(path=['plugins']):
|
for finder, name, ispkg in pkgutil.iter_modules(path=['plugins/plugins']):
|
||||||
plugins[name] = importlib.import_module(name)
|
plugins[name] = importlib.import_module(name)
|
||||||
row_format = "{:<30}{:<10}{:<6}{:<20}"
|
row_format = "{:<30}{:<10}{:<6}{:<20}"
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ for host, details in hosts['hosts'].items():
|
|||||||
arguments[argument] = value
|
arguments[argument] = value
|
||||||
|
|
||||||
|
|
||||||
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], result[1]))
|
print(row_format.format(host, action_name, result[0], result[1]))
|
||||||
|
|||||||
0
plugins/__init__.py
Normal file
0
plugins/__init__.py
Normal file
9
plugins/plugin.py
Normal file
9
plugins/plugin.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from enum import Enum
|
||||||
|
class Plugin:
|
||||||
|
class Status(Enum):
|
||||||
|
SUCCESS = "Succ
|
||||||
|
i = 12345
|
||||||
|
|
||||||
|
def f(self):
|
||||||
|
return 'hello world'
|
||||||
|
|
||||||
0
plugins/plugins/__init__.py
Normal file
0
plugins/plugins/__init__.py
Normal file
23
plugins/plugins/cert_expiration.py
Normal file
23
plugins/plugins/cert_expiration.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import socket
|
||||||
|
import ssl
|
||||||
|
|
||||||
|
def cert_expiration(args):
|
||||||
|
hostname = args['endpoint'].split(":")[0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
port = args['endpoint'].split(":")[1]
|
||||||
|
except IndexError:
|
||||||
|
port = 443
|
||||||
|
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
|
||||||
|
with context.wrap_socket(socket.socket(socket.AF_INET),
|
||||||
|
server_hostname = hostname) as conn:
|
||||||
|
conn.connect((hostname, int(port)))
|
||||||
|
|
||||||
|
cert = conn.getpeercert()
|
||||||
|
|
||||||
|
return [True, f"Expiration: {cert['notAfter']}"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,7 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from plugins import plugin
|
||||||
|
|
||||||
def ping(arguments):
|
def ping(arguments):
|
||||||
|
print(plugin.Plugin.i)
|
||||||
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:
|
||||||
22
plugins/plugins/ssl_expiration.py
Normal file
22
plugins/plugins/ssl_expiration.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import ssl
|
||||||
|
import socket
|
||||||
|
|
||||||
|
def ssl_expiration(url):
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
|
||||||
|
#context = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||||
|
|
||||||
|
#context.check_hostname = False
|
||||||
|
#context.verify_mode = ssl.CERT_NONE
|
||||||
|
#context.options &= ~ssl.OP_NO_TLSv1
|
||||||
|
#context.options &= ~ssl.OP_NO_SSLv3
|
||||||
|
port = 443 if not "port" in details else details['port']
|
||||||
|
with context.wrap_socket(socket.socket(socket.AF_INET),
|
||||||
|
server_hostname=details['hostname']) as conn:
|
||||||
|
conn.connect((details['hostname'], port))
|
||||||
|
cert = conn.getpeercert()
|
||||||
|
print()
|
||||||
|
print(host)
|
||||||
|
print(cert['serialNumber'])
|
||||||
|
print(cert['subject'][4][0][1])
|
||||||
|
print(cert['notAfter'])
|
||||||
Loading…
x
Reference in New Issue
Block a user