#!/usr/local/bin/python

import os
import sys
import isi.celog
import isi.gconfig as gconfig
from isi.celog.eventids import eventid_map

NO_EVENT_FLAG = "/etc/ifs/esrs_no_unconfigured_event"

def main(argv):
    if "--disable-event" in argv:
        open(NO_EVENT_FLAG, "w").close()
    tree = gconfig.Tree("remote-support")
    base = c = gconfig.open(tree)
    ctx = c.ctx_new()
    connectemc_cfg = ctx.read("connectemc")

    if connectemc_cfg["enabled"] == False and not os.path.exists(NO_EVENT_FLAG):
        isi.celog.Event(event_id=eventid_map["SW_ESRS_UNCONFIGURED"],
            severity=isi.celog.EVENT_LEVEL_WARN,
            message="This cluster is not connected back to EMC via " \
                    "ESRS.\nConfiguring connectivity to EMC via ESRS " \
                    "is a secure method to improve the overall " \
                    "reliability of your cluster and reduce the\ntime " \
                    "it takes to resolve any issues the cluster may develop.",
            send_event=True)

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
