Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rbisewski/add-code-to-check-zpool-status
Add code to check zpool status
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:]) |