Bro - write two filters for database - bro

I'm trying to push my bro data to a database. The example with the conn table works. Now I want to add the http log as well. I've created a new filter in the misc folder, added it to my bro-default and restarted my bro but it doesn't add the new table. What is wrong with my filter?
event bro_init()
{
local filter: Log::Filter =
[
$name="sqlite",
$path="/var/db/conn",
$config=table(["tablename"] = "http"),
$writer=Log::WRITER_SQLITE
];
Log::add_filter(HTTP::LOG, filter);
}

Found the problem. Both of my filters had the same name filter. The moment I changed the name it worked fine.

Related

How to add an array of datarows into an exisitng table inside my database

I'm a newbie so don't laugh :#
I'm working with 2002-2003 Microsoft access database.
Now, I want to add an array of DataRow into an existing table that I've in my database. Is there a way to do that? because right now I'm just adding the rows with a foreach loop
thank you
I think that the foreach-loop actually is the best way to do it.
foreach(DataRow row in yourRowArray)
{
dataTable.Add(row);
}
If you are using .Net Framework 3.5+ you can also use the DataRows CopyToDataTable() Method.
But you have to watch out because the Data in the DataTable is overwritten in this case.
DataTable table = yourDataTable;
DataRow[] yourRowArray = ...;
if(yourRowArray.Length > 0)
{
table = yourRowArray.CopyToDataTable();
}
I would recommend using the foreach-loop.
What you describe as array must be a saved file type i.e. excel or csv. Be sure it is a clean grid of data without extraneous non aligned rows.
Then you can link to that file with Access as a table. This is a manual step using the Access interface - in the ribbon it is the External area. This link remains good - allowing you to replace the excel/csv with a new one as long as the location path and structure of the file do not change.
Then you create an Append query to write all the records from this table into the table in your Access database.
www.CahabaData.com

How to Get a data from a table and insert another table in YII form

I am newbe in YII. Apologies for simple and stupid question.
I messed up my system. In that Case I need your help to clear the concept :: my question is :::
How to Get a data from a table and insert another table in YII form ::::
means---> I want to get data and view in form field --> how can I do that ??
please help me out
Generate a model using gii. It will do all what you need and hopefully you can get the code for that.
localhost:2010/index.php?r=gii
Use Above changing your host and port to see Gii.
You have to Enable Gii in the Config file before doing this
$modelA = ModelA:;model()->find('somecondition');
$modelB= new ModelB();
$modelB->attribute1 = $modelA->attribute1;
$modelB->attribute2 = $modelA->attribute2;
$modelB->attribute3 = $modelA->attribute3;
$modelB->attribute4 = $modelA->attribute4;
$modelB->attribute5 = $modelA->attribute5;
$modelB->save();
Try this..

Return newly inserted row without having to Submit to database

I need to find a way to get the newly insert row, without previously having to save to the database.
Is there a way? Or I need to keep the whole collection of row in a separated array?
Is this example I adding a row to the table tblConfig, but when I look back in the table the new row is not there.
tblConfig Config = new tblConfig { ID = Guid.NewGuid(), Code ="new config code" };
CTX.tblConfig.InsertOnSubmit(Config);
var Data = from dd in CTX.tblConfig select dd;
this.dataGridView1.DataSource = Data;
After some research , I'll do the work by attaching my LINQ query to a BindingSource object, witch will help me handle with insertion update and so.
Thanks for everyone, for your help :)
Hugo
Could you add that manually like this?
this.dataGridView1.DataSource = CTX.tblConfig.Execute(MergeOption.AppendOnly);

How can I see CakePHP's SQL dump in the controller?

Is there a way that one can cause CakePHP to dump its SQL log on demand? I'd like to execute code up until a point in my controller and see what SQL has been run.
Try this:
$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
http://api.cakephp.org/2.3/class-Model.html#_getDataSource
You will have to do this for each datasource if you have more than one though.
There are four ways to show queries:
This will show the last query executed of user model:
debug($this->User->lastQuery());
This will show all executed query of user model:
$log = $this->User->getDataSource()->getLog(false, false);
debug($log);
This will show a log of all queries:
$db =& ConnectionManager::getDataSource('default');
$db->showLog();
If you want to show all queries log all over the application you can use in view/element/filename.ctp.
<?php echo $this->element('sql_dump'); ?>
If you're using CakePHP 1.3, you can put this in your views to output the SQL:
<?php echo $this->element('sql_dump'); ?>
So you could create a view called 'sql', containing only the line above, and then call this in your controller whenever you want to see it:
$this->render('sql');
(Also remember to set your debug level to at least 2 in app/config/core.php)
Source
for cakephp 2.0
Write this function in AppModel.php
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
To use this in Controller
Write : echo $this->YourModelName->getLastQuery();
It is greatly frustrating that CakePHP does not have a $this->Model->lastQuery();. Here are two solutions including a modified version of Handsofaten's:
1. Create a Last Query Function
To print the last query run, in your /app_model.php file add:
function lastQuery(){
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
// return the first element of the last array (i.e. the last query)
return current(end($logs));
}
Then to print output you can run:
debug($this->lastQuery()); // in model
OR
debug($this->Model->lastQuery()); // in controller
2. Render the SQL View (Not avail within model)
To print out all queries run in a given page request, in your controller (or component, etc) run:
$this->render('sql');
It will likely throw a missing view error, but this is better than no access to recent queries!
(As Handsofaten said, there is the /elements/sql_dump.ctp in cake/libs/view/elements/, but I was able to do the above without creating the sql.ctp view. Can anyone explain that?)
In CakePHP 1.2 ..
$db =& ConnectionManager::getDataSource('default');
$db->showLog();
What worked finally for me and also compatible with 2.0 is to add in my layout (or in model)
<?php echo $this->element('sql_dump');?>
It is also depending on debug variable setted into Config/core.php
Plugin DebugKit for cake will do the job as well. https://github.com/cakephp/debug_kit
If you are interested in some specific part of code, you can clear first the log, and then display only queries that happen after that point.
Also note that 'Model' below, is the actual class name, like User, Page etc.
//clear log (boolean $clear = true)
$this->Model->getDataSource()->getLog(false, true);
...
...
...
...
//Show log so far
$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);
exit;

Cannot add new Workitems using TFS API

Hi I am trying to add new workitems to the TFS repository using the API, but when I validate the workitem before it is saved, it returns an error. I previously got exceptions regarding the field definitions for a bug namely, Symptom, Steps to Reproduce and Triage. (Error code TF 26027). The code snippet is shown below: Can anyone tell me what's wrong here?
switch (workItemType)
{
case "Bug":
{
workItem.Title = values["Title"].ToString();
workItem.State = values["State"].ToString();
workItem.Reason = values["Reason"].ToString();
workItem.Fields["Priority"].Value = values["Priority"].ToString();
workItem.Fields["Severity"].Value = values["Severity"].ToString();
//workItem.Fields["Triage"].Value = values["Triage"].ToString();
workItem.Fields["Assigned To"].Value = values["Assigned To"].ToString();
//workItem.Fields["Symptom"].Value = values["Symptom"].ToString();
//workItem.Fields["Steps to Reproduce"].Value = values["Steps to Reproduce"].ToString();
// Validate the Work Item fields.
ArrayList result = workItem.Validate();
// If any invalid fields are returned, report an error.
if (result.Count > 0)
MessageBox.Show("An Error occurred while adding the Bug to the repository.");
else
workItem.Save();
}
break;
To find the available field definitions, you can iterate over the collection (FieldDefinitions). The Name and ReferenceName properties are the values you can index by into the collection.
the Field "Symptom" cannot be empty
Just reading the error message it looks like you are defining a field called "somefield" in your work item. I'm thinking that you have some old code hanging around elsewhere, maybe above the code snippet you posted, where you are defining a value for workItem.Fields["somefield"]
Old question, but hopefully helps someone. The field name is "Repro Steps"
.Fields["Repro Steps"].Value