posibility to execute a command on event.. ?
in root. .... remember position? ok..
maybe can be and alarm on the zm machine.!!
or other things... .. i thing cant be so hard..
allways commands in root mode.
execute a command in event..
- zoneminder
- Site Admin
- Posts: 5215
- Joined: Wed Jul 09, 2003 2:07 pm
- Location: Bristol, UK
- Contact:
Re: execute a command in event..
Hi Fernando,
At the moment there is no 'simple' way of doing this. Probably the easiest way is to write a little script that periodicaly polls the shared memory and checks for either the last event id increasing or the state going into alarm (or both). You can probably base it on one of zmfilter.pl, zmx10.pl or zmwatch.pl which all do a similar thing.
In a forthcoming release I will be changing things slightly to expand on the concept of 'triggers' whereby a monitor can receive or transmit information when various circumstances occur. This will be similar to the current support for X10 but more extensible.
Cheers,
Phil,
At the moment there is no 'simple' way of doing this. Probably the easiest way is to write a little script that periodicaly polls the shared memory and checks for either the last event id increasing or the state going into alarm (or both). You can probably base it on one of zmfilter.pl, zmx10.pl or zmwatch.pl which all do a similar thing.
In a forthcoming release I will be changing things slightly to expand on the concept of 'triggers' whereby a monitor can receive or transmit information when various circumstances occur. This will be similar to the current support for X10 but more extensible.
Cheers,
Phil,
Re: execute a command in event..
Hi Fernando and Phil,
here a very quick and messy implementation of what you need (the code is terrible).
Basically it should be a daemon going to verify into the mysql database if the event id counter is incrased or not.
Even if the code is bad I post it because is working (actually id just beeps in case of event but it's trivial to make it do anything)
Luigi
*-------------------------------*
#!/usr/bin/perl -w
# GPL License v 2.0 - Made by Luigi Paiella - 05-08-2003
#
# Last UPDATE
# rev 0.0.0 - 05-08-2003
#Creazione
#
use constant ZM_PATH_BIN => "/usr/local/bin"; # Path to the ZoneMinder executables, autogenerated do not change (from zmconfig)
use constant ZM_DB_SERVER => "localhost"; # Machine on which the database server is running (from zmconfig)
use constant ZM_DB_NAME => "zm"; # Database containing the tables (from zmconfig)
use constant ZM_DB_USERA => "root"; # Privileged DB user name, needs at least select, insert, update and delete privileges (from zmconfig)
use constant ZM_DB_PASSA => "whatever"; # Privileged DB user password (from zmconfig)
# Load the config from the database into the symbol table
BEGIN
{
use DBI;
no strict 'refs';
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA );
my $sql = qq{select max(Id) from Events};
my $sth = $dbh->prepare( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
my( $id );
$sth->bind_columns( undef, \$id );
while( $sth->fetch() ) {
print "$id\n";
}
my $last_id=$id;
while( 1 )
{
my $sth = $dbh->prepare( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
$sth->bind_columns( undef, \$id );
while( $sth->fetch() ) {
print "$id\n";
}
if ( $id ne $last_id)
{
print "\a"; #just a beep! but put here your command
$last_id=$id;
}
}
}
sleep(10); #ritardo per non sovraccaricare cpu
$sth->finish();
$dbh->disconnect();
}
exit();
here a very quick and messy implementation of what you need (the code is terrible).
Basically it should be a daemon going to verify into the mysql database if the event id counter is incrased or not.
Even if the code is bad I post it because is working (actually id just beeps in case of event but it's trivial to make it do anything)
Luigi
*-------------------------------*
#!/usr/bin/perl -w
# GPL License v 2.0 - Made by Luigi Paiella - 05-08-2003
#
# Last UPDATE
# rev 0.0.0 - 05-08-2003
#Creazione
#
use constant ZM_PATH_BIN => "/usr/local/bin"; # Path to the ZoneMinder executables, autogenerated do not change (from zmconfig)
use constant ZM_DB_SERVER => "localhost"; # Machine on which the database server is running (from zmconfig)
use constant ZM_DB_NAME => "zm"; # Database containing the tables (from zmconfig)
use constant ZM_DB_USERA => "root"; # Privileged DB user name, needs at least select, insert, update and delete privileges (from zmconfig)
use constant ZM_DB_PASSA => "whatever"; # Privileged DB user password (from zmconfig)
# Load the config from the database into the symbol table
BEGIN
{
use DBI;
no strict 'refs';
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_SERVER, ZM_DB_USERA, ZM_DB_PASSA );
my $sql = qq{select max(Id) from Events};
my $sth = $dbh->prepare( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
my( $id );
$sth->bind_columns( undef, \$id );
while( $sth->fetch() ) {
print "$id\n";
}
my $last_id=$id;
while( 1 )
{
my $sth = $dbh->prepare( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
$sth->bind_columns( undef, \$id );
while( $sth->fetch() ) {
print "$id\n";
}
if ( $id ne $last_id)
{
print "\a"; #just a beep! but put here your command
$last_id=$id;
}
}
}
sleep(10); #ritardo per non sovraccaricare cpu
$sth->finish();
$dbh->disconnect();
}
exit();