ASNMTAP

 view release on metacpan or  search on metacpan

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

  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

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

    }

	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);
    return ( $ERRORS{OK} );
  }

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

  my ($returnCode, $hrasconn, $modem, $ok, $answer);
  my $not_connected_guess = 0;

  return ( $returnCode ) if ( $returnCode = _test_modem ( $asnmtapInherited, \%parms, \$modem, \$ok, \$answer, \$not_connected_guess, $modem_not_ras, $debug ) );

  unless ( $modem_not_ras ) {
    my ($pppStatus, $exit);

    if ( $parms{windows} ) {
      eval { no strict 'subs'; $hrasconn = RasDial( $parms{phonebook}, $parms{phonenumber}, $parms{username}, $parms{password} ) or _error_trap_modem ( 'Cannot Dial to '. $parms{phonenumber}, Win32::RASE::FormatMessage, $debug ) };
    } else {
      $$asnmtapInherited->call_system ( $ROUTECOMMAND .' del default' ) if ( $parms{defaultDelete} );

      my $ATZ= ''; # APE: there are modems that have problems with the command 'ATZ' ! # ' ATZ OK';
      my $command = 'cd '. $parms{pppPath} .'; '. $PPPDCOMMAND .' '. $parms{port} .' '. $parms{baudrate} .' debug user '. $parms{username} .' call '. $parms{phonebook} ." connect \"$CHATCOMMAND -v ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO D...
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::pppd: $command\n" if ($debug);

      if ( $$asnmtapInherited->call_system ( "$command" ) ) {
        $$asnmtapInherited->pluginValues ( { alert => "'$command' failed" }, $TYPE{APPEND} );
        $not_connected_guess++;
      } else {
        $SIG{ALRM} = sub { alarm (0); $exit = 1 };
        alarm ( $parms{pppTimeout} ); $exit = 0;

        do {
          my $info; eval { $info = Net::Ifconfig::Wrapper::Ifconfig ('list') };

          if ( defined $info ) {
            $pppStatus = _ppp_interface_info ( $asnmtapInherited, $info, $parms{pppInterface}, $debug );

            if ( $pppStatus eq 'UP' ) {
              $hrasconn = $parms{phonebook};
            } else {
              $not_connected_guess++
            }

            undef $info;
          } else {
            $$asnmtapInherited->pluginValues ( { alert => "info '". $parms{phonebook} ."' not defined" }, $TYPE{APPEND} );
            $not_connected_guess++
          }

          sleep (1);
        } until (defined $hrasconn || $exit);

        alarm (0); $SIG{ALRM} = 'DEFAULT';

        unless ( defined $hrasconn ) {
          sleep (1);
          $$asnmtapInherited->pluginValues ( { alert => "pppd call '". $parms{phonebook} ."' failed" }, $TYPE{APPEND} );
          $$asnmtapInherited->call_system ( $KILLALLCOMMAND .' -HUP pppd' );
          $not_connected_guess++;
        }
      }

      $$asnmtapInherited->call_system ( $ROUTECOMMAND .' -n' );
    }

    if ( defined $hrasconn ) {
	  $ok = 1;
      $not_connected_guess = 0;
      print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request: Connected to $hrasconn\n" if ($debug);
    } else {                                                 # modem test
      return ( $returnCode ) if ( $returnCode = _test_modem ( $asnmtapInherited, \%parms, \$modem, \$ok, \$answer, \$not_connected_guess, ! $modem_not_ras, $debug ) );

      if ( $parms{windows} ) {
        $$asnmtapInherited->pluginValues ( { alert => "Cannot Dial to '" .$parms{phonenumber}. "'" }, $TYPE{APPEND} );
        $not_connected_guess++;
      }
    }
  }

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

  $returnCode = $ERRORS{OK};

  if ( ( $modem_not_ras and defined $ok ) or ( defined $ok and $ok and ! $not_connected_guess ) ) {
    if ( defined $parms{custom} ) {
      $returnCode = ( defined $parms{customArguments} ) ? $parms{custom}->($$asnmtapInherited, \%parms, \$modem, \$ok, \$answer, \$not_connected_guess, $parms{customArguments}) : $parms{custom}->($$asnmtapInherited, \%parms, \$modem, \$ok, \$answer, ...
    } else {
      print 'ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request: ', $$asnmtapInherited->{_programDescription}, "\n" if ($debug);
    }
  }

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

  unless ( defined $parms{phonebook} ) {
    if ( $ok and $answer ne 'SKIP HANGUP' ) {
      sleep (1);
      $ok = $modem->hangup();

      if( $ok =~ /OK/ ) {
        print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::modem::hangup: Hanging up done\n" if ($debug);
      } else {
        print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::modem::hangup: Cannot Hanging up\n" if ($debug);
        $$asnmtapInherited->pluginValues ( { alert => 'Cannot Hanging up' }, $TYPE{APPEND} );
        $not_connected_guess++;
      }
    }
  } elsif ( $parms{windows} ) {
    eval {
      no strict 'subs';

      if ( RasHangUp($hrasconn, 3) ) {
        print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::RAS: RAS connection was terminated successfully.\n" if ($debug);
      } elsif ( ! Win32::RASE::GetLastError ) {
        print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::RAS: Timeout. RAS connection is still active.\n" if ($debug);

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

        print "ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::RAS: ", Win32::RASE::FormatMessage, "\n";
        $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => ' '. Win32::RASE::FormatMessage }, $TYPE{APPEND} );
      }
    }
  } else {
    $$asnmtapInherited->call_system ( $ROUTECOMMAND .' del default' ) if ( $parms{defaultDelete} );
    $$asnmtapInherited->call_system ( $KILLALLCOMMAND .' -HUP pppd' );
    $$asnmtapInherited->call_system ( $ROUTECOMMAND .' add default gw '. $parms{defaultGateway} .' dev '. $parms{defaultInterface} ); # if ( $parms{defaultDelete} );
  }

  $returnCode = ( $not_connected_guess ) ? $ERRORS{UNKNOWN} : $returnCode;
  $$asnmtapInherited->pluginValue ( stateValue => $returnCode );
  return ( $returnCode );
}

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

1;

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

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


returns the exact modem answer in the C<$answer> scalar. C<$answer> typically can contain strings like C<CONNECT 19200> or C<NO CARRIER>, C<BUSY>, ... all standard modem answers to a dial command.

=over 4

=item SKIP HANGUP

in a custom function you can set $$answer to 'SKIP HANGUP' for skipping the function $modem->hangup() on exit, needed for some PABX.

 sub actionOnModemResponse {
   my ($asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess, $arguments) = @_;

   my $debug = $asnmtapInherited->getOptionsValue ('debug');

   print 'ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::actionOnModemResponse: ', $asnmtapInherited->programDescription (), "\n" if ( $debug );

   unless ( $$ok ) {
     my $ATDT = 'ATDT'. $$parms{phonenumber};
     my $busy = ( $$answer eq $ATDT ? 1 : ( $$answer =~ /^$ATDT\s*(?:BUSY)?\s*$/ ? 2 : 0 ) );

     if ( $busy ) {
       $$answer = 'SKIP HANGUP' if ( $busy == 2 );
       print "OK: BUSY\n" if ($debug);
       $$ok = 1;
     } else {
       print "NOK: BUSY\n" if ($debug);
       $$not_connected_guess++;
       $asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, alert => "Cannot dial [". $$parms{phonenumber} ."], answer: BUSY" }, $TYPE{APPEND} );
     }
   }

   return ( ( $$ok and ! $$not_connected_guess ) ? $ERRORS{OK} : $ERRORS{UNKNOWN} ); 
 }

=back

=item $not_connected_guess

default 0, everytime there is a problem we do $not_connected_guess++

=back

 sub actionOnModemResponse {
   my ($asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess) = @_;
   return ($returnCode);
 }

and now with customArguments:

 sub actionOnModemResponse {
   my ($asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess, $arguments) = @_;
   return ($returnCode);
 }

=item customArguments

optional, when you need to pass parameters to your own custom defined function, this can be done with customArguments.

 customArguments: SCALAR, ARRAY, HASH,
                  REF SCALAR, REF ARRAY, REF HASH

plugins/templates/check_template-modem.pl  view on Meta::CPAN


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End plugin  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$objectPlugins->exit (7);

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

sub actionOnModemResponse {
  my ($asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess, $arguments) = @_;

  my $debug = $asnmtapInherited->getOptionsValue ('debug');

  if ($debug and defined $arguments) {
    for ( ref $arguments ) {
      /^REF$/ &&
        do { 
          for ( ref $$arguments ) {
            /^ARRAY$/ &&
              do { print "REF ARRAY: @$$arguments\n"; last; };

plugins/templates/check_template-modem.pl  view on Meta::CPAN

  }

  print 'ASNMTAP::Asnmtap::Plugins::Modem::get_modem_request::actionOnModemResponse: ', $asnmtapInherited->programDescription (), "\n" if ( $debug );

  my $returnCode;

  if ( $$ok ) {
    $returnCode = $ERRORS{OK};
    $asnmtapInherited->pluginValues ( { stateValue => $returnCode, alert => "Dialed [". $$parms{phonenumber} ."], answer: $$answer" }, $TYPE{APPEND} );
  } else {
    $$not_connected_guess++;
    $returnCode = $ERRORS{UNKNOWN};
    $asnmtapInherited->pluginValues ( { stateValue => $returnCode, alert => "Cannot dial [". $$parms{phonenumber} ."], answer: $$answer" }, $TYPE{APPEND} );
  }

  return ($returnCode);
}

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

__END__

plugins/templates/check_template-ras.pl  view on Meta::CPAN


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# End plugin  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$objectPlugins->exit (7);

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

sub actionOnModemResponse {
  my ($asnmtapInherited, $parms, $modem, $ok, $answer, $not_connected_guess, $arguments) = @_;

  my $debug = $asnmtapInherited->getOptionsValue ('debug');

  if ($debug and defined $arguments) {
    for ( ref $arguments ) {
      /^REF$/ &&
        do { 
          for ( ref $$arguments ) {
            /^ARRAY$/ &&
              do { print "REF ARRAY: @$$arguments\n"; last; };

plugins/templates/snmptt/snmptt.ini  view on Meta::CPAN

resolve_value_ip_addresses = 1

# Set to 1 to enable the use of the Perl module from the UCD-SNMP / NET-SNMP package.
# This is required for $v variable substitution to work, and also for some other options
# that are enabled in this .ini file.
# Set to 0 to disable the use of the Perl module from the UCD-SNMP / NET-SNMP package.
# Note: Enabling this with stand-alone mode can cause SNMPTT to run very slowly due to
#       the loading of the MIBS at startup.
net_snmp_perl_enable = 1

# This sets the best_guess parameter used by the UCD-SNMP / NET-SNMP Perl module for 
# translating symbolic nams to OIDs and vice versa.
# For UCD-SNMP, and Net-SNMP 5.0.8 and previous versions, set this value to 0.
# For Net-SNMP 5.0.9, or any Net-SNMP with patch 722075 applied, set this value to 2.
# A value of 2 is equivalent to -IR on Net-SNMP command line utilities.
# UCD-SNMP and Net-SNMP 5.0.8 and previous may not be able to translate certain formats of
# symbolic names such as RFC1213-MIB::sysDescr.  Net-SNMP 5.0.9 or patch 722075 will allow
# all possibilities to be translated.  See the FAQ section in the README for more info
net_snmp_perl_best_guess = 1

# Configures how the OID of the received trap is handled when outputting to a log file /
# database.  It does NOT apply to the $O variable.
# Set to 0 to use the default of numerical OID
# Set to 1 to translate the trap OID to short text (symbolic form) (eg: linkUp)
# Set to 2 to translate the trap OID to short text with module name (eg: IF-MIB::linkUp)
# Set to 3 to translate the trap OID to long text (eg: iso...snmpTraps.linkUp)
# Set to 4 to translate the trap OID to long text with module name (eg: 
# IF-MIB::iso...snmpTraps.linkUp)
# Note: -The output of the long format will vary depending on the version of Net-SNMP you



( run in 0.278 second using v1.01-cache-2.11-cpan-702932259ff )