Skip to content

Commit

Permalink
Merge pull request #1 from rbisewski/add-code-to-check-zpool-status
Browse files Browse the repository at this point in the history
Add code to check zpool status
  • Loading branch information
rbisewski committed Oct 14, 2018
2 parents 338c8ea + 59ccf0f commit 4e6f9fe
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,11 @@ Conduct a quick lookup of the kernel version and type of a given Linux host.
Prints the files and their sizes, in the /var/log/ directory of a given
Linux host.

## check-zpool.py

Prints the health status of the zpool on a given host, as well as the ZFS
volume information.

## TODO

* consider separating out parts into separate functions
Expand Down
98 changes: 98 additions & 0 deletions check-zpool.py
@@ -0,0 +1,98 @@
#!/usr/bin/python3

import sys, getopt, getpass
from fabric import Connection

def main(argv):

usageInfo = ("check-zpool-status.py "
"-d <destination hostname or IP> "
"-p <port number> "
"-u <user> "
"-i </path/to/identity_file>")

destinationHost = ''
destinationPort = 22
user = ''
identityFile = ''

#
# input validation
#

try:
opts, args = getopt.getopt(argv,"hd:p:u:i:",["host=","port=","user=","id="])
except getopt.GetoptError:
print(usageInfo)
exit(1)

for opt, arg in opts:
if opt == "-h":
print(usageInfo)
exit()
elif opt in ("-d","--host"):
destinationHost = arg
elif opt in ("-p","--port"):
destinationPort = arg
elif opt in ("-u","--user"):
user = arg
elif opt in ("-i","--id"):
identityFile = arg

if destinationHost == '':
print("Error: No host specified.")
exit(1)

if destinationPort == 0 or not destinationPort.isdigit():
print("Error: Invalid port specified.")
exit(1)

if user == '':
print("Error: No user specified.")
exit(1)

#
# if an identity is supplied, attempt to obtain the passphrase
#
identityPassphrase = getpass.getpass()

#
# attempt to connect using the given parameters
#

if identityFile == '' or identityPassphrase == '':
conn = Connection(host=destinationHost, port=destinationPort, user=user)
else:
conn = Connection(host=destinationHost, port=destinationPort, user=user,
connect_kwargs={'key_filename':identityFile,'passphrase':identityPassphrase})

if conn is None:
print("Error: Unable to initialize Connection object.")
exit(1)

print("The following connection was established: ", conn)

#
# obtain the status of the zpool and zfs volume information
#

result = conn.run("zpool status")
if result.exited != 0 or result.ok != True:
print("Warning: The connection was improper or terminated prematurely.")
print("Unable to obtain zpool status.")

result = conn.run("zfs list")
if result.exited != 0 or result.ok != True:
print("Warning: The connection was improper or terminated prematurely.")
print("Unable to obtain ZFS volume information.")

#
# close the connection since everything is done
#

conn.close()

#
# execute the main function declared above
#
main(sys.argv[1:])

0 comments on commit 4e6f9fe

Please sign in to comment.