#!/usr/bin/env python
#
# Copyright C 2002-2007 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  "Isilon IQ" is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.
#
# $Id: database.py 60606 2006-12-12 01:54:52Z jroberson $

import os
import sys

import isi.celog.query as cq
from isi.celog.eventids import eventid_map
import isi.celog.celog_config_api as ccapi

def usage():
    print "Invalid arguments:"
    print "isi_healthy_drives_alert [enable|disable]"
    sys.exit(os.EX_USAGE)

cc = ccapi.CelogConfigAPI()
ms = cc.get_monitor_settings()

if len(sys.argv) == 2:
    needs_commit = False

    if sys.argv[1].lower()[0] == 'e':
        if not ms['monitor_drive_health']:
            ms['monitor_drive_health'] = True
            needs_commit = True
    elif sys.argv[1].lower()[0] == 'd':
        if ms['monitor_drive_health']:
            ms['monitor_drive_health'] = False
            cdb = cq.Query()
            drive_evs = cdb.get_events(
                    eventids=[eventid_map["SYS_DISK_UNHEALTHY"]])
            for ev in drive_evs:
                ev.end()
            needs_commit = True
    else:
        usage()

    if needs_commit:
        cc.set_monitor_settings(ms)

elif len(sys.argv) != 1:
    usage()

sys.stdout.write("The 'Unhealthy drives' alert is ")

if ms['monitor_drive_health']:
    sys.stdout.write("enabled\n")
else:
    sys.stdout.write("disabled\n")

