Beispiel #1
0
        public static DataTable GetData(string queryST, ref string retErr)
        {
            DataTable EventDT = new DataTable("EventDT");

            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the Event Log Input Format object
                EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();

                // Set its "direction" parameter to "BW"
                oEVTInputFormat.direction = "BW";

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oEVTInputFormat);

                int i = 0;

                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    EventDT.Columns.Add(new DataColumn(colnm, typeof(string)));
                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    // populate holding table with site name & summary bytes for the period
                    DataRow dr = EventDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    EventDT.Rows.Add(dr);
                }


                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return(EventDT);
        }
Beispiel #2
0
        public static DataTable FSquery(string queryST, ref string retErr)
        {
            DataTable resultsDT = new DataTable("resultsDT");

            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the File System Input Format object
                FileSystemInputFormat oFSInputFormat = new MSUtil.COMFileSystemInputContextClassClass();

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oFSInputFormat);
                int          i          = 0;
                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    resultsDT.Columns.Add(new DataColumn(colnm, typeof(string)));
                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    DataRow dr = resultsDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    resultsDT.Rows.Add(dr);
                }

                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return(resultsDT);
        }
Beispiel #3
0
        public static DataTable FSquery(string queryST, ref string retErr)
        {
            DataTable resultsDT = new DataTable("resultsDT");
            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the File System Input Format object
                FileSystemInputFormat oFSInputFormat = new MSUtil.COMFileSystemInputContextClassClass();

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oFSInputFormat);
                int i = 0;
                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    resultsDT.Columns.Add(new DataColumn(colnm, typeof(string)));

                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    DataRow dr = resultsDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    resultsDT.Rows.Add(dr);
                }

                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return resultsDT;
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lblServerName.Text = System.Environment.MachineName.ToString();
            lblServerName2.Text = System.Environment.MachineName.ToString();

            string strEventLog;
            string strNumberOfEvents;

            if (!Page.IsPostBack)
            {
                strEventLog = "Application";
                strNumberOfEvents = "15";
            }

            strEventLog = ddlEventLog.SelectedItem.Value;
            strNumberOfEvents = ddlNumberOfEvents.SelectedItem.Value;

            Top10Events("APPLICATION");
            Top10Events("SYSTEM");

            try
            {

               // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the Event Log Input Format object
                EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();

                // Instantiate the data tables, columns and rows....
                DataTable dtData = new DataTable("results");
                DataColumn dtColumn = new DataColumn("timeGenerated");
                dtData.Columns.Add(dtColumn);

                DataColumn dtColumn2 = new DataColumn("sourcename");
                dtData.Columns.Add(dtColumn2);

                DataColumn dtColumn3 = new DataColumn("eventid");
                dtData.Columns.Add(dtColumn3);

                DataColumn dtColumn4 = new DataColumn("message");
                dtData.Columns.Add(dtColumn4);

                // Set its "direction" parameter to "BW"
                oEVTInputFormat.direction = "BW";

                // Create the query
                string query = @"SELECT TOP " + strNumberOfEvents + " TimeGenerated, SourceName, EventID, Message FROM " + strEventLog;

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(query, oEVTInputFormat);

                // Browse the recordset
                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    LogRecord oRecord = oRecordSet.getRecord();
                    DataRow row = dtData.NewRow();

                    row[0] = oRecord.getValue(0);
                    row[1] = oRecord.getValue(1);
                    row[2] = oRecord.getValue(2);
                    row[3] = oRecord.getValue(3);

                    dtData.Rows.Add(row);

                   // Console.WriteLine(oRecordSet.getRecord().toNativeString(","));
                }

                // Close the recordset
                oRecordSet.close();

                DataSet ds = new DataSet();
                ds.Tables.Add(dtData);

                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
            catch (System.Runtime.InteropServices.COMException exc)
            {
                //Console.WriteLine("Unexpected error: " + exc.Message);
            }
        }
Beispiel #5
0
        private void Top10Events(string strEventLogName)
        {
            try
            {

                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the Event Log Input Format object
                EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();

                // Instantiate the data tables, columns and rows....
                DataTable dtData = new DataTable("results");
                DataColumn dtColumn = new DataColumn("hits");
                dtData.Columns.Add(dtColumn);

                DataColumn dtColumn2 = new DataColumn("sourcename");
                dtData.Columns.Add(dtColumn2);

                // Create the query
                string query = @"SELECT TOP 10 distinct count(*) as hits, SourceName FROM " + strEventLogName + " where eventtype='1' group by sourcename order by hits desc";

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(query, oEVTInputFormat);

                // Browse the recordset
                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    LogRecord oRecord = oRecordSet.getRecord();
                    DataRow row = dtData.NewRow();

                    row[0] = oRecord.getValue(0);
                    row[1] = oRecord.getValue(1);

                    dtData.Rows.Add(row);

                    // Console.WriteLine(oRecordSet.getRecord().toNativeString(","));
                }

                // Close the recordset
                oRecordSet.close();

                DataSet ds = new DataSet();
                ds.Tables.Add(dtData);

                if (strEventLogName == "APPLICATION")
                {
                    GridView2.DataSource = ds;
                    GridView2.DataBind();
                }
                else
                {
                    GridView3.DataSource = ds;
                    GridView3.DataBind();
                }

                //GridView1.DataSource = ds;
                //GridView1.DataBind();
            }
            catch (System.Runtime.InteropServices.COMException exc)
            {
                //Console.WriteLine("Unexpected error: " + exc.Message);
                lblAppEvtError.Text = "[Unexpected error: " + exc.Message + "]";
            }
        }
        public static QueryResult Execute(string query, string inputName, Dictionary <PropertyInfo, object> properties)
        {
            Stopwatch watch             = Stopwatch.StartNew();
            int       maxUnitsInResults = 5000;       // TODO add this to user settings

            MSUtil.LogQueryClassClass logQuery = new MSUtil.LogQueryClassClass();

            QueryResult queryResult = new QueryResult();

            object inputFormat = SqalpApplication.Inputs[inputName].CreateInstance();

            foreach (PropertyInfo propertyInfo in properties.Keys)
            {
                try
                {
                    propertyInfo.SetValue(inputFormat, properties[propertyInfo], null);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }


            MSUtil.ILogRecordset recordset = logQuery.Execute(query, inputFormat);

            bool columnsExtracted = false;
            long unitProcessed    = 0;

            // Browse the recordset
            for (; !recordset.atEnd() && unitProcessed < maxUnitsInResults /* && !cancelComputing.WaitOne(0,false) */; recordset.moveNext())
            {
                MSUtil.ILogRecord record = recordset.getRecord();

                // Remplissage des colonnes
                if (!columnsExtracted)
                {
                    for (int c = 0; c < recordset.getColumnCount(); c++)
                    {
                        DataColumn col = new DataColumn(recordset.getColumnName(c));
                        //object logRecord = record.getValueEx(c);
                        switch (recordset.getColumnType(c))
                        {
                        case 1:                                 // int32
                            col.DataType = typeof(int);
                            break;

                        case 2:                                 // double
                            col.DataType = typeof(double);
                            break;

                        case 4:                                 // datetime
                            col.DataType = typeof(DateTime);
                            break;

                        default:
                            col.DataType = typeof(string);
                            break;
                        }

                        queryResult.DataTable.Columns.Add(col);
                    }
                    columnsExtracted = true;
                }

                // on insert les datas
                DataRow dr = queryResult.DataTable.NewRow();
                dr[0] = record.getValue(0).ToString();

                //dataTableResults.ExtendedProperties.Add("source", record.getValue(0).ToString());

                for (int c = 1; c < recordset.getColumnCount(); c++)
                {
                    if (record.getValue(c) != DBNull.Value)
                    {
                        dr[c] = record.getValue(c).ToString();
                    }
                }
                //logQuery.inputUnitsProcessed;
                unitProcessed++;
                queryResult.DataTable.Rows.Add(dr);
                // MainForm.StatusBar.Text = string.Format("Computing in progress ... {0} line(s)",unitProcessed);
            }
            // MainForm.StatusBar.Text = string.Format("{0} input units processed",recordset.inputUnitsProcessed);
            recordset.close();


            queryResult.Duration = watch.Elapsed;

            if (logQuery != null)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(logQuery);
                GC.SuppressFinalize(logQuery);
                logQuery = null;
            }

            return(queryResult);
        }
Beispiel #7
0
        public static DataTable GetData(string queryST, ref string retErr)
        {
            DataTable EventDT = new DataTable("EventDT");

            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the Event Log Input Format object
                EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();

                // Set its "direction" parameter to "BW"
                oEVTInputFormat.direction = "BW";

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oEVTInputFormat);

                int i = 0;

                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    EventDT.Columns.Add(new DataColumn(colnm, typeof(string)));
                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    // populate holding table with site name & summary bytes for the period
                    DataRow dr = EventDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    EventDT.Rows.Add(dr);
                }

                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return EventDT;
        }