public JObject ReadToJson(ILogRecord row) { var json = new JObject(); foreach (var field in this.fields) { if (this.columnMap.ContainsKey(field.Name)) { object v = row.getValue(field.Name); if (field.DataType == typeof(DateTime)) { DateTime dt = DateTime.Parse(v.ToString()); json.Add(new JProperty(field.Name, dt)); } else { json.Add(new JProperty(field.Name, v)); } } } AddTimestamp(json); return(json); }
//TODO: add methods for other types // W3C - COMW3CInputContextClassClass // NCSA - COMIISNCSAInputContextClassClass private static DataTable Execute <T>(string query) where T : new() { LogQueryClassClass log = new LogQueryClassClass(); ILogRecordset recordset = log.Execute(query, new T()); ILogRecord record = null; DataTable dt = new DataTable(); Int32 columnCount = recordset.getColumnCount(); for (int i = 0; i < columnCount; i++) { dt.Columns.Add(recordset.getColumnName(i), types[recordset.getColumnType(i) - 1]); } for (; !recordset.atEnd(); recordset.moveNext()) { DataRow dr = dt.NewRow(); record = recordset.getRecord(); for (int i = 0; i < columnCount; i++) { dr[i] = record.getValue(i); } dt.Rows.Add(dr); } return(dt); }
public string GetLogMetadata() { StringBuilder result = new StringBuilder(); ILogRecordset logRecordset = _logQuery.Execute($"SELECT Field2 as logLevel, COUNT(*) AS rowCount FROM {_logFileName} GROUP BY Field2", _input); while (!logRecordset.atEnd()) { ILogRecord record = logRecordset.getRecord(); if (!string.IsNullOrEmpty(record.getValue("logLevel").ToString())) { result.Append($"Level: {record.getValue("logLevel")}; Count: {record.getValue("rowCount")}\n"); } logRecordset.moveNext(); } return(result.ToString()); }
public int GerErrorsCount() { int result = 0; ILogRecordset logRecordset = _logQuery.Execute($"SELECT COUNT(*) AS rowCount FROM {_logFileName} WHERE Field2 = 'ERROR'", _input); while (!logRecordset.atEnd()) { ILogRecord record = logRecordset.getRecord(); result = record.getValue("rowCount"); logRecordset.moveNext(); } return(result); }
public void getLogTable(object sender, EventArgs e) { LogTable.Rows.Clear(); Logger l = new Logger(query.Text); ILogRecordset result = l.executeCommand(); ILogRecord dataRow = null; TableHeaderRow header = new TableHeaderRow(); TableHeaderCell headerCell; for (int i = 0; i < result.getColumnCount(); i++) { headerCell = new TableHeaderCell(); headerCell.Text = result.getColumnName(i); headerCell.CssClass = "forumHeader"; headerCell.Style.Add("border", "1px solid black"); header.Cells.Add(headerCell); } LogTable.Rows.Add(header); while (!result.atEnd()) { dataRow = result.getRecord(); TableRow row = new TableRow(); TableCell cell; for (int i = 0; i < result.getColumnCount(); i++) { cell = new TableCell(); cell.Text = dataRow.getValue(i).ToString(); cell.Style.Add("border", "1px solid black"); row.Cells.Add(cell); } LogTable.Rows.Add(row); result.moveNext(); } }
public JObject ReadToJson(ILogRecord row) { var json = new JObject(); foreach (var field in this.fields) { if (this.columnMap.ContainsKey(field.Name)) { object v = row.getValue(field.Name); if (field.DataType == typeof(DateTime)) { DateTime dt = DateTime.Parse(v.ToString()); json.Add(new JProperty(field.Name, dt)); } else { json.Add(new JProperty(field.Name, v)); } } } AddTimestamp(json); return json; }
public override void Import(DateTime @from) { var logQuery = new LogQueryClass(); var inputFormat = new COMW3CInputContextClass(); string strQuery = string.Format(@"SELECT to_timestamp(date, time) as date, s-ip as sourceIP, cs-method as method, cs-uri-stem as uri, cs-uri-query as query, s-port as port, c-ip as clientIP, cs(User-Agent) as userAgent, cs-host as clientToServerHost, sc-status as statusCode, sc-substatus as subStatus, sc-win32-status as win32Status, sc-bytes as serverToClientBytes, cs-bytes as clientToServerBytes, time-taken as duration FROM {0}", "SOME FILE"); ILogRecordset results = logQuery.Execute(strQuery, inputFormat); var tweets = new List <Entry>(); while (!results.atEnd()) { ILogRecord logRecord = results.getRecord(); dynamic date = logRecord.getValue("date"); dynamic sourceIP = logRecord.getValue("sourceIP"); dynamic method = logRecord.getValue("method"); dynamic uri = logRecord.getValue("uri"); dynamic query = logRecord.getValue("query") is DBNull ? string.Empty : logRecord.getValue("query"); dynamic port = logRecord.getValue("port"); dynamic clientIP = logRecord.getValue("clientIP") is DBNull ? string.Empty : logRecord.getValue("clientIP"); dynamic userAgent = logRecord.getValue("userAgent") is DBNull ? string.Empty : logRecord.getValue("userAgent"); dynamic clientToServerHost = logRecord.getValue("clientToServerHost") is DBNull ? string.Empty : logRecord.getValue("clientToServerHost"); dynamic statusCode = logRecord.getValue("statusCode"); dynamic subStatus = logRecord.getValue("subStatus"); dynamic win32Status = logRecord.getValue("win32Status"); dynamic serverToClientBytes = logRecord.getValue("serverToClientBytes"); dynamic clientToServerBytes = logRecord.getValue("clientToServerBytes"); dynamic duration = logRecord.getValue("duration"); tweets.Add(new Entry { Date = date, SourceIP = sourceIP, Method = method, Uri = uri, Query = query, Port = port, ClientIP = clientIP, UserAgent = userAgent, ClientToServerHost = clientToServerHost, StatusCode = statusCode, SubStatus = subStatus, Win32Status = win32Status, ServerToClientBytes = serverToClientBytes, ClientToServerBytes = clientToServerBytes, Duration = duration }); results.moveNext(); } var serializer = new JsonNetSerializer(); string bulkCommand = new BulkCommand(index: "log", type: "iis"); string bulkJson = new BulkBuilder(serializer) .BuildCollection(tweets, (builder, tweet) => builder.Create(tweet) ); _connection.Post(bulkCommand, bulkJson); }
public override void ImportToDatabase(ILogRecord record, DateTime date) { if (ConfigurationManager.AppSettings["AddToDatabase"] == "1") { using(IDnaDataReader dataReader = StoredProcedureReader.Create("impressionswrite")) { dataReader.AddParameter("@date", DateTime.Parse(record.getValue("DateTime").ToString())); dataReader.AddParameter("@machine_name", record.getValue("ComputerName")); dataReader.AddParameter("@http_method", record.getValue("Method")); dataReader.AddParameter("@http_status", record.getValue("Status")); dataReader.AddParameter("@url", record.getValue("URL")); dataReader.AddParameter("@site", String.IsNullOrEmpty(record.getValue("Site").ToString()) ? "UNKNOWN" : record.getValue("Site").ToString()); dataReader.AddParameter("@count", Int32.Parse(record.getValue("count").ToString())); dataReader.AddParameter("@min", Int32.Parse(record.getValue("min").ToString())); dataReader.AddParameter("@max", Int32.Parse(record.getValue("max").ToString())); dataReader.AddParameter("@avg", Int32.Parse(record.getValue("avg").ToString())); dataReader.Execute(); } } }
private Result Map(ILogRecord record) { var value = -1; var dateTime = DateTime.Now; var name = string.Empty; var r = record.getValue(0); if ((r is string)) { name = Convert.ToString(r); } if ((r is int) || (r is decimal)) { value = Convert.ToInt32(r); } r = record.getValue(1); if ((r is string)) { name = Convert.ToString(r); } if ((r is int) || (r is decimal)) { value = Convert.ToInt32(r); } //Console.WriteLine(record.getValue(0).GetType()); //Console.WriteLine(record.getValue(1).GetType()); try { //Console.WriteLine(record.getValue(2)); } catch (Exception ex) { var s = ex.Message; } //Console.WriteLine(string.Format("{0} {1}", record.getValue(0), record.getValue(1))); //for (int i = 0; i < record.; i++) //{ // if (record[i] is string) // { // name = Convert.ToString(record[i]); // } // if (record[i] is int || record[i] is decimal) // { // value = Convert.ToInt32(record[i]); // } // if (record[i] is DateTime) // { // dateTime = Convert.ToDateTime(record[i]); // } //} if (this.Name != string.Empty && name == string.Empty) { name = this.Name; } this.Log.Debug(string.Format("Got [{1}] {0}", value, dateTime)); var result = new Result(name, dateTime, this.Path); result.SetValue(value); return result; }