Added auto script execution for filters.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1016 e3e1d417-86f3-4887-817a-d78f3d33393fpull/27/merge
parent
c6d67fc431
commit
5c3be53b33
|
@ -156,7 +156,7 @@ sub DateTimeToSQL
|
|||
my $dt_val = strtotime( $dt_str );
|
||||
if ( !$dt_val )
|
||||
{
|
||||
print( STDERR "Error, unable to parse date string '$dt_str'" );
|
||||
print( STDERR "Error, unable to parse date string '$dt_str'\n" );
|
||||
return( undef );
|
||||
}
|
||||
return( strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
|
||||
|
@ -242,7 +242,7 @@ while( 1 )
|
|||
sub GetFilters
|
||||
{
|
||||
my @filters;
|
||||
my $sql = "select * from Filters where (AutoArchive = 1 or AutoDelete = 1 or AutoUpload = 1 or AutoEmail = 1 or AutoMessage = 1) order by Name";
|
||||
my $sql = "select * from Filters where (AutoArchive = 1 or AutoDelete = 1 or AutoUpload = 1 or AutoEmail = 1 or AutoMessage = 1 or AutoExecute != '') order by Name";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
|
||||
FILTER: while( my $filter_data = $sth->fetchrow_hashref() )
|
||||
|
@ -326,7 +326,7 @@ sub GetFilters
|
|||
$value = DateTimeToSQL( $temp_value );
|
||||
if ( !$value )
|
||||
{
|
||||
print( STDERR "Error parsing date/time '$value', skipping filter '$filter_data->{Name}'\n" );
|
||||
print( STDERR "Error parsing date/time '$temp_value', skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
}
|
||||
$value = "'$value'";
|
||||
|
@ -336,7 +336,7 @@ sub GetFilters
|
|||
$value = DateTimeToSQL( $temp_value );
|
||||
if ( !$value )
|
||||
{
|
||||
print( STDERR "Error parsing date/time '$value', skipping filter '$filter_data->{Name}'\n" );
|
||||
print( STDERR "Error parsing date/time '$temp_value', skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
}
|
||||
$value = "to_days( '$value' )";
|
||||
|
@ -346,7 +346,7 @@ sub GetFilters
|
|||
$value = DateTimeToSQL( $temp_value );
|
||||
if ( !$value )
|
||||
{
|
||||
print( STDERR "Error parsing date/time '$value', skipping filter '$filter_data->{Name}'\n" );
|
||||
print( STDERR "Error parsing date/time '$temp_value', skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
}
|
||||
$value = "extract( hour_second from '$value' )";
|
||||
|
@ -356,7 +356,7 @@ sub GetFilters
|
|||
$value = DateTimeToSQL( $temp_value );
|
||||
if ( !$value )
|
||||
{
|
||||
print( STDERR "Error parsing date/time '$value', skipping filter '$filter_data->{Name}'\n" );
|
||||
print( STDERR "Error parsing date/time '$temp_value', skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
}
|
||||
$value = "weekday( '$value' )";
|
||||
|
@ -407,6 +407,21 @@ sub GetFilters
|
|||
$sql .= " order by E.Id";
|
||||
#print $sql."\n";
|
||||
$filter_data->{Sql} = $sql;
|
||||
if ( $filter_data->{AutoExecute} )
|
||||
{
|
||||
my $script = $filter_data->{AutoExecute};
|
||||
if ( !-e $script )
|
||||
{
|
||||
print( STDERR "Error, auto execute script '$script' not found, skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
|
||||
}
|
||||
elsif ( !-x $script )
|
||||
{
|
||||
print( STDERR "Error, auto execute script '$script' not executable, skipping filter '$filter_data->{Name}'\n" );
|
||||
next FILTER;
|
||||
}
|
||||
}
|
||||
push( @filters, $filter_data );
|
||||
}
|
||||
$sth->finish();
|
||||
|
@ -424,6 +439,7 @@ sub CheckFilter
|
|||
($filter->{AutoUpload}?", upload":"").
|
||||
($filter->{AutoEmail}?", email":"").
|
||||
($filter->{AutoMessage}?", message":"").
|
||||
($filter->{AutoExecute}?", execute":"").
|
||||
"\n"
|
||||
) if ( VERBOSE );
|
||||
my $sql = $filter->{Sql};
|
||||
|
@ -441,23 +457,33 @@ sub CheckFilter
|
|||
while( my $event = $sth->fetchrow_hashref() )
|
||||
{
|
||||
print( "Checking event $event->{Id}\n" ) if ( VERBOSE );
|
||||
if ( $filter->{AutoExecute} )
|
||||
{
|
||||
if ( !$event->{Execute} )
|
||||
{
|
||||
executeCommand( $filter, $event );
|
||||
}
|
||||
}
|
||||
if ( ZM_OPT_EMAIL && $filter->{AutoEmail} )
|
||||
{
|
||||
next if ( $event->{Emailed} );
|
||||
|
||||
sendEmail( $filter, $event );
|
||||
if ( !$event->{Emailed} )
|
||||
{
|
||||
sendEmail( $filter, $event );
|
||||
}
|
||||
}
|
||||
if ( ZM_OPT_MESSAGE && $filter->{AutoMessage} )
|
||||
{
|
||||
next if ( $event->{Messaged} );
|
||||
|
||||
sendMessage( $filter, $event );
|
||||
if ( !$event->{Messaged} )
|
||||
{
|
||||
sendMessage( $filter, $event );
|
||||
}
|
||||
}
|
||||
if ( ZM_OPT_UPLOAD && $filter->{AutoUpload} )
|
||||
{
|
||||
next if ( $event->{Uploaded} );
|
||||
|
||||
uploadArchFile( $filter, $event );
|
||||
if ( !$event->{Uploaded} )
|
||||
{
|
||||
uploadArchFile( $filter, $event );
|
||||
}
|
||||
}
|
||||
if ( $filter->{AutoArchive} )
|
||||
{
|
||||
|
@ -482,6 +508,30 @@ sub CheckFilter
|
|||
$sth->finish();
|
||||
}
|
||||
|
||||
sub executeCommand
|
||||
{
|
||||
my $filter = shift;
|
||||
my $event = shift;
|
||||
|
||||
my $event_path = "$event->{MonitorName}/$event->{Id}";
|
||||
|
||||
my $command = $filter->{AutoExecute};
|
||||
$command .= " $event_path";
|
||||
|
||||
print( "Executing '$command'\n" );
|
||||
my $output = qx($command);
|
||||
my $status = $? >> 8;
|
||||
if ( $status || VERBOSE )
|
||||
{
|
||||
chomp( $output );
|
||||
print( "Output: $output\n" );
|
||||
}
|
||||
if ( $status )
|
||||
{
|
||||
print( "Command '$command' exited with status: $status\n" );
|
||||
}
|
||||
}
|
||||
|
||||
sub uploadArchFile
|
||||
{
|
||||
my $filter = shift;
|
||||
|
|
|
@ -90,7 +90,7 @@ if ( isset($action) )
|
|||
$filter_parms[] = "$key=$value";
|
||||
}
|
||||
$filter_query_string = join( '&', $filter_parms );
|
||||
$sql = "replace into Filters set Name = '$filter_name', Query = '$filter_query_string', AutoArchive = '$auto_archive', AutoDelete = '$auto_delete', AutoUpload = '$auto_upload', AutoEmail = '$auto_email', AutoMessage = '$auto_message'";
|
||||
$sql = "replace into Filters set Name = '$filter_name', Query = '$filter_query_string', AutoArchive = '$auto_archive', AutoDelete = '$auto_delete', AutoUpload = '$auto_upload', AutoEmail = '$auto_email', AutoMessage = '$auto_message', AutoExecute = '$auto_execute'";
|
||||
$result = mysql_query( $sql );
|
||||
if ( !$result )
|
||||
die( mysql_error() );
|
||||
|
|
|
@ -96,23 +96,27 @@ while ( $row = mysql_fetch_assoc( $result ) )
|
|||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoArchiveEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_archive" value="1"<?php if ( $filter_data['AutoArchive'] ) { echo " checked"; } ?>></td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_archive" value="1"<?php if ( $filter_data['AutoArchive'] ) { echo " checked"; } ?> class="form-noborder"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoDeleteEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_delete" value="1"<?php if ( $filter_data['AutoDelete'] ) { echo " checked"; } ?>></td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_delete" value="1"<?php if ( $filter_data['AutoDelete'] ) { echo " checked"; } ?> class="form-noborder"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoUploadEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_upload" value="1"<?php if ( $filter_data['AutoUpload'] ) { echo " checked"; } ?>></td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_upload" value="1"<?php if ( $filter_data['AutoUpload'] ) { echo " checked"; } ?> class="form-noborder"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoEmailEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_email" value="1"<?php if ( $filter_data['AutoEmail'] ) { echo " checked"; } ?>></td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_email" value="1"<?php if ( $filter_data['AutoEmail'] ) { echo " checked"; } ?> class="form-noborder"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoMessageEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_message" value="1"<?php if ( $filter_data['AutoMessage'] ) { echo " checked"; } ?>></td>
|
||||
<td align="left" class="text"><input type="checkbox" name="auto_message" value="1"<?php if ( $filter_data['AutoMessage'] ) { echo " checked"; } ?> class="form-noborder"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" class="text"><?= $zmSlangAutoExecuteEvents ?>: </td>
|
||||
<td align="left" class="text"><input type="text" name="auto_execute" value="<?= $filter_data['AutoExecute'] ?>" size="32" maxlength="255" class="form"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" colspan="2" class="text"> </td>
|
||||
|
|
|
@ -101,11 +101,12 @@ $zmSlangAttrMonitorName = 'Monitor Name';
|
|||
$zmSlangAttrTime = 'Time';
|
||||
$zmSlangAttrTotalScore = 'Total Score';
|
||||
$zmSlangAttrWeekday = 'Weekday';
|
||||
$zmSlangAutoArchiveEvents = 'Automatically archive all matching events';
|
||||
$zmSlangAutoDeleteEvents = 'Automatically delete all matching events';
|
||||
$zmSlangAutoEmailEvents = 'Automatically email details of all matching events';
|
||||
$zmSlangAutoMessageEvents = 'Automatically message details of all matching events';
|
||||
$zmSlangAutoUploadEvents = 'Automatically upload all matching events';
|
||||
$zmSlangAutoArchiveEvents = 'Automatically archive all matches';
|
||||
$zmSlangAutoDeleteEvents = 'Automatically delete all matches';
|
||||
$zmSlangAutoEmailEvents = 'Automatically email details of all matches';
|
||||
$zmSlangAutoExecuteEvents = 'Automatically execute command on all matches';
|
||||
$zmSlangAutoMessageEvents = 'Automatically message details of all matches';
|
||||
$zmSlangAutoUploadEvents = 'Automatically upload all matches';
|
||||
$zmSlangAvgBrScore = 'Avg.<br/>Score';
|
||||
$zmSlangBadMonitorChars = 'Monitor Names may only contain alphanumeric characters plus hyphen and underscore';
|
||||
$zmSlangBandwidth = 'Bandwidth';
|
||||
|
|
Loading…
Reference in New Issue