如何触发Zoneminder拨打固定电话

时间:2013-12-22 15:02:57

标签: triggers alarm phone-call modem zoneminder

  1. 您需要通过“调制解调器”将PC连接到固定电话。

  2. 安装wvdial(并进行配置)(并测试它是否会响铃)。

  3. 然后修改script supplied by zoneminder以访问调制解调器(搜索该页面,例如“触发器”)。

  4. 运行该脚本,例如在您的主目录中。

  5. 此外,我发现调制解调器相当过时,在Linux中得不到很好的支持,例如“Winmodems”(便宜),因为他们在(Windows)软件中执行低级别的东西以节省硬件,因此在当前的Linux中不再支持我的旧PC的PCI调制解调器,即我必须找到硬件驱动的调制解调器,例如而是“Trendnet TFM 561u”。这在我的Mint 14系统(2013年12月)开箱即用,显示为/ dev / ttyACM0。

    #!/usr/bin/perl -w
    
    use strict;
    
    use lib ("/opt/zm/share/perl/5.14.2");
    
    use ZoneMinder;
    
    $| = 1;
    
    # mDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );
    
    my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );
    
    my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
    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() );
    my @monitors;
    while ( my $monitor = $sth->fetchrow_hashref() ) 
    {
        push( @monitors, $monitor );
    }
    
    while( 1 ) {
        foreach my $monitor ( @monitors ) {
            next if ( !zmMemVerify( $monitor ) );
    
            my $lei = eval {               # avoid...
                $monitor->{LastEventId};   # ...aborting
            };                             # ...this script
            warn $@ if $@;                 # ...if there is no
            if( ! $lei ) {                 # ...LastEventId
            next;                          # ...e.g. for a clean start
            }                              # ...after clearing out database.
    
            my $last_event_id = zmHasAlarmed( $monitor, $lei );
    
    
            if ( $last_event_id ) {
                if ( $monitor->{Name} ne "monitor-1" && $monitor->{Name} ne "monitor-2" )  {
                    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
                    if ( $hour > 23 || $hour < 7 ) {
                        $monitor->{LastEventId} = $last_event_id;
                        print( "Monitor ".$monitor->{Name}." has alarmed \n" );
                        my $cmd .= "echo ";
                        $cmd .= "\"";
                        $cmd .= "Garage Alarm: ".$monitor->{Name};
                        $cmd .= "\"";
                        $cmd .=  ' | mail -s `curl ifconfig.me` myemailaddress@gmail.com';
                        system ($cmd);
                        system('wvdial');
                    }
                } 
            }
        }
        sleep( 1 );
    }
    

    这是我第一次尝试(修改)Perl。这将是粗糙的!

    第一个系统($ cmd)通过myemailaddress@gmail.com发送电子邮件给我(您需要自己设置以获取邮件)以及当前的URL,以防它最近发生变化。

    第二个系统('wvdial')敲响了我的手机。

    如您所见,“monitor-1”和“monitor-2”将被忽略。

    正如您所看到的,它是在晚上11点到早上7点之间启用的。

    我的/etc/wvdial.conf文件与此类似: -

    [Dialer Defaults]
    Init1 = ATZ
    Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
    Modem Type = USB Modem
    Phone = 123456789
    ISDN = 0
    Password = <Your Password>
    New PPPD = yes
    Username = <Your Login Name>
    
    Modem = /dev/ttyACM0
    Baud = 460800
    Dial Command = ATDT
    Auto Reconnect = off
    Dial Attempts = 1
    

0 个答案:

没有答案