# 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.

import os

from django.utils.translation import ugettext as _

from freenasUI.system.alert import alertPlugins, Alert, BaseAlert


class ZpoolTrapAlert(BaseAlert):

    def run(self):
        ZPOOL_TRAP_FILE = '/var/tmp/zpool_trap'
        if not os.path.exists(ZPOOL_TRAP_FILE):
            return None
        msg = open(ZPOOL_TRAP_FILE).read()
        os.unlink(ZPOOL_TRAP_FILE)
        if msg == "":
            return [Alert(
                Alert.CRIT,
                _('zpool device removal detected')
            )]
        else:
            return [Alert(Alert.CRIT, msg)]

alertPlugins.register(ZpoolTrapAlert)
