Example #1
0
    def __init__(self,
                 host="127.0.0.1",
                 port=9082,
                 log=None,
                 onready=None,
                 onexercise=None,
                 onrun=None,
                 onrunmanual=None,
                 onalarm=None,
                 onservice=None,
                 onoff=None,
                 onmanual=None):

        self.AccessLock = threading.Lock()
        self.ThreadList = []
        self.LastEvent = None
        self.Events = {}  # Dict for handling events

        if log != None:
            self.log = log
        else:
            # log errors in this module to a file
            self.log = mylog.SetupLogger("client", "/var/log/myclient.log")

        # init event callbacks
        if onready != None:
            self.Events["READY"] = onready
        if onexercise != None:
            self.Events["EXERCISING"] = onexercise
        if onrun != None:
            self.Events["RUNNING"] = onrun
        if onrunmanual != None:
            self.Events["RUNNING-MANUAL"] = onrunmanual
        if onalarm != None:
            self.Events["ALARM"] = onalarm
        if onservice != None:
            self.Events["SERVICEDUE"] = onservice
        if onoff != None:
            self.Events["OFF"] = onoff
        if onmanual != None:
            self.Events["MANUAL"] = onmanual

        self.Generator = myclient.ClientInterface(host=host, log=log)

        # start thread to accept incoming sockets for nagios heartbeat
        self.StartThread(self.MainPollingThread, Name="PollingThread")
Example #2
0
    log.error("Starting " + AppPath + ", Port:" + str(HTTPPort) +
              ", Secure HTTP: " + str(bUseSecureHTTP) + ", SelfSignedCert: " +
              str(bUseSelfSignedCert))

    # validate needed files are present
    file = os.path.dirname(os.path.realpath(__file__)) + "/startgenmon.sh"
    if not ValidateFilePresent(file):
        log.error("Required file missing : startgenmon.sh")

    file = os.path.dirname(os.path.realpath(__file__)) + "/genmonmaint.sh"
    if not ValidateFilePresent(file):
        log.error("Required file missing : genmonmaint.sh")

    MyClientInterface = myclient.ClientInterface(host=address,
                                                 port=clientport,
                                                 log=log)

    Start = datetime.datetime.now()

    while ((datetime.datetime.now() - Start).total_seconds() < 5):
        data = MyClientInterface.ProcessMonitorCommand("generator: gethealth")
        if "OK" in data:
            print("OK - Init complete.\n")
            break

    while True:
        try:
            app.run(host="0.0.0.0",
                    port=HTTPPort,
                    threaded=True,
Example #3
0
    def __init__(self,
                 host="127.0.0.1",
                 port=9082,
                 log=None,
                 onready=None,
                 onexercise=None,
                 onrun=None,
                 onrunmanual=None,
                 onalarm=None,
                 onservice=None,
                 onoff=None,
                 onmanual=None,
                 onutilitychange=None):

        super(GenNotify, self).__init__()

        self.AccessLock = threading.Lock()
        self.Threads = {}
        self.LastEvent = None
        self.LastOutageStatus = None
        self.Events = {}  # Dict for handling events

        if log != None:
            self.log = log
        else:
            # log errors in this module to a file
            self.log = mylog.SetupLogger("client", "/var/log/myclient.log")

        self.console = mylog.SetupLogger("notify_console",
                                         log_file="",
                                         stream=True)
        try:
            # init event callbacks
            if onready != None:
                self.Events["READY"] = onready
            if onexercise != None:
                self.Events["EXERCISING"] = onexercise
            if onrun != None:
                self.Events["RUNNING"] = onrun
            if onrunmanual != None:
                self.Events["RUNNING-MANUAL"] = onrunmanual
            if onalarm != None:
                self.Events["ALARM"] = onalarm
            if onservice != None:
                self.Events["SERVICEDUE"] = onservice
            if onoff != None:
                self.Events["OFF"] = onoff
            if onmanual != None:
                self.Events["MANUAL"] = onmanual
            if onutilitychange != None:
                self.Events["OUTAGE"] = onutilitychange

            startcount = 0
            while startcount <= 10:
                try:
                    self.Generator = myclient.ClientInterface(host=host,
                                                              log=log)
                    break
                except Exception as e1:
                    startcount += 1
                    if startcount >= 10:
                        self.console.info("genmon not loaded.")
                        sys.exit(1)
                    time.sleep(1)
                    continue

            # start thread to accept incoming sockets for nagios heartbeat
            self.Threads["PollingThread"] = mythread.MyThread(
                self.MainPollingThread, Name="PollingThread")
        except Exception as e1:
            self.LogErrorLine("Error in mynotify init: " + str(e1))
Example #4
0
def signal_handler(signal, frame):

    sys.exit(0)


#------------------- Command-line interface for monitor -----------------#
if __name__ == '__main__':  # usage program.py [server_address]
    address = 'localhost' if len(sys.argv) < 2 else sys.argv[1]

    # log errors in this module to a file
    log = mylog.SetupLogger("client", "client.log")

    # Set the signal handler
    signal.signal(signal.SIGINT, signal_handler)

    MyClientInterface = myclient.ClientInterface(host=address, log=log)

    try:

        while True:
            try:
                line = raw_input(">")
            except NameError:
                pass
                line = input(">")

            if line.lower() == "exit":
                break
            if len(line):
                data = MyClientInterface.ProcessMonitorCommand(line)
                print(data)