Пример #1
0
        //ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)     ACTION(package0.collect_current_thread_id,package0.event_sequence,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.client_pid,sqlserver.database_id,sqlserver.database_name,sqlserver.is_system,sqlserver.nt_username,sqlserver.query_hash,sqlserver.request_id,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.session_server_principal_name,sqlserver.sql_text,sqlserver.transaction_id,sqlserver.username)     WHERE ([cpu_time]>(99)))
        public string AddEventActionText()
        {
            string setPrivateFields = string.Empty;
            string setGlobalActions = string.Empty;
            string setLocalActions  = string.Empty;
            string setWhereClause   = string.Empty;

            //if it's auto included, don't set
            if (EventFieldList != null && EventFieldList.Count() > 0)
            {
                int    counter = 0;
                string prefix  = "";
                setPrivateFields = "SET ";
                foreach (EventField evtfield in EventFieldList)
                {
                    if (evtfield.AutoInclude == false)
                    {
                        if (counter > 0)
                        {
                            prefix = " , ";
                        }

                        setPrivateFields += prefix + string.Format("{0}=(1)  ", evtfield.Name);
                        counter++;
                    }
                }
            }
            //if event requests specific actions capture them (we will not append to global actions since you can get into situations where you get too many actions error)
            if (this.EventActionList.Count() > 0)
            {
                setLocalActions = " ACTION (";
                for (int a = 0; a < this.EventActionList.Count(); a++)
                {
                    setLocalActions += this.EventActionList[a].FullName;
                    if (a != this.EventActionList.Count() - 1)
                    {
                        setLocalActions += ", ";
                    }
                    else
                    {
                        setLocalActions += ") ";
                    }
                }
                setGlobalActions = String.Copy(setLocalActions);
            }
            //otherwise go with global sction list (we will not append to event specific actions since you can get into situations where you get too many actions error)
            else if (XMgr.GlobalActionList != null && XMgr.GlobalActionList.Count() > 0)
            {
                setGlobalActions = " ACTION (";
                for (int i = 0; i < XMgr.GlobalActionList.Count(); i++)
                {
                    setGlobalActions += XMgr.GlobalActionList[i].FullName;
                    if (i != XMgr.GlobalActionList.Count() - 1)
                    {
                        setGlobalActions += ", ";
                    }
                    else
                    {
                        setGlobalActions += ") ";
                    }
                }
            }

            EventFilterCollection MyUserFilters = new EventFilterCollection();

            foreach (EventFilter evtFilter in XMgr.UserFilterList)
            {
                EventAction act   = XMgr.GlobalActionList.FindByNameIgnoreCase(evtFilter.Name);
                EventField  field = this.EventFieldList.Find(x => x.Name == evtFilter.Name);
                if (act != null || field != null)
                {
                    MyUserFilters.Add(evtFilter);
                }
            }
            //remove logical operator from last one
            if (MyUserFilters.Count > 0)
            {
                EventFilter evtFilter = MyUserFilters.Last <EventFilter>();
                evtFilter.LogicalOperator = string.Empty;
            }

            if (MyUserFilters != null && MyUserFilters.Count() > 0)
            {
                setWhereClause += " WHERE ( ";
                for (int i = 0; i < MyUserFilters.Count(); i++)
                {
                    EventFilter filt = MyUserFilters[i];
                    setWhereClause += filt.WhereClause + " ";
                }
                setWhereClause += ") ";
            }
            return(string.Format(AddEventTextTemplate, this.FullName, setPrivateFields, setGlobalActions, setWhereClause));
        }
Пример #2
0
        //ADD EVENT sqlserver.sql_batch_completed(SET collect_batch_text=(1)     ACTION(package0.collect_current_thread_id,package0.event_sequence,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.client_pid,sqlserver.database_id,sqlserver.database_name,sqlserver.is_system,sqlserver.nt_username,sqlserver.query_hash,sqlserver.request_id,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.session_server_principal_name,sqlserver.sql_text,sqlserver.transaction_id,sqlserver.username)     WHERE ([cpu_time]>(99)))

        public string AddEventActionText()
        {
            string setPrivateFields = string.Empty;
            string setGlobalActions = string.Empty;
            string setWhereClause   = string.Empty;


            //if it's auto included, don't set
            if (EventFieldList != null && EventFieldList.Count() > 0)
            {
                int    counter = 0;
                string prefix  = "";
                setPrivateFields = "SET ";
                foreach (EventField evtfield in EventFieldList)
                {
                    if (evtfield.AutoInclude == false)
                    {
                        if (counter > 0)
                        {
                            prefix = " , ";
                        }

                        setPrivateFields += prefix + string.Format("{0}=(1)  ", evtfield.Name);
                        counter++;
                    }
                }
            }
            if (XMgr.GlobalActionList != null && XMgr.GlobalActionList.Count() > 0)
            {
                setGlobalActions = " ACTION (";
                for (int i = 0; i < XMgr.GlobalActionList.Count(); i++)
                {
                    setGlobalActions += XMgr.GlobalActionList[i].FullName;
                    if (i != XMgr.GlobalActionList.Count() - 1)
                    {
                        setGlobalActions += ", ";
                    }
                    else
                    {
                        setGlobalActions += ") ";
                    }
                }
            }


            EventFilterCollection MyUserFilters = new EventFilterCollection();

            foreach (EventFilter evtFilter in XMgr.UserFilterList)
            {
                EventAction act   = XMgr.GlobalActionList.FindByNameIgnoreCase(evtFilter.Name);
                EventField  field = this.EventFieldList.Find(x => x.Name == evtFilter.Name);

                if (act != null || field != null)
                {
                    MyUserFilters.Add(evtFilter);
                }
            }



            //remove logical operator from laste one

            if (MyUserFilters.Count > 0)
            {
                EventFilter evtFilter = MyUserFilters.Last <EventFilter>();
                evtFilter.LogicalOperator = string.Empty;
            }

            if (MyUserFilters != null && MyUserFilters.Count() > 0)
            {
                setWhereClause += " WHERE ( ";
                for (int i = 0; i < MyUserFilters.Count(); i++)
                {
                    EventFilter filt = MyUserFilters[i];

                    setWhereClause += filt.WhereClause + " ";
                }

                setWhereClause += ") ";
            }


            return(string.Format(AddEventTextTemplate, this.FullName, setPrivateFields, setGlobalActions, setWhereClause));
        }