# Copyright (c) 2015 iXsystems, Inc.
# All rights reserved.
# This file is a part of TrueNAS
# and may not be copied and/or distributed
# without the express permission of iXsystems.

class FailoverAlert(object):

    def volumes_status_enabled(self):
        from freenasUI.middleware.notifier import notifier
        status = notifier().failover_status()
        return status in ('MASTER', 'SINGLE')

    def on_volume_status_degraded(self, vol, status, message):
        from freenasUI.middleware.notifier import notifier
        rv = super(FailoverAlert, self).on_volume_status_degraded(
            vol, status, message
        )
        try:
            notifier().zpool_enclosure_sync(vol.vol_name)
        except:
            pass
        return rv

    def on_volume_status_not_healthy(self, vol, status, message):
        from freenasUI.middleware.notifier import notifier
        rv = super(FailoverAlert, self).on_volume_status_not_healthy(
            vol, status, message
        )
        try:
            notifier().zpool_enclosure_sync(vol.vol_name)
        except:
            pass
        return rv
