ASNMTAP

 view release on metacpan or  search on metacpan

lib/ASNMTAP/Asnmtap/Plugins/Modem.pm  view on Meta::CPAN

        $pppInterfaceInfo .= sprintf ("inet %-15s mask $pppMask\n", $pppIp);
        $$asnmtapInherited->pluginValues ( { alert => "$pppInterface $pppStatus - inet $pppIp mask $pppMask" }, $TYPE{APPEND} );
      };

      $pppInterfaceInfo .= 'ether '. $info->{$pppInterface}->{ether} ."\n" if ( $info->{$pppInterface}->{ether} );
      $pppInterfaceInfo .= 'descr '. $info->{$pppInterface}->{descr} ."\n" if ( $info->{$pppInterface}->{descr} );
    }

    print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_ppp_interface_info: $pppInterfaceInfo" if ($debug);
    return ( $pppStatus );
  }

  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  sub _error_trap_modem {
    my ($error_message, $ras_message, $debug) = @_;

    print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_error_trap_modem: $error_message, $ras_message\n" if ($debug);
    return (0);
  }

  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  sub _test_modem {
    my ( $asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess, $test_modem, $debug ) = @_;

    my $log = 'syslog';

    if ( $$parms{logtype} eq 'file' ) {
      $$asnmtapInherited->call_system ( 'mkdir '. $LOGPATH ) unless ( -e "$LOGPATH" );
      my $logfile = $LOGPATH .'/'. $$asnmtapInherited->programName() .'.log';
      $log = 'file,'. $logfile;
    }

    if ($debug) {                              # test syslog/file logging
      $$modem = Device::Modem->new ( port => $$parms{port}, log => $log, loglevel => 'debug' );
    } else {
      $$modem = Device::Modem->new ( port => $$parms{port}, log => $log, loglevel => $$parms{loglevel} );
    }

    if ($debug) {
      print 'ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem::Device::Modem::new: '. $$modem ."\n";
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem::Device::Modem::connect: baudrate => $$parms{baudrate}, databits => $$parms{databits}, initString => $$parms{initString}, parity => $$parms{parity}, stopbits => $$parms{sto...
    }

    if ( $$modem->connect ( baudrate => $$parms{baudrate}, databits => $$parms{databits}, initString => $$parms{initString}, parity => $$parms{parity}, stopbits => $$parms{stopbits} ) ) {
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Modem is connected to ". $$parms{port} ." serial port\n" if ($debug);
    } else {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Cannot connect to '. $$parms{port} ." serial port!: $!" }, $TYPE{APPEND} );
      return ( $ERRORS{UNKNOWN} );
    }

    if ( $$modem->is_active () ) {
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Modem is active\n" if ($debug);
    } else {
      $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'Modem is turned off, or not functioning ...' }, $TYPE{APPEND} );
      return ( $ERRORS{UNKNOWN} );
    }

	if ( $test_modem ) {
      # Try with AT escape code, send `attention' sequence (+++)
      $$answer = $$modem->attention();
      $$answer = '<no answer>' unless ( defined $$answer );
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Sending attention, modem says '$$answer'\n" if ($debug);

      unless ( $$answer eq '<no answer>' ) {
        $$asnmtapInherited->pluginValues ( { alert => "Sending attention, modem says '$$answer'" }, $TYPE{APPEND} );
        $$not_connected_guess++;
      }

      # Send empty AT command
      $$answer = undef;
      $$modem->atsend('AT'. Device::Modem::CR);
      $$answer = $$modem->answer();
      $$answer = '<no answer>' unless ( defined $$answer );
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Sending AT, modem says '$$answer'\n" if ($debug);

      unless ( $$answer =~ /OK/ ) {
        $$asnmtapInherited->pluginValues ( { alert => "Sending AT, modem says '$$answer'" }, $TYPE{APPEND} );
        $$not_connected_guess++;
      }

      # This must generate an error!
      $$answer = undef;
      $$modem->atsend('AT@x@@!$#'. Device::Modem::CR);
      $$answer = $$modem->answer();
      $$answer = '<no answer>' unless ( defined $$answer );
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Sending erroneous AT command, modem says '$$answer'\n" if ($debug);

      unless ( $$answer =~ /ERROR/ ) {
        $$asnmtapInherited->pluginValues ( { alert => "Sending erroneous AT command, modem says '$$answer'" }, $TYPE{APPEND} );
        $$not_connected_guess++;
      }

      $$answer = undef;
      $$modem->atsend('AT'. Device::Modem::CR);
      $$answer = $$modem->answer();
      $$answer = '<no answer>' unless ( defined $$answer );
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Sending AT command, modem says '$$answer'\n" if ($debug);

      $$answer = undef;
      $$modem->atsend('ATZ'. Device::Modem::CR);
      $$answer = $$modem->answer();
      $$answer = '<no answer>' unless ( defined $$answer );
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: Sending ATZ reset command, modem says '$$answer'\n" if ($debug);

      unless ( $$answer =~ /OK/ ) {
        $$asnmtapInherited->pluginValues ( { alert => "Sending ATZ reset command, modem says '$$answer'" }, $TYPE{APPEND} );
        $$not_connected_guess++;
      }

      $$answer = undef;
      ($$ok, $$answer) = $$modem->dial( $$parms{phonenumber}, $$parms{timeout} );
      $$answer = '<no answer>' unless ( defined $$answer );

      print 'ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::_test_modem: ', ( $$ok ? 'Dialed' : 'Cannot Dial' ), '['. $$parms{phonenumber} ."], answer: $$answer\n" if ($debug);
    } else {
      $$modem = undef;
    }

    sleep (1);



( run in 0.713 second using v1.01-cache-2.11-cpan-13bb782fe5a )