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
|
||||
- httpcheck:
|
||||
endpoint: https://webassets.confederationcollege.ca
|
||||
- cert_expiration:
|
||||
endpoint: webassets.confederationcollege.ca
|
||||
secureassets:
|
||||
hostname: secureassets.confederationcollege.ca
|
||||
actions:
|
||||
- ping
|
||||
cognos-test:
|
||||
hostname: cc-cognotest-01.confederationc.on.ca
|
||||
port: 9300
|
||||
actions:
|
||||
- ping
|
||||
- cert_expiration:
|
||||
endpoint: cc-cognotest-01.confederationc.on.ca:9300
|
||||
Solarwinds Service Desk:
|
||||
hostname: itsupport.confederationcollege.ca
|
||||
actions:
|
||||
|
||||
@ -3,11 +3,11 @@ import yaml
|
||||
import pprint
|
||||
import json
|
||||
import sys
|
||||
sys.path.append('plugins')
|
||||
sys.path.append('plugins/plugins')
|
||||
import pkgutil
|
||||
import importlib
|
||||
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)
|
||||
row_format = "{:<30}{:<10}{:<6}{:<20}"
|
||||
|
||||
@ -31,7 +31,7 @@ for host, details in hosts['hosts'].items():
|
||||
arguments[argument] = value
|
||||
|
||||
|
||||
print(arguments)
|
||||
#print(arguments)
|
||||
result = getattr(plugins[action_name], action_name)(arguments)
|
||||
#print(f"{host}\t{action_name}\t{result[0]}\t{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 subprocess
|
||||
from plugins import plugin
|
||||
|
||||
def ping(arguments):
|
||||
print(plugin.Plugin.i)
|
||||
response = subprocess.run(["ping","-c","1",arguments['hostname']],
|
||||
stdout = subprocess.DEVNULL, stderr = subprocess.PIPE)
|
||||
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