Finished WIP #31a27229 - now optional parameters can be specified for
each plugin in the hosts.yaml file
This commit is contained in:
parent
31a27229f4
commit
d5d0c068fc
22
monimon.py
22
monimon.py
@ -16,8 +16,22 @@ with open('hosts.yaml', 'r') as file:
|
|||||||
|
|
||||||
for host, details in hosts['hosts'].items():
|
for host, details in hosts['hosts'].items():
|
||||||
for action in details['actions']:
|
for action in details['actions']:
|
||||||
!!! arguments = {'hostname': }
|
# Start building the arguments dict that will get passed to the plugin.
|
||||||
|
# By default, the only item is the hostname.
|
||||||
|
arguments = {'hostname': details['hostname']}
|
||||||
|
|
||||||
result = getattr(plugins[action], action)(details['hostname'])
|
# Check if the action has any parameters defined in the YAML file, by
|
||||||
#print(f"{host}\t{action}\t{result[0]}\t{result[1]}")
|
# checking if it's a string or a dict
|
||||||
print(row_format.format(host, action, result[0], result[1]))
|
if type(action) is str:
|
||||||
|
action_name = action
|
||||||
|
# If it's a dict, add each parameter to the arguments dict
|
||||||
|
elif type(action) is dict:
|
||||||
|
action_name = list(action)[0]
|
||||||
|
for argument, value in action[action_name].items():
|
||||||
|
arguments[argument] = value
|
||||||
|
|
||||||
|
|
||||||
|
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]))
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
def httpcheck(host):
|
def httpcheck(arguments):
|
||||||
try:
|
try:
|
||||||
r = requests.head(f"https://{host}")
|
r = requests.head(f"{arguments['endpoint']}")
|
||||||
return [True, r.status_code]
|
return [True, r.status_code]
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
return [False, r.status_code]
|
return [False, r.status_code]
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def ping(host):
|
def ping(arguments):
|
||||||
response = subprocess.run(["ping","-c","1",host],
|
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 [True, ""]
|
return [True, ""]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user