Example #1
0
        /// <summary>
        ///     Events the get action.
        /// </summary>
        /// <param name="E">The e.</param>
        /// <returns></returns>
        public static MonitActionType GetAction(Event_T E)
        {
            Action_T A = null;

            switch (E.state)
            {
            case MonitStateType.State_Succeeded:
            case MonitStateType.State_ChangedNot:
                A = E.action.succeeded;
                break;

            case MonitStateType.State_Failed:
            case MonitStateType.State_Changed:
            case MonitStateType.State_Init:
                A = E.action.failed;
                break;

            default:
                Logger.Log.ErrorFormat("Invalid event state: {0}", E.state);
                return(MonitActionType.Action_Ignored);
            }
            if (A == null)
            {
                return(MonitActionType.Action_Ignored);
            }
            /* In the case of passive mode we replace the description of start, stop or restart action for alert action, because these actions are passive in this mode */
            return((E.mode == MonitMonitorModeType.Monitor_Passive &&
                    ((A.id == MonitActionType.Action_Start) || (A.id == MonitActionType.Action_Stop) ||
                     (A.id == MonitActionType.Action_Restart)))
                ? MonitActionType.Action_Alert
                : A.id);
        }
 public static void PrintEventratio(Action_T action, StringBuilder buf)
 {
     if (action.cycles > 1)
     {
         if (action.count == action.cycles)
         {
             buf.AppendFormat("for {0} cycles ", action.cycles);
         }
         else
         {
             buf.AppendFormat("for {0} times within {1} cycles ", action.count, action.cycles);
         }
     }
 }
 public static void PrintAction(Action_T A, StringBuilder buf)
 {
     buf.Append(MonitWindowsAgent.actionnames[(int)A.id]);
     if (A.id == MonitActionType.Action_Exec)
     {
         buf.Append(A.exec.Method.Name);
         //var C = A.exec;
         //for (int i = 0; C.arg[i]; i++)
         //        buf.AppendFormat("{0}{1}", i != 0 ? " " : " '", C.arg[i]);
         //buf.Append("'");
         //if (C.has_uid)
         //        buf.AppendFormat(" as uid {0}", C.uid);
         //if (C.has_gid)
         //        buf.AppendFormat(" as gid {0}", C.gid);
         //if (C.timeout)
         //        buf.AppendFormat(" timeout {0} cycle(s)", C.timeout);
     }
 }
Example #4
0
        /// <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 |= MMonit.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);
            }
        }