Beispiel #1
0
 private void DoPeriodicCheck(object sender, ElapsedEventArgs e)
 {
     heartbeatRunning = true;
     Collector.HandleMmonit(null);
     heartbeatRunning = false;
 }
Beispiel #2
0
        public MonitWindowsAgent()
        {
            Run                   = new Run_T();
            Run.id                = UniqueWindowsId.GetOrCreateUniqueId();
            Run.incarnation       = SystemStats.ProcessRunningInSec();
            Run.controlfile       = "none"; //TODO
            Run.startdelay        = 0;      //TODO
            Run.polltime          = 120;    //TODO
            Run.Env               = new myenvironment();
            Run.Env.user          = SystemStats.GetHostname();
            Run.httpd             = new Httpd_T();
            Run.httpd.port        = ConfigMgr.Config.Httpd.Port;
            Run.httpd.ssl         = ConfigMgr.Config.Httpd.SSL;
            Run.httpd.address     = ConfigMgr.Config.Httpd.BindIp;
            Run.httpd.credentials = new List <Auth_T>();
            Run.httpd.credentials.Add(new Auth_T
            {
                uname  = ConfigMgr.Config.Httpd.Username,
                passwd = ConfigMgr.Config.Httpd.Password
            });

            Run.mmonits = new List <Mmonit_T>();
            Run.mmonits.Add(new Mmonit_T
            {
                url = new URL_T
                {
                    url = ConfigMgr.Config.MMonits[0].Url,
                    //port = ConfigMgr.Config.MMonits[0].Port,
                    password = ConfigMgr.Config.MMonits[0].Password,
                    user     = ConfigMgr.Config.MMonits[0].Username
                }
            });

            servicelist      = new List <Service_T>();
            servicelist_conf = new List <Service_T>();
            ConfigMgr.Config.Services.ForEach(sc =>
            {
                var newS = ServiceHelper.CreateService(sc, sc.Name.ToLower());

                if (newS == null)
                {
                    Logger.Log.Error("Service could not be created!");
                }
                else
                {
                    if (sc is ProcessConfig)
                    {
                        ProcessHelper.AddProcess(newS);
                    }
                    else if (sc is FilesystemConfig)
                    {
                        FilesystemHelper.AddFilesystem(newS);
                    }
                }
            });

            servicegrouplist = new List <ServiceGroup_T>();
            systeminfo       = SystemInfoHelper.GetSystemInfo();

            m_timer           = new Timer(ConfigMgr.Config.Period);
            m_timer.Elapsed  += DoPeriodicCheck;
            m_timer.AutoReset = true;

            m_mMonitClient = new Collector();

            var service = ServiceHelper.GetSystemService();

            Run.system = new List <Service_T>();
            Run.system.Add(service);
        }
        /// <summary>
        ///     TODO
        ///     Handles the action.
        /// </summary>
        /// <param name="E">The e.</param>
        /// <param name="A">a.</param>
        private static void handleAction(Event_T E, Action_T A)
        {
            Service_T s;

            E.flag = MonitHandlerType.Handler_Succeeded;

            if (A.id == MonitActionType.Action_Ignored)
            {
                return;
            }

            /* Alert and mmonit event notification are common actions */
            E.flag |= Collector.HandleMmonit(E);
            E.flag |= Alert.HandleAlert(E);

            /* In the case that some subhandler failed, enqueue the event for
             * partial reprocessing */
            if (E.flag != MonitHandlerType.Handler_Succeeded)
            {
                if (!string.IsNullOrEmpty(MonitWindowsAgent.Run.eventlist_dir))
                {
                    eventQueueAdd(E);
                }
                else
                {
                    Logger.Log.Error("Aborting event");
                }
            }

            if ((s = GetSource(E)) == null)
            {
                Logger.Log.Error("Event action handling aborted");
                return;
            }

            /* Action event is handled already. For Instance events
             * we don't want actions like stop to be executed
             * to prevent the disabling of system service monitoring */
            if (A.id == MonitActionType.Action_Alert || E.id == MonitEventType.Event_Instance)
            {
            }
            if (A.id == MonitActionType.Action_Exec)
            {
                Logger.Log.InfoFormat("'{0}'", s.name);
                //spawn(s, A.exec, E);
            }
            else
            {
                if (s.actionratelist != null &&
                    (A.id == MonitActionType.Action_Start || A.id == MonitActionType.Action_Restart))
                {
                    s.nstart++;
                }

                if (s.mode == MonitMonitorModeType.Monitor_Passive &&
                    (A.id == MonitActionType.Action_Start || A.id == MonitActionType.Action_Stop ||
                     A.id == MonitActionType.Action_Restart))
                {
                    return;
                }

                Control.ControlService(s.name, A.id);
            }
        }