ZFSSA List Replication Actions Status

ZFSSA List Replication Actions Status

Using the ZFS appliance REST API to take a quick look at all replication actions and check on progress of long running jobs.

# python zfssa_status_replication_v1.0.py

List Replicated Project Snapshots -- PST Run Date 2017-04-30 06:42:59.386738
date                       target project    pool      bytes_sent      estimated_size  estimated_time_left average_throughput
2017-04-30 07:20:04.232975 zfs2   EBSPRD     POOL1     6.78G           21.3G           01:00:35            4MB/s
2017-04-30 06:42:59.386738 zfs3   EBSPRD     POOL2     0               0               00:00:00            0B/s           
<snip>
# cat zfssa_status_replication_v1.0.py 
#!/usr/bin/env python

# Version 1.0
import sys
import requests, json, os
import datetime

requests.packages.urllib3.disable_warnings()
dt = datetime.datetime.now()

# ZFSSA API URL
url = "https://zfs1:215"

# ZFSSA authentication credentials, it reads username and password from environment variables ZFSUSER and ZFSPASSWORD
#zfsauth = (os.getenv('ZFSUSER'), os.getenv('ZFSPASSWORD'))
zfsauth = ('ROuser','password')

jsonheader={'Content-Type': 'application/json'}

def list_replication_actions_status():
  r = requests.get("%s/api/storage/v1/replication/actions" % (url), auth=zfsauth, verify=False, headers=jsonheader)
  if r.status_code != 200:
    print("Error getting actions %s %s" % (r.status_code, r.text))
  else:
   j = json.loads(r.text)
   #print j
   for action in j["actions"]:
     #print action
     print("{} {:15} {:10} {:15} ".format(dt, action["target"], action["project"], action["pool"])),
     show_one_replication_action(action["id"])

def show_one_replication_action(id):
  r = requests.get("%s/api/storage/v1/replication/actions/%s" % (url,id), auth=zfsauth, verify=False, headers=jsonheader)
  if r.status_code != 200:
    print("Error getting status %s %s" % (r.status_code, r.text))
  else:
   j = json.loads(r.text)
   #print j
   print("{:15} {:15} {:19} {:15}".format(j["action"]["bytes_sent"], j["action"]["estimated_size"], j["action"]["estimated_time_left"], j["action"]["average_throughput"]))

print ("\nList Replicated Project Snapshots -- PST Run Date %s" % dt)
print('{:26} {:15} {:10} {:16} {:15} {:15} {:16} {}').format('date','target','project','pool','bytes_sent','estimated_size','estimated_time_left','average_throughput')
list_replication_actions_status()